﻿var firstTimescroll='false';
var successPostLoadSecond="yes";
var globalLastPostID	="";
var pageCond			=	'';
var	pageCondMenu		=	'';

var recordsLimit	=	'';

$(document).ready(function(){
			
/*	$("img.lazy").lazyload({ 
   effect : "fadeIn"
	
	
});*/

$("img.lazy").lazyload();
	
	function product_funtion(disPageName,checkPageName) 
	{ 
	  var ID=$(".ProductDisplayScroll:last").attr("id");
		//alert(ID);
		// Get condition on product details page
		
		pageCond		=	document.getElementById('pageCond').value;
		//alert('pageCond '+ pageCond);
		//pageCondMenu	=	document.getElementById('pageCondMenu').value;
		//alert('pageCondMenu '+ pageCondMenu);
		recordsLimit	=	document.getElementById('recordsLimit').value;
		orderby			=	document.getElementById('orderbys').value;
		showby			=	document.getElementById('showbys').value;
		brandId			=	document.getElementById('brandIds').value;
		p_statusAdmin	=	document.getElementById('pstatus').value;
		
		if(document.getElementById('submenu').value)
			submenus	=	document.getElementById('submenu').value;
			
			
		if(globalLastPostID!=ID) {
			
			$('div#last_msg_loader').html('<img src="'+webSiteJsUrl+'images/bigLoader.gif">');
			globalLastPostID=ID;
			//$.post(disPageName+"?action=get&last_pid="+ID,
			//alert(disPageName+"?action=get&pageCond="+pageCond+"&recordsLimit="+recordsLimit+"&pageCondSection="+pageCondMenu+"&last_pid="+ID+"&lastID="+ID);
		//alert(disPageName+"?action=get&pageCond="+pageCond+"&recordsLimit="+recordsLimit+"&orderby="+orderby+"&showby="+showby+"&brandId="+brandId+"&pageCondSection="+pageCondMenu+"&last_pid="+ID+"&lastID="+ID);	
		
			$.post(disPageName+"?action=get&pageCond="+pageCond+"&recordsLimit="+recordsLimit+"&orderby="+orderby+"&showby="+showby+"&brandId="+brandId+"&p_status="+p_statusAdmin+"&pageCondSection="+pageCondMenu+"&smenus="+submenus+"&last_pid="+ID+"&lastID="+ID,
			function(data){
			
		
		
				data=$.trim(data);
				if (data != "") {
					$(".ProductDisplayScroll:last").after(data);	
					successPostLoadSecond="yes";		
				}
				else{
					//$('div#last_msg_loader').css('margin', '-150px');
				}
				//$('div#last_msg_loader').empty();
			});
		}
		else{
			//$('div#last_msg_loader').css('margin', '-150px');
			$('div#last_msg_loader').empty();
			$('#FooterWraper').show();
		}
	}; 
		

	$(window).scroll(function(){
		if(document.getElementById('checkPageName').value)
		{
			var checkPageName	=	document.getElementById('checkPageName').value;
			var winDisplay	=	$(document).height() - $(window).height() ;
			
			var winDisplay	=	($(document).height()-1200) - $(window).height() ;
			if(firstTimescroll=='false') {
				if( $(window).scrollTop() > (($(document).height()) - $(window).height())  ){
					$(window).scrollTop('0');
				}
			}
			//alert('asda');
			firstTimescroll=='true';
			//alert(checkPageName);
			if(checkPageName.match("homepage_product") || checkPageName.match("homepage_product_music")  || checkPageName.match("homepage_product_dvds")  || checkPageName.match("productpage_scroll") || checkPageName.match("musicpage_scroll") || checkPageName.match("dvdpage_scroll"))
			{	
				var pageName	=	document.getElementById('pageName').value;
				
			//alert("a");
		
				if(successPostLoadSecond=="yes" &&  ($(window).scrollTop() > winDisplay && $(window).scrollTop()>0) ){
					//alert("testing Jhan");
					$('#FooterWraper').hide();
					product_funtion(pageName,checkPageName);
					successPostLoadSecond="no";
				}
				
			}
		}
			
		
	}); 
		
});
			
var clicks = 0;	
var currshow = 48;
function nextSetofRecords(val)
{
	
	k =currshow +1;
	j =currshow +48;
	 
	 var showhide ='yes';
	
		for(k=49;k<=j;k++)
		{
			if($('#dvds'+k).hide())
			{
				$('#dvds'+k).show();
			}
			else
			{
				showhide='no';
			}
		}
	if(showhide=='no')
		$('#morerecords').hide();
	
	currshow = currshow +j;
}
