jQuery(document).ready(function($){

	// Products dock
	var numprod = 10;					// products per line
	var widthprod = 160;				// total width of every product item (incl. margin and borders)
	var scrollnumprod = 5;				// how many products to scroll at once
	var scrolldiv_id = '#dock-prods'; 	// id of the element to scroll
	var morph_duration = 300; 			// duration of the element morphing

	// Actions to perform on page load
	$(scrolldiv_id).animate({marginLeft: 0}, 600);
	
	// Prev/Next buttons events
	$('#dock-next').click(function() {
		var scroll_div = $(scrolldiv_id);
		if(parseInt(scroll_div.css('margin-left')) > 0-((widthprod*numprod)-(widthprod*scrollnumprod))) {
			var offset = parseInt(scroll_div.css('margin-left'))-(widthprod*scrollnumprod);			if(offset <= 0-(widthprod*scrollnumprod)) { offset = 0-(widthprod*scrollnumprod); }
			scroll_div.animate({marginLeft: offset}, 600);		};	});
	
	$('#dock-prev').click(function() {		var scroll_div = $(scrolldiv_id);
		if(parseInt(scroll_div.css('margin-left')) < 0) {
			var offset = parseInt(scroll_div.css('margin-left'))+(widthprod*scrollnumprod);
			if(offset >= 0) { offset = 0; }			scroll_div.animate({marginLeft: offset}, 600);
		};	});	

	// Products thumbnails actions
	var count = 1;
	$('.dock-prod img').each(function(index,element) {
		
		var span = $(element).parent().find('span');
		span.css('opacity', 0);
		$(element).css({width: 100, height: 100, margin: 30});
		var c = count;
		count++;

		$(element).hover(function() {
			$(element).animate({width: 156, height: 156, margin: 0}, morph_duration);
			$(span).animate({opacity: 1}, morph_duration);
		}, function(){
			$(element).animate({width: 100, height: 100, margin: 30}, morph_duration);
			$(span).animate({opacity: 0}, morph_duration);
		}); 
	});
});

jQuery(window).load(function(){

	// Nivo Slider config
	jQuery('.nivoSlider').nivoSlider({
		effect:'sliceDown',
		slices:20,
		animSpeed:500,
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:1, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});



