$(document).ready(function() 
{
    $('#slide').cycle({
		fx: 'fade'
	});
	
	randomAd();
	//randomSlide();
	
	textReplacement($('#search_query'));
	textReplacement($('#nl_first_name'));
	textReplacement($('#nl_email')); 
	textReplacement($('#login_email'));
	textReplacement($('#login_pass'));
	

	function textReplacement(input){
		var originalvalue = input.val();
		input.focus( function(){
			if( $.trim(input.val()) == originalvalue ){ input.val(''); }
		});
		input.blur( function(){
		if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
		});
	}
	
	function randomAd(){
	
		adcount = $("#bottom-ad a").size();
		//alert(adcount);
		var ri=Math.floor(Math.random()*adcount);
		//alert(ri);
	 
		if (ri==0) 
		{
			ri=1;
		}
		//var randomad = "#bottom-ad a:nth-child(" + ri + ")";
		//alert(randomad);
		$("#bottom-ad a:nth-child(" + ri + ")").css("display","block");
	  }
	  
	  function randomSlide(){
	  
		count = $("#slide a").size();
		//alert(count);
		var ri=Math.floor(Math.random()*count);
		//alert(ri);
	 
		if (ri==0) 
		{
			ri=1;
		}
		$("#slide a:nth-child(" + ri + ")").css("display","block");
	  }
	  
});

	function detectcurrency()
    {
		var currency = $('.ProductPriceRating .RetailPriceValue').html();
		currency = currency.substring(0,1);
		return(currency);  
	}
                                 
	function getPercentages()
	{
		var count = $('#CategoryContent .ProductList li').length; 
		var i = 1;
		var sprice = "";
		var rprice = "";
		var sprices = "";
		var curcur = detectcurrency();
		
		while ( count >= i )
		{
			if ($('.ProductList li:nth-child('+i+') .ProductPriceRating em .SalePrice').length > 0) {
				sprice = $('.ProductList li:nth-child('+i+') .ProductPriceRating em .SalePrice').html();
			} else {
				sprice = $('.ProductList li:nth-child('+i+') .ProductPriceRating em').html();
			}
			sprices = sprice.lastIndexOf(curcur);
			sprice = sprice.substring(sprices,sprices + sprice.length).replace(curcur,"");
			rprice = $('.ProductList li:nth-child('+i+') .ProductPriceRating strike').html();
			if (rprice != null)
			{
				rprice = rprice.replace(curcur,"");
				totalpercentage = rprice - sprice;
				totalpercentage = totalpercentage / rprice;
				totalpercentage = totalpercentage * 100;
				
				$('.ProductList li:nth-child('+i+') .Percentage').html('Save <br /><span>' + Math.round(totalpercentage) + "%<span>");
			} else {
				$('.ProductList li:nth-child('+i+') .Percentage').removeClass('Percentage');
			}
			
			i++;
		}
	}

