// JavaScript Document
/** Lavora con jQuery **/

$(document).ready(function() {
	var buts = $('.gallery.button');
	var slider = $('#slider');
	var imgs = $('#slider a > img');
	
	var nimg = imgs.length
	var maxleft = (-1) * (135 * (nimg-3));
	var minleft = ((135) * (nimg-3));
	var left = 0;
	
	$('#slide-wrap').css({'width' : '406px','height' : '135px', 'overflow' : 'hidden', 'position':'relative', 'margin':'auto', 'background-color':'#FFF', 'margin-top':'12px', 'float':'left'});
	slider.css({'position' : 'absolute', 'left' : ''+left+'px', 'top':'0px'});
	imgs.css({'opacity':'.8'});
	buts.css({'opacity':'.7'});
	
	buts.each(function(i){
		$(this).hover(function() {
			$(this).animate({'opacity' : '1'});
		}, function() {
			$(this).animate({'opacity' : '.7'});
		});

		switch(i) {
			case 0 : 
			$(this).bind('click', function (i) {
				//alert('scorri giu');
				left = left - 135;
				if (left < maxleft) { left = maxleft; }
				slider.css({'opacity':'.7'});
				slider.animate({'left':''+left+'px', 'opacity':'1'});
			});
			break;
				
			case 1 : 
			$(this).bind('click', function (i) {
				if (left != 0)
				{
				
				left = left + 135;
				if (left > minleft) { left = minleft; }
				slider.css({'opacity':'.7'});
				slider.animate({'left':''+left+'px', 'opacity' : '1'});
				
				}
			});
			break;
		}
	});
	
	
	imgs.each(function(i){
		$(this).hover(function() {
			$(this).animate({'opacity' : '1'},200);
		}, function() {
			$(this).animate({'opacity' : '.8'});
		});

	});

});
