type='<?=$type?>';
mypage='<?=$_GET["page"]?>';
sindex='<?=$sindex?>';
index='<?=$index?>';
$(document).ready(function() {	

if (mypage==NaN) mypage=1;

$(".thumbimg").lazyload({ threshold : 180 });
$(".videoBars").corner();





if (parseInt(maxpage2)>400){maxpage2=400;};
var nextpage;
var cid='<?=$cid?>';
if(!prodpage) {var prodpage='<?=($page+1)?>';}
var maxpage='<?=($maxPage)?>';
var curpageNum='<?=($pageNum)?>';
	try{
		if (parseInt(curpageNum)==1) {
			nextpage='0';
		} else {
			nextpage=curpageNum;
		}
}catch(err){
}
nextpage=parseInt(mypage)+1;
if (mypage>1) {
pageNum=parseInt(mypage)-1;
} else {
pageNum=parseInt(mypage);
}

var encodedcid=escape(encodeURI(cid));
var a='<?=$a?>';
$("#loading3").hide();
$("#loading4").hide();
$("#loading5").hide();
if ($('#loading2'))$('#loading2').hide();


		$("#topnextpage").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#loading4").show();
		$('#exclusive').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=P&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		  				function() { $("#loading4").hide(); });
		  	});

		$("#toppreviouspage").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#loading4").show();
		$('#exclusive').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=P&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading4").hide(); });
});

		$("#nextpage").click(function () {
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}
			
			$("#loading3").show();

		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=P&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		  				function() { $("#loading3").hide(); });
		
		  	});

		$("#previouspage").click(function () {
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}
			
			
			$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=P&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading3").hide(); });
});



		$("#nextpageagency").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+nextpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}
			
			
			$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+nextpage, 
		  				function() { $("#loading5").hide(); });
		  	});

		$("#previouspageagency").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}
			
			
			$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading5").hide(); });
});
				$("#nextpageagency-bottom").click(function () {
					
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+nextpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

					
					$("#searchtext").focus();$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+nextpage, 
		  				function() { $("#loading5").hide(); });
		  	});

		$("#previouspageagency-bottom").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading5").hide(); });
});

		$("#pageagency-first").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=0&page=1', 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=0&page=1', 
		  				function() { $("#loading5").hide(); });
		  	});

		$("#pageagency-last").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$offset?>&page='+maxpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading5").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$offset?>&page='+maxpage, 
		  				function() { $("#loading5").hide(); });
});


		$("#viewproduct2").click(function () {
			
			$("#loading2").show();$('#viewproduct').attr('class', 'tab on');$('#viewagency').attr('class', 'tab');
		$('#topwrapper').fadeOut(150, function() {
		  	$(this).load('/bring_data.php?r='+unixTime()+'&reset=1&a=search&type=P&cid='+encodedcid+'&topcat=<?=$rowcat[1]?>', 
		  				function() { $(this).fadeIn(150); $("#loading2").hide();        
});
		  	});
		  	});



////// PRODUCT clicks \\\\\
		$("#nextpageproduct").click(function () {
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

		
		$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { $("#loading3").hide(); });
		  	});

		$("#previouspageproduct").click(function () {
			
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading3").hide(); });
});
		$("#nextpageproduct-bottom").click(function () {
			
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$sindex?>&page='+prodpage, 
		  				function() { $("#loading3").hide(); });
		  	});

		$("#previouspageproduct-bottom").click(function () {
			
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=<?=$pindex?>&page='+pageNum, 
		  				function() { $("#loading3").hide(); });
});

		$("#pageproduct-first").click(function () {
			
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=0&page=1', 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			
			$("#searchtext").focus();$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=0&page=1', 
		  				function() { $("#loading3").hide(); });
		  	});

		$("#pageproduct-last").click(function () {
			
			if (a=='search'){
			$("#loading-left").show();
			$('#myleftcarousel').hide();
			$('#carouselwrapper').load('/left_scroller.php?r='+unixTime()+'&a=carousel&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=4000&page='+maxpage2, 
		 function() { 
			$("#loading-left").hide();
			$('#myleftcarousel').show();	 
			});
			}

			
			$("#searchtext").focus();$("#loading3").show();
		$('#topwrapper').load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=<?=$type?>&cid='+encodedcid+'&topcat=<?=$topcatid?>&sindex=4000&page='+maxpage2, 
		  				function() { $("#loading3").hide(); });
});


$("#rows_select").change(
	function () {
	var message_index 
    message_index = $("#rows_select").val(); 
	$("#loading2").show();
	$('#topwrapper').fadeOut(150, function() {
		$(this).load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type=A&cid='+encodedcid+'&topcat=<?=$rowcat[1]?>&sindex=0&page=1&setrows='+message_index, 
		  				function() { $(this).fadeIn(150); $("#loading2").hide();        
		});
		  	});
		  	});


index='<?=$index?>';
$("#quick").change(
	function () {
	var message_index 
    message_index = $("#quick").val(); 
	if (message_index>1){
		quickindex=parseInt(message_index)-1;
		quickindex2=parseInt(quickindex)*parseInt(index);
	} else {
		quickindex2=parseInt(message_index)*parseInt(index);
	}
	$("#searchtext").focus();
	$("#loading2").show();
	$('#topwrapper').fadeOut(150, function() {
		$(this).load('/bring_data.php?r='+unixTime()+'&a=<?=$a?>&type='+type+'&cid='+encodedcid+'&sindex='+quickindex2+'&topcat=<?=$rowcat[1]?>&page='+message_index, 
		  				function() { $(this).fadeIn(150); $("#loading2").hide();        
		});
		  	});
		  	});

			

});


// {{{ is_int
function is_int( mixed_var ) {
    // Find whether the type of a variable is integer
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_int/
    // +       version: 812.1017
    // +   original by: Alex
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: 1.0 is simplified to 1 before it can be accessed by the function, this makes
    // %        note 1: it different from the PHP implementation. We can't fix this unfortunately.
    // *     example 1: is_int(186.31);
    // *     returns 1: false
    // *     example 2: is_int(12);
    // *     returns 2: true

    var y = parseInt(mixed_var * 1);
    
    if (isNaN(y)) {
        return false;
    }
    
    return mixed_var == y && mixed_var.toString() == y.toString(); 
}// }}}

function constrain(str,n){ 
  if(str.length > n){  
    var s = str.substr(0, n);
    var words = s.split(' '); 
    words[words.length-1] ='';
    str = words.join(' ') + '&hellip;'
  }
return str;
}
function onImgErrorSmall(source)
{
source.src = "/images/default_pic_112x93.gif";
source.style.width="112px";
// disable onerror to prevent endless loop
source.onerror = "";         
return true;
}

