


$(document).ready(function() {
	
	// Initiates the Cycle Lite Plugin 
	$('#banner_home_page_top').cycle( {timeout: 7000, pause:1});
		
		
		
	//Functions to control the tabs on the homepage
	$('span#FeaturedTab').css('background-position', '0px -40px');
	
	$("span#FeaturedTab").click(
	
		function(){
			$('#HomepageTabs span').css('background-position', '0px 0px');
			$(this).css('background-position', '0px -40px');				
			$('#HomeNewProducts, #HomeSaleProducts').fadeOut(300);	
			$('#HomeFeaturedProducts').delay(300).fadeIn(300);		
	});
	
	$("span#LatestTab").click(
	
		function(){	
			$('#HomepageTabs span').css('background-position', '0px 0px');
			$(this).css('background-position', '0px -40px');
			$('#HomeFeaturedProducts, #HomeSaleProducts').fadeOut(300);	
			$('#HomeNewProducts').delay(300).fadeIn(300);		
	});
	
	$("span#SaleTab").click(
	
		function(){				
			$('#HomepageTabs span').css('background-position', '0px 0px');
			$(this).css('background-position', '0px -40px');
			$('#HomeNewProducts, #HomeFeaturedProducts').fadeOut(300);	
			$('#HomeSaleProducts').delay(300).fadeIn(300);		
	});
	

	//Functions to control the tabs on the Product Page
	$("span#DescriptionTab").click(
	
		function(){
			$('#ProductTabButtons span').css('background', '#88cff8');
			$(this).css('background', '#ffd200');				
			$('#ProductReviews, #SideProductRelated').fadeOut(300);	
			$('#ProductDescription').delay(300).fadeIn(300);		
	});
	
	$("span#RelatedProductsTab").click(
	
		function(){	
			$('#ProductTabButtons span').css('background', '#88cff8');
			$(this).css('background', '#ffd200');	
			$('#ProductDescription, #ProductReviews').fadeOut(300);	
			$('#SideProductRelated').delay(300).fadeIn(300);		
	});
	
	$("span#Reviewstab").click(
	
		function(){				
			$('#ProductTabButtons span').css('background', '#88cff8');
			$(this).css('background', '#ffd200');	
			$('#ProductDescription, #SideProductRelated').fadeOut(300);	
			$('#ProductReviews').delay(300).fadeIn(300);		
	});	
	
	
	
	
	//Dropdown Menu Script 	
	$('#Menu ul li').hover(	
		function(){					
			$(this).children('ul').stop(true,true).slideDown(3);},		
		function(){	
			
			$(this).children('ul').animate({opacity: '+=0'}, 100).slideUp(3); 		
	}); 


	
	//Resize Cart Images on the fly	
	var max_size = 50;
	$("td.CartThumb a img").each(function(i) {
	  if ($(this).height() > $(this).width()) {
		var h = max_size;
		var w = Math.ceil($(this).width() / $(this).height() * max_size);
	  } else {
		var w = max_size;
		var h = Math.ceil($(this).height() / $(this).width() * max_size);
	  }
	  $(this).css({ height: h, width: w });
	});
	
	//hide Empty Brand Images & Links 
	var ImgSrc = $("a.BrandLink img").attr("src");
	
	if (ImgSrc == 'http://www.organiccottonshop.ie/template/images/brands/.jpg') 
		{$('a.BrandLink').hide();}
		
		



    // Force the Class "ActivePage" on the Category Pages
    var loc = window.location.pathname;
	
	if (loc == '/categories/Clothes/') 
		{$('#Menu ul li:nth-child(2)').addClass('ActivePage');}
	else if (loc == '/categories/Toys/') 
		{$('#Menu ul li:nth-child(3)').addClass('ActivePage');}
	else if (loc == '/categories/Feeding-Time/') 
		{$('#Menu ul li:nth-child(4)').addClass('ActivePage');}
	else if (loc == '/categories/Accessories-/') 
		{$('#Menu ul li:nth-child(5)').addClass('ActivePage');}
	else if (loc == '/categories/Nappies-%26-Babywipes/') 
		{$('#Menu ul li:nth-child(6)').addClass('ActivePage');}
	
		
		
	
			
});
