var homepageProducts = [];


$(document).ready(function () {
//window.addEvent('domready', function() {
/* Homepage Products Details */
	if ($j("#homepagePromo") && homepageProducts){ 
		var len = homepageProducts.length;
		for(var i=0; i<len; i++){  
			var product = homepageProducts[i]; 
			if ($j("#showPro"+product) && $j("#productdetails"+product)){  
				$j("#showPro"+product).click(function(event) {
					$j(this).next().slideToggle(500,function(){  //this = showPro; this.next=productdetails
						if ($j(this).css("display")=='none'){    //this = productdetails							
							$j(this).prev().removeClass("productActive");						   
						}else {
							$j(this).prev().addClass("productActive");						   
						}
					});
					
				});
			}
		}
	}


	/* Virtual Cart */
	if ($j("#cart-total")){ 
		$j("#cart-total").click(function(event) {
			$j("#virtualcart").slideToggle(500,function(){
			})
		});
	}
	
	/* Catalog side banner */
	if ($j("#side-banner")){
		$j("#side-banner").mouseenter(function(){
			$j(this).fadeTo(100,0.7);
		});
		$j("#side-banner").mouseleave(function(){
			$j(this).fadeTo(100,1);
		});

	}
	
	/* Catalog Search Form - Expand search filter */
	if ($('productSearchFilter')){
		var fxSearchCatalogExpand = new Fx.Styles($('productSearchFilter'), {duration:300,wait:false,transition:Fx.Transitions.Quad.easeIn});
		var childNodes = $('productSearchFilter').childNodes;
				
		if ($('productSearchExpand')){
			//Expand
			$('productSearchExpand').addEvent('click',function(){			   
				fxSearchCatalogExpand.start({'height':'72px','opacity':1});	
				$('productSearchFilter').style.display='block';
				$('productSearchHide').style.visibility='visible';
				$('productSearchExpand').style.visibility='hidden';
			});
		}
		
		if ($('productSearchHide')){  
			//Hide 
			$('productSearchHide').addEvent('click',function(){ 
				fxSearchCatalogExpand.start({'height':'0px','opacity':0});	
				$('productSearchFilter').style.display='none';
				$('productSearchHide').style.visibility='hidden';
				$('productSearchExpand').style.visibility='visible';
			});
		}
	}
	
	
	
	
	
	/* More Related Products - jquery slideDown */
	if ($j("#btn-more-prod")){
		$j("#btn-more-prod").click(function(){
			$j("#more-related-prod").slideDown(500,function(){})
			$j("#btn-more-prod").css('display','none');	
		});
	}
	
	
	if ($('carousel-hero')){  

		/* Set number of slides */
		if ($('carousel-images')){  
			//calculate from number of images divide by 3 (3 images at one slide)
			var ulChildren = $('carousel-images').childNodes; 
			var slides = Math.ceil(ulChildren.length/2);
			var slides_active_nation = ulChildren.length-2;
		}else {
			var slides = 1;
			var slides_active_nation = 1;
		}
		
		var pos = 0;
		var offset = 186;  //how much to slide each time. 2 x 80px plus 2 x 13px margin 
		var offset_active_nation = 143
		var currentslide = 1;											// CURRENT SLIDE IS THE FIRST SLIDE

//		var heroImage = $('heroImage');								   
//		var imgFx = new Fx.Styles(heroImage, {duration: 300, transition: Fx.Transitions.Sine.easeOut});
// 		var imgFx2 = new Fx.Styles(heroImage, {duration: 200, transition: Fx.Transitions.Sine.easeOut});
//		
		if ($('carousel-wrapper')){
			var imgscroll = new Fx.Scroll('carousel-wrapper', {
   				offset: {'x': 0, 'y': 0},
				transition: Fx.Transitions.Cubic.easeOut 
			}).toLeft();
		}
		
		
		/* EVENTS - WHEN AN ARROW IS CLICKED THE THUMBNAILS SCROLL */
		if ($('carousel-prev')){
			$('carousel-prev').addEvent('click', function(event) { 
				event = new Event(event).stop();
				if(currentslide == 1) return;
				currentslide--;																	// CURRENT SLIDE IS ONE LESS
				pos += -(offset);															   // CHANGE SCROLL POSITION
				var imgscroll = new Fx.Scroll('carousel-wrapper', {
					offset: {'x': pos, 'y': 1},
					transition: Fx.Transitions.Cubic.easeOut 
				}).toLeft();
			});
		}
		
		if ($('carousel-prev-an')){
			$('carousel-prev-an').addEvent('click', function(event) { 
				event = new Event(event).stop();
				if(currentslide == 1) return;
				currentslide--;																	// CURRENT SLIDE IS ONE LESS
				pos += -(offset_active_nation);													// CHANGE SCROLL POSITION
				var imgscroll = new Fx.Scroll('carousel-wrapper', {
					offset: {'x': pos, 'y': 1},
					transition: Fx.Transitions.Cubic.easeOut 
				}).toLeft();
			});
		}

		if ($('carousel-next')){ 
			$('carousel-next').addEvent('click', function(event) { 
				//alert('next='+currentslide+'='+slides);							  
				event = new Event(event).stop();
				if(currentslide >= slides) return;
				currentslide++;
				pos += offset; 	
				var imgscroll = new Fx.Scroll('carousel-wrapper', {
					offset: {'x': pos, 'y': 1},
					transition: Fx.Transitions.Cubic.easeOut 
				}).toLeft();
			});
		}
		
		if ($('carousel-next-an')){ 
			$('carousel-next-an').addEvent('click', function(event) { 
				event = new Event(event).stop();
				if(currentslide >= slides_active_nation) return;
				currentslide++;
				pos += offset_active_nation; 
				var imgscroll = new Fx.Scroll('carousel-wrapper', {
					offset: {'x': pos, 'y': 1},
					transition: Fx.Transitions.Cubic.easeOut 
				}).toLeft();
			});
		}
	}
	

});