//$(document).ready(function(){
	
	var cyp_host = location.host;
	if(cyp_host == "localhost") {
		cyp_host += '/' + 'cypruswebsites';
	}

	//alert(cyp_host);
	
	$('a.classif_navigation').each(function(i) {
		$(this).click(function(e){
			e.preventDefault();
			var navstr = $(this).attr('rel');
			$('#subSearchFrom').val(navstr);
			//$('#itemsResults').empty();
			getItemsBySubCateg();
			//else alert(typeof getItemsBySubCateg);
		});
		
	});
	
	
	$('select.order_by').each(function(i){
		$(this).change(function(e){
			$('#subSearchOrderBy').val($(this).val());
			if($('#entries_search_form').length > 0) {
				$('#entries_search_form').submit();
			}
			else {
				$('#subs_search_form').submit();
			}
		});
	});
	
	
	
	
	$('div.print_entry a').each(function(i){
		$(this).click(function(e){
			var item_id = $(this).attr('rel');
			//alert('Report Item ID = ' + $(this).attr('rel'));
			$('<div class="displayWnd reportWnd">Loading ... </div').load('http://'+cyp_host+'/ajax_util.php', {ax_action:'modules/classifieds/ajax/printEntry.php',ax_method:'POST',item_id: item_id}).appendTo('#itemsResults').css({width: '800px',height:'420px'}).displayBox({}, function(){});
			return false;
		});
	});
	
	$('div.email_entry a').each(function(i){
		$(this).click(function(e){
			var item_id = $(this).attr('rel');
			//alert('Report Item ID = ' + $(this).attr('rel'));
			$('<div class="displayWnd reportWnd">Loading ... </div').load('http://'+cyp_host+'/ajax_util.php', {ax_action:'modules/classifieds/ajax/emailEntry.php',ax_method:'POST',item_id: item_id}).appendTo('#itemsResults').css('width', '350px').displayBox({}, function(){});
			return false;
		});
	});
	
	$('div.save_entry a').each(function(i){
		$(this).click(function(e){
			var item_id = $(this).attr('rel');
			var member_item = ( $('#member_id').val() ) * 1;
			
			if(member_item != "" && member_item > -1) {
				var member_id = member_item;
				$.ajax({
					url : 'http://'+cyp_host+'/ajax_util.php',
					type: 'POST',
					data: {ax_action:'modules/classifieds/ajax/favoriteEntry.php', ax_method:'POST',item_id: item_id, member_id:member_id, ajx:'1'},
					dataType: 'json',
					success: function(ret) {
						if(ret.success != undefined) {
							if(ret.success == "SAVED") {
								$.prompt('<b class="black">Success!!!</b><br/><hr/>The Ad has been saved successfully!',{prefix:'brownJqi', buttons:{Ok:true}});
							}
							if(ret.success == "EXISTS") {
								$.prompt('<b class="red">No Action!!!</b><br/><hr/>You already saved this Ad!',{prefix:'brownJqi', buttons:{Ok:true}});
							}
						}
						else {
							if(ret.error != undefined) {
								if(ret.error == "ERROR") {
									$.prompt('<b class="red">Error!!!</b><br/><hr/>The Ad has not been saved!',{prefix:'brownJqi', buttons:{Ok:true}});
								}
								if(ret.error == "OWN") {
									$.prompt('<b class="red">Error!!!</b><br/><hr/>This Ad belongs to you!',{prefix:'brownJqi', buttons:{Ok:true}});
								}
							}
							
						}
					},
					error: function(a,b,c){
						$.prompt('<b class="red">Error!!!</b><br/><hr/>The Ad has not been saved!<br/><b>' + b + ':</b><br>' + c ,{prefix:'brownJqi', buttons:{Ok:true}});
					}
					
				});
			}
			return false;
		});
	});
	
	$('div.report_entry a').each(function(i){
		$(this).click(function(e){
			var item_id = $(this).attr('rel');
			//alert('Report Item ID = ' + $(this).attr('rel'));
			$('<div class="displayWnd reportWnd"></div').load('http://'+cyp_host+'/ajax_util.php', {ax_action:'modules/classifieds/ajax/reportEntry.php',ax_method:'POST',item_id: item_id}).appendTo('#itemsResults').displayBox({}, function(){});
			return false;
		});
	});
	
	jQuery.fn.slideFadeOut = function(speed, easing, callback) {
		var resetCSS = { display: '', overflow: '', height: '' };
        if (!$.browser.msie) // not in IE to prevent ClearType font issue
            resetCSS.opacity = '';
         
        this.css('display','none').css(resetCSS);   
            
        if ($.browser.msie) {
        	this.css('filter', '');
        }
        
  		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};
	
	
	$('div.tab').each(function(i){
		$('a', this).click(function(e){
			e.preventDefault();
		});
		$(this).click(function(e){
			if($(this).hasClass('selected')) {
				// nothing
			}
			else {
				var rel = $(this).attr('rel');
				var $bd = $('div.selected:has[rel='+rel+']');
				
				if($bd) {
					var bid = $('a', $bd).attr('rel').replace("#", "");
					//alert(bid);
					$('div#' + bid).css({display:'none', overflow: '', height:''});
					$bd.removeClass('selected');
				}
					
				$(this).toggleClass('selected');
				var id = $('a', this).attr('rel').replace("#", "");
				
				
				var newheight = '';
				if(!$.browser.msie) newheight = '100%';
				$('div#'+id).css({display:'block', overflow: '', height:''+newheight+''});
				//alert('div#'+id);
			}
		});
	});
	
	// This should stay lower

	
//});