$(document).ready(function(){
	
	$.lightspeed = {
	        pageno: 1,
	        itemcount: 0
	    };
	
	setcount();
	
	$("#lblCount").live('click', function(){
		loadContent('inquirybasket.php', 'Inquiry Basket');
		return false;
	});
	
	$("#content-slider").slider({
	    animate: 'normal',
	    change: handleSliderChange,
	    slide: handleSliderSlide
	  });

	$("#txtSearch").live('focus', function(event){
		if($(this).val() == 'Search Product(s)')
		{
			$(this).val('');
		}
	});
	
	$("#txtSearch").live('focusout', function(event){
		if($(this).val() == '')
		{
			$(this).val('Search Product(s)');
		}
	});
	
	$("#txtSearch").keypress(function(e){
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			$("#btnSearch").click();
			return false;
		}
		else
		{
			return true;
		}
	});
	
	$("#btnSearch").live('click', function(event){
		if($("#txtSearch").val() != '' && $("#txtSearch").val() != 'Search Product(s)')
		{
			loadContent("getrightpanelcontent.php?menu=searchproduct&searchparam=" + $("#txtSearch").val(), 'Products');
		}
	});
	
  $("#divMenu a").click(function(event){
	  var rel = $(this).attr("rel");
	  if(rel == 'Home')
	  {
		  $("#divContent").hide('fast', function(){
			  loadHome(linkurl);
			  });
	  }
	  else
	  {
		  var linkurl = $(this).attr("href");
		  $("#divContent").hide('fast', function(){
		  loadContent(linkurl, rel);
		  });
	  }
	  return false;
  });
  $(".bottomList a").click(function(event){
	  var rel = $(this).attr("rel");
	  if(rel == 'Home')
	  {
		  $("#divContent").hide('fast', function(){
			  loadHome(linkurl);
			  });
	  }
	  else
	  {
		  var linkurl = $(this).attr("href");
		  $("#divContent").hide('fast', function(){
		  loadContent(linkurl, rel);
		  });
	  }
	  return false;
  });
  $("#logodiv a").click(function(event){
	  $("#divContent").hide('fast', function(){
		  loadHome("home.php");
	  });
	  return false;
  });
  
  $("#navigationByCategory a").live('click', function(event){
	  navigationClicked($(this).attr("href"), $(this).attr("rel"));
	  return false;
  });
  
  $("#navigationByBrand a").live('click', function(event){
	  navigationClicked($(this).attr("href"), $(this).attr("rel"));
	  return false;
  });
  
  $("#brandsPageContent a").live('click', function(event){
	  navigationClicked($(this).attr("href"), $(this).attr("rel"));
	  return false;
  });
  
  $('#divBreadCrumb a').live('click', function(event){
	  return false;
  });
  
  $("#selectsubid").live('change', function(event){
	  var subid=$(this).val();
	  var mainid = $(this).siblings('#idhiddenmain').val();
	  var rel = $('#divBreadCrumb a').last().text();
	  var type= $(this).siblings('#typehiddenmain').val();
	  var linkurl = "search.php?type=" + type + "&id=" + mainid + "&subid=" + subid;
	  navigationClicked(linkurl, rel);
	  return false;
  });
  
  $(".divSearchItem a").live('click', function(event){
	  showBreadcrumbProduct($(this).attr("rel"));
	  var linkurl = $(this).attr("href");
	  $("#rightPanelContentHolder").hide('fast', function(){
		  loadRightContent(linkurl);
		  });
	  return false;
  });
  
  $('#divNews a').live('click', function(event){
	  var linkurl = $(this).attr("href");
	  $("#rightPanelContentHolder").hide('fast', function(){
		  loadRightContent(linkurl);
		  });
	  return false;
  });
  
  $(".divThumbnailGallery a").live('click', function(event){
	  var imgno = $(this).attr("rel");
	  var leftposition = $('.divThumbnailGallery').width() * (imgno - 1); 
	  $(".productimagereel").animate({
          left: -leftposition
      }, 500 );
	  return false;
  });
  
  $(".btnIncrement").live('click', function(event){
	  var quantity = $('#txtQuantity').val();
	  var newquant = parseInt(quantity) + 1;
	  $('#txtQuantity').val(newquant);
	  if($(".btnIncrement").parent().parent().hasClass('colquantity'))
	  {
		  var price = $(".btnIncrement").parent().parent().siblings('.pricehidden').val();
		  var subtotal = parseInt(newquant) * parseInt(price);
		  $(".btnIncrement").parent().parent().siblings('.colsubtotal').text('AED ' + subtotal);
		  var diff = newquant - parseInt(quantity);
		  var grandtotal = parseInt($('#grandtotal').text());
		  grandtotal = grandtotal + diff * parseInt(price);
		  $('#grandtotal').text(grandtotal);
		  var id = $(".btnIncrement").parent().parent().siblings('.idhidden').val();
		  $.ajax({
			  url: 'managebasket.php?id=' + id + '&count=' + newquant + '&mode=set',
		  	  success: function(data){
			  $('#lblCount').text('(' + data + ') items');
			  $('#lblCount1').text('(' + data + ') items');
		  	}
		  });
	  }
	  return false;
  });

  $(".btnDecrement").live('click', function(event){
	  var quantity = $('#txtQuantity').val();
	  if(quantity > 0)
	  {
		  $('#txtQuantity').val(quantity - 1);
		  if($(".btnDecrement").parent().parent().hasClass('colquantity'))
		  {
			  var price = $(".btnDecrement").parent().parent().siblings('.pricehidden').val();
			  var subtotal = (quantity - 1) * parseInt(price);
			  $(".btnDecrement").parent().parent().siblings('.colsubtotal').text('AED ' + subtotal);
			  var grandtotal = parseInt($('#grandtotal').text());
			  grandtotal = grandtotal - parseInt(price);
			  $('#grandtotal').text(grandtotal);
			  var id = $(".btnDecrement").parent().parent().siblings('.idhidden').val();
			  var newquant = quantity - 1;
			  $.ajax({
				  url: 'managebasket.php?id=' + id + '&count=' + newquant + '&mode=set',
			  	  success: function(data){
				  $('#lblCount').text('(' + data + ') items');
				  $('#lblCount1').text('(' + data + ') items');
			  	}
			  });
		  }
	  }
	  return false;
  });
  
  $("#divProductAddition .divAddButton a").live('click', function(event){
	  var rel = $(this).attr('rel');
	  var quantity = parseInt($('#txtQuantity').val());
	  $.lightspeed.itemcount = parseInt($.lightspeed.itemcount) + quantity;
	  
	  $.ajax({
		  url: 'managebasket.php?id=' + rel + '&count=' + quantity + '&mode=set',
		  success: function(data){
		  		$.lightspeed.itemcount = data;
		  		$('#lblCount').text('(' + $.lightspeed.itemcount + ') items');
		  		loadContent('inquirybasket.php', 'Inquiry Basket');
	  		}
	  });
	  return false;
  });
  
  $(".pagenumbering a").live('click', function(event){
	  var linkurl = $(this).attr("href");
	  var rel = $(this).attr("rel");
	  
	  var previouspage = $.lightspeed.pageno;
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('color', '#515558');
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('font-weight', 'normal');
	  
	  $.lightspeed.pageno = rel;
	  $('.pagenumbering a[rel="' + rel + '"]').css('color', "#3D8C00");
	  $('.pagenumbering a[rel="' + rel + '"]').css('font-weight', "bold");
	  
	  setnumberingimages();
	  
	  $("#divSearchContent").hide('fast', function(){
		  loadSearchContent(linkurl);
		  });
	  return false;
  });
  
  $("#imgBack1").live('click', function(e){
	  movePreviousPage();
  });
  
  $("#imgBack2").live('click', function(e){
	  movePreviousPage();
  });
  
  $("#imgNext1").live('click', function(e){
	  moveNextPage();
  });
  
  $("#imgNext2").live('click', function(e){
	  moveNextPage();
  });
  
  $("#divNewsLetter #btnSubscribe").live('click', function(event){
	  var id = $("#divNewsLetter .textNewsLetter").text();
	  subscribeNewsLetter(id);
	  return false;
  });
  
  $(".bottomList ul a").live('click', function(event){
	  return false;
  });
  
  $(".productPageItem").live('mouseover', function(event){
	  $(this).children(".heading").removeClass('heading').addClass('headingGreen');
  });
  
  $(".productPageItem").live('mouseleave', function(event){
	  $(this).children(".headingGreen").removeClass('headingGreen').addClass('heading');
  });
  
  $(".productPageItem .category").live('click', function(event){
	  navigationClicked($(this).attr("href"), $(this).attr("rel"));
	  return false;
  });
  
  $(".productPageItem .product").live('click', function(event){
	  showBreadcrumbProduct($(this).attr("rel"));
	  var linkurl = $(this).attr("href");
	  $("#rightPanelContentHolder").hide('fast', function(){
		  loadRightContent(linkurl);
		  });
	  return false;
  });
  
  $(".productdetailscroll").dotdotdot({
	  'height':50
	});
  
  $("#btncontinueshopping").live('click',function(event){
	  var rel = $(this).attr("rel");
	  var linkurl = $(this).attr("href");
	  $("#divContent").hide('fast', function(){
	  loadContent(linkurl, rel);
	  });
	  return false;
  	});
  
  $("#btnsendinquiry").live('click',function(event){
	  var rel = $(this).attr("rel");
	  var linkurl = $(this).attr("href");
	  $("#divContent").hide('fast', function(){
	  loadContent(linkurl, rel);
	  });
	  return false;
  	});
  
  $(".coldelete a").live('click',function(event){
	  var rel = $(this).attr("rel");
	  var linkurl = 'managebasket.php?id='+rel+'&mode=remove';
	  $.ajax({
		  url: linkurl,
		  success: function(data){
		  $.lightspeed.itemcount = data;
	  	  $('#lblCount').text('(' + $.lightspeed.itemcount + ') items');
		  $("#rightPanelContentHolder").hide('fast', function(){
			  loadRightContent('inquirybasket.php');
			  });
	  }
	  });
	  return false;
  	});
  
  $('#btnSend').live('click', function(){
	  var error = 0;
	  $('#formcontact input').each(function(){
		  
		  if($(this).text() == '')
		  {
			  error = 1;
			  return false;
		  }
	  
	  });
	  if(error == 0)
	  {
		  $('#formcontact').ajaxSubmit({ 
	          success: function(responseText){
	              $('#formcontact').each(function(){
	            	  this.reset();
	              });
	              }
	          });
	  }
	  return false;
  });
  
  $('#btnReset').live('click', function(){
	  $('#formcontact').each(function(){
    	  this.reset();
      });
	  return false;
  });
  
  $('.bottomcategories ul li a').live('click', function(){
	  linkurl = $(this).attr("href");
	  var rel = $(this).attr("rel");
	  $("#divRightPanel").css('height','auto');
		$("#divContent").empty().load('content.php', function(){
			$('#divContent').show('normal',function(){
				$("#divRightPanel").css('height','auto');
				$('#divNews .newstext').each(function(){
					  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
				  });
				  $('#divnewsupdates .newstext').each(function(){
					  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
				  });
				  
				  $('.divNewsContent').vTicker({
					  speed: 500,
					  pause: 4000,
					  animation: 'fade'
				  });
				navigationClicked(linkurl, rel);
				});
		});
		return false;
  });
  
  $('#expandercontent a').live('click', function(){
	  linkurl = $(this).attr("href");
	  var rel = $(this).attr("rel");
	  $("#divRightPanel").css('height','auto');
		$("#divContent").empty().load('content.php', function(){
			$('#divContent').show('normal',function(){
				$("#divRightPanel").css('height','auto');
				$('#divNews .newstext').each(function(){
					  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
				  });
				  $('#divnewsupdates .newstext').each(function(){
					  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
				  });
				  
				  $('.divNewsContent').vTicker({
					  speed: 500,
					  pause: 4000,
					  animation: 'fade'
				  });
				navigationClicked(linkurl, rel);
				});
		});
		return false;
  });
  
  $('#btnexpand').live('click', function(){
	  $('#expandercontent').animate({height: 250}, 'slow', function(){
		  $('#divcollapse').css('display', 'block');
		  $('#divexpand').css('display', 'none');
	  });
	  return false;
  });
  
  $('#btncollapse').live('click', function(){
	  $('#expandercontent').animate({height: 0}, 'slow', function(){
		  $('#divcollapse').css('display', 'none');
		  $('#divexpand').css('display', 'block');
	  });
	  return false;
  }); 
  
  $('.galleryproduct a').live('click', function(){
	  var linkurl = $(this).attr('href');
	  var rel=$(this).text();
	  loadContent(linkurl, rel, function(){
		  showBreadcrumbMenu('Products');
		  showBreadcrumbProduct(rel);
	  });
	  return false;
  });
  
//Show the paging and activate its first link
  $(".paging").show();
  $(".paging a:first").addClass("active");

  //Get size of the image, how many images there are, then determin the size of the image reel.
  var imageWidth = $(".window").width();
  var imageSum = $(".image_reel img").size();
  var imageReelWidth = imageWidth * imageSum;
  var now, before = new Date();
  //Adjust the image reel to its new size
  $(".image_reel").css({'width' : imageReelWidth});
  
//Paging  and Slider Function
  rotate = function(){
      var triggerID = $active.attr("rel") - 1; //Get number of times to slide
      var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

      $(".paging a").removeClass('active'); //Remove all active class
      $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

      //Slider Animation
      $(".image_reel").animate({
          left: -image_reelPosition
      }, 500 );

  }; 
  
  $(".image_reel a").hover(function() {
	    clearInterval(play); //Stop the rotation
	}, function() {
	    rotateSwitch(); //Resume rotation timer
	});
  
  //On Click
  $(".paging a").live('click', function() {
      $active = $(this); //Activate the clicked paging
      rotate(); //Trigger rotation immediately
      rotateSwitch();
      return false; //Prevent browser jump to link anchor
  });
  
//Rotation  and Timing Event
  rotateSwitch = function(){
      play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
    	  now = new Date();
    	    var elapsedTime = (now.getTime() - before.getTime());
    	    if(elapsedTime > 7000)
    	    {
		          $active = $('.paging a.active').next(); //Move to the next paging
		          if ( $active.length === 0) { //If paging reaches the end...
		              $active = $('.paging a:first'); //go back to first
		          }
		          rotate(); 
    	    }//Trigger the paging and slider function
    	    before = new Date();
      }, 7000); //Timer speed in milliseconds (7 seconds)
  };

  rotateSwitch();
  
});

function visualLength(str)
{
	  var ruler = $("#ruler");
	  $("#ruler").text(str);
    var retval = $("#ruler").width();
    return retval;
};

function trimToPx(tmp, length)
{
    var temptext = tmp;
    if(visualLength(tmp) > length)
    {
    	var trimmed = tmp + '...';
	    while(visualLength(trimmed) >= length)
	    {
	    	temptext = temptext.substring(0, temptext.length/2);
	    	trimmed = temptext + "...";
	    }
	    while (visualLength(trimmed) < length)
        {
	    	temptext = temptext + tmp.substring(temptext.length - 1, temptext.length);
            trimmed = temptext + "...";
        }
	    return trimmed;
    }
    else
    	return tmp;
};


function handleSliderChange(e, ui)
{
    var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
    $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
	var contentwidth = $("#content-holder").width();
	var scrollvalue = ui.value;
    var maxScroll = contentwidth - $("#content-scroll").width();
    var position = (maxScroll * scrollvalue)/100;
    
    $("#content-holder").animate({
        left: -position
    }, 10 );
}

function loadHome()
{
	$("#divRightPanel").css('height','auto');
	$("#divContent").empty().load('home.php', function(){
		//$('#divLoading #load').remove();
		$('#divContent').show('normal',afterloadContent);
	});
}

function loadContent(linkurl, rel, callback)
{
	//$('#divLoading').append('<span id="load" style="padding:20px;">LOADING...</span>');  
	//$('#load').fadeIn('normal');
	$("#divRightPanel").css('height','auto');
	$("#divContent").empty().load('content.php', function(){
		//$('#divLoading #load').remove();
		showBreadcrumbMenu(rel);
		$('#divContent').show('normal',function(){
			  
			  $('#divNews .newstext').each(function(){
				  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
			  });
			  $('#divnewsupdates .newstext').each(function(){
				  $(this).text(trimToPx($(this).text(), 2*($(this).width())));	  
			  });
			  
			  $('.divNewsContent').vTicker({
				  speed: 500,
				  pause: 4000,
				  animation: 'fade'
			  });
			loadRightContent(linkurl, callback); });
	});
}

function loadRightContent(linkurl, callback)
{
	$("#divRightPanel").css('height','auto');
	$.get(linkurl, function(data) {
		  $('#rightPanelContentHolder').html(data);
		  $.lightspeed.pageno = 1;
		  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('color', "#3D8C00");
		  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('font-weight', "bold");
		  $('#rightPanelContentHolder').show('normal',afterloadContent(callback));
		});
}

function loadSearchContent(linkurl)
{
	$("#divRightPanel").css('height','auto');
	$.get(linkurl, function(data) {
		  $('#divSearchContent').html(data);
		  $('#divSearchContent').show('normal',afterload);
		  
		});
}

function initpage()
{
	  $("#content-slider").slider({
	    animate: 'normal',
	    change: handleSliderChange,
	    slide: handleSliderSlide
	  });
	  
	//Show the paging and activate its first link
	  $(".paging").show();
	  $(".paging a:first").addClass("active");

	  //Get size of the image, how many images there are, then determin the size of the image reel.
	  var imageWidth = $(".window").width();
	  var imageSum = $(".image_reel img").size();
	  var imageReelWidth = imageWidth * imageSum;

	  //Adjust the image reel to its new size
	  $(".image_reel").css({'width' : imageReelWidth});
	  
	  rotateSwitch();
	  
	  var scrollitems = $(".searchdescription").size();
	  
	  $('.searchdescription').each(function(){
		  $(this).text(trimToPx($(this).text(), $(this).width()));	  
	  });
	  
	  
	  $(".productdetailscroll").dotdotdot({
			'height':50
		});
	  
}

function setrightheight()
{
	//var leftheight= $("#divleftPanel").innerHeight();
	//var rightheight = $("#rightPanelContentHolder").innerHeight();
	//var rightht = $('#divRightPanel').height();
	//if(leftheight > rightheight)
	//{
	//	$("#divRightPanel").innerHeight(leftheight);
	//}
}

function afterload()
{
	$(".productdetailscroll").dotdotdot({
		'height':50
	});
	
	
	  
	  setrightheight();
	  
	  $('.divImgLarge .imgMain').loupe({
		  width: 200, // width of magnifier
		  height: 150, // height of magnifier
		  loupe: 'loupe' // css class for magnifier
		});
}

function afterloadContent(callback)
{
	afterload();
	initpage();
	setrightheight();
	if(callback instanceof Function)
		callback();
}

function showBreadcrumbMenu(rel)
{
	if(rel == 'Products')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Products</a>');
	}
	else if(rel == 'Brands')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Brands</a>');
	}
	else if(rel == 'Buy')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Where to buy</a>');
	}
	else if(rel == 'Inquiry Basket')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Inquiry Basket</a>');
	}
	else if(rel == 'Contact')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Contact</a>');
	}
	else if(rel == 'About Us')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">About Us</a>');
	}
	else if(rel == 'News')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">News &amp; Update</a>');
	}
	else if(rel == 'Customer Services')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Customer Services</a>');
	}
	else if(rel == 'Terms and Conditions')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Terms and Conditions</a>');
	}
	else if(rel == 'Sitemap')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Sitemap</a>');
	}
	else if(rel == 'Help')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Help</a>');
	}
	else if(rel == 'FAQ')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">FAQ</a>');
	}
	else if(rel == 'Store Ads')
	{
		$('#dcnt').html('<a href="#" style="color:#3D8C00;font-weight:bold;">Store Ads</a>');
	}
}

function showBreadcrumbNavigation(rel,linkurl)
{
	$('#dcnt').html('<a href="javascript:void(0);" onclick="$(\'#divContent\').hide(\'fast\', function(){loadContent(\'getrightpanelcontent.php?menu=products\',\'Products\');});">Products</a><a href="javascript:void(0);" onclick="navigationClicked(\''+linkurl+'\',\''+rel+'\');" rel="'+rel+'" style="color:#3D8C00;font-weight:bold;">' + rel + '</a>');
}

function showBreadcrumbProduct(rel)
{
	$("#dcnt a").css('color','#515558');
	$("#dcnt a").css('font-weight', 'normal');
	var num = $('#dcnt a').length;
	if(num == 4)
	{
		alert("??");
		$('#dcnt a:last-child').remove();
	}
	else
	{
		$('#dcnt').append('<a href="#" rel="'+rel+'" style="color:#3D8C00;font-weight:bold;">' + rel + '</a>');
	}
}

function subscribeNewsLetter(id)
{
	$.post("subscribe.php", {email: id}, function(data){
	});
}

function navigationClicked(linkurl, rel)
{
	$("#navigationByCategory a").css('color','#515558');
	  $("#navigationByCategory a").css('font-weight','normal');
	  $("#navigationByBrand a").css('color','#515558');
	  $("#navigationByBrand a").css('font-weight','normal');
	  var selector1 = '#navigationByBrand a[rel="' + rel + '"]';
	  $(selector1).css('color', '#3D8C00');
	  $(selector1).css('font-weight', 'bold');
	  var selector2 = '#navigationByCategory a[rel="' + rel + '"]';
	  $(selector2).css('color', '#3D8C00');
	  $(selector2).css('font-weight', 'bold');
	  showBreadcrumbNavigation(rel,linkurl);
	  $("#rightPanelContentHolder").hide('fast', function(){
		  loadRightContent(linkurl);
		  });
}

function moveNextPage(pageno)
{
	var previouspage = $.lightspeed.pageno;
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('color', '#515558');
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('font-weight', 'normal');
	  
	  $.lightspeed.pageno = $.lightspeed.pageno + 1;
	  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('color', "#3D8C00");
	  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('font-weight', "bold");
	  
	  var linkurl = $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').attr('href');
	  
	  setnumberingimages();
	  
	  $("#divSearchContent").hide('fast', function(){
		  loadSearchContent(linkurl);
		  });
}

function movePreviousPage(pageno)
{
	var previouspage = $.lightspeed.pageno;
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('color', '#515558');
	  $('.pagenumbering a[rel="' + previouspage + '"]').css('font-weight', 'normal');
	  
	  $.lightspeed.pageno = $.lightspeed.pageno - 1;
	  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('color', "#3D8C00");
	  $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').css('font-weight', "bold");
	  
	  var linkurl = $('.pagenumbering a[rel="' + $.lightspeed.pageno + '"]').attr('href');
	  
	  setnumberingimages();
	  
	  $("#divSearchContent").hide('fast', function(){
		  loadSearchContent(linkurl);
		  });
}

function setnumberingimages()
{
	var length = $('.pagenumbering a').length/2;
	  if($.lightspeed.pageno == length)
	  {
		  $('#imgNext1').css('display', 'none');
		  $('#imgNext2').css('display', 'none');
	  }
	  else
	  {
		  $('#imgNext1').css('display', 'inline-block');
		  $('#imgNext2').css('display', 'inline-block');
	  }
	  if($.lightspeed.pageno == 1)
	  {
		  $('#imgBack1').css('display', 'none');
		  $('#imgBack2').css('display', 'none');
	  }
	  else
	  {
		  $('#imgBack1').css('display', 'inline-block');
		  $('#imgBack2').css('display', 'inline-block');
	  }
}

function setcount()
{
	$.get('getbasketcount.php', function(data){
		$.lightspeed.itemcount = data;
		$('#lblCount').text('('+$.lightspeed.itemcount+') items');
	});
}

