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

$(document).ready(function() {
	var buts = $('img.arrows');
	var slider = $('#slider');
	var imgs = $('#slider a > img');
	
	var nimg = imgs.length
	var maxtop = (-1) * (150 * (nimg-3));
	var mintop = (150 * (nimg-3));
	var top = 0;
	
	$('#slide-wrap').css({'height' : '446px', 'width' : '216px', 'margin-left' : '15px', 'overflow' : 'hidden', 'position':'relative'});
	slider.css({'position' : 'absolute', 'top' : ''+top+'px', 'left':'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');
				top = top - 150;
				if (top < maxtop) { top = maxtop; }
				slider.css({'opacity':'.5'});
				slider.animate({'top':''+top+'px', 'opacity':'1'});
			});
			break;
				
			case 1 : 
			$(this).bind('click', function (i) {
				
				if (top != 0)
				{
					top = top + 150;
					if (top > mintop) { top = mintop; }
					slider.css({'opacity':'.5'});
					slider.animate({'top':''+top+'px', 'opacity' : '1'});
				}
			});
			break;
		}
	});
	
	
	imgs.each(function(i){
		$(this).hover(function() {
			$(this).animate({'opacity' : '1'});
		}, function() {
			$(this).animate({'opacity' : '.8'});
		});

	});

});
