$(window).load(function () {

});

$(document).ready(function(){
	
	var newYear = new Date(); 
	newYear = new Date(2010, 7 - 1, 30, 20); 
//	$('#countDown').countdown({until: newYear, layout: '<strong>{dnn}</strong><strong>{hnn}</strong><strong>{mnn}</strong><strong>{snn}</strong>'});
	
	$('#countDown').countdown({until: newYear, layout: '<strong>{dnn}</strong><span>-</span><strong>{hnn}</strong><span>-</span><strong>{mnn}</strong><span>-</span><strong>{snn}</strong>'});

	if( $("#featured").size() ) {	
	
		maskLink();
	
		var featuredProductsPrev = $('#prevFeatured'),
			featuredProductsNext = $('#nextFeatured'),
			slideWidth = 780,
			holderPosition = 0,
			holder = $('#featuredContainer ul');
				
		var elementWidthTotal = holder.children().length * slideWidth;
			
	    holder.width(elementWidthTotal);
		
		var autoslide = setInterval (function () {
		    
		    if((holderPosition-slideWidth) > -(elementWidthTotal)) {
		    
		    	holderPosition = holderPosition - slideWidth;
		    	holder.animate({ 'left': holderPosition + 'px' }, {duration:1000, easing: 'easeOutCirc'});				
		    	$('#featuredContainer ul li.active').removeClass('active').next().addClass('active');
		    	
		    	
		    	maskLink();
		    }
		    
		    
		}, 7500);
		
		
		featuredProductsNext.bind('click', function() {
			
			if((holderPosition-slideWidth) > -(elementWidthTotal)) {
			
				holderPosition = holderPosition - slideWidth;
				holder.animate({ 'left': holderPosition + 'px' }, {duration:1000, easing: 'easeOutCirc'});				
				$('#featuredContainer ul li.active').removeClass('active').next().addClass('active');
				
				clearInterval(autoslide);
				
				maskLink();
			}
			
			
			return false;
				
		});
		
		featuredProductsPrev.bind('click', function() {
			
			if(holderPosition < 0) {
		
				holderPosition = holderPosition + slideWidth;
				holder.animate({ 'left': holderPosition + 'px' }, {duration:1000, easing: 'easeOutCirc'});
				$('#featuredContainer ul li.active').removeClass('active').prev().addClass('active');
				
				clearInterval(autoslide);
				
				maskLink();
			}
			
			return false;
			
		});
	
	
	}
	
	$(".colorbox").colorbox();


	if( $("#gallery").size() ) {
	
		$("#gallery a").colorbox();	
		$("#gallery img").imgCenter({
				scaleToFit: false,
				centerVertical: true,
				centerHorizontal: true
			});
		
		var featuredProductsPrev = $('#galleryPrev'),
			featuredProductsNext = $('#galleryNext'),
			slideWidth = 840,
			holderPosition = 0,
			holder = $('#gallery .overflow');
				
		if ( $("#gallery a").size() < 17 ) {
		
			$('#galleryPrev, #galleryNext').css("visibility", "hidden");
		
		}		
				
		var elementWidthTotal = holder.children().length * slideWidth;
			
		holder.width(elementWidthTotal);
		
		featuredProductsNext.bind('click', function() {
			
			if((holderPosition-slideWidth) > -(elementWidthTotal)) {
			
				holderPosition = holderPosition - slideWidth;
				holder.animate({ 'left': holderPosition + 'px' }, {duration:1000, easing: 'easeOutCirc'});				

			}
			
			
			return false;
				
		});
		
		featuredProductsPrev.bind('click', function() {
			
			if(holderPosition < 0) {
		
				holderPosition = holderPosition + slideWidth;
				holder.animate({ 'left': holderPosition + 'px' }, {duration:1000, easing: 'easeOutCirc'});

			}
			
			return false;
			
		});
	
	}
	
	function maskLink() {
		
		$('#featuredMask').click(function(){
			window.location = $('#featuredContainer ul li.active a').attr("href"); 
			return false;
		});
		
	}
	
//	swfobject.registerObject("youtubeVideo1", "9.0.0");
//	swfobject.registerObject("youtubeVideo2", "9.0.0");
		
	
});
