$(document).ready(function()
{
	/*IMMAGINI HOMEPAGE*/
	$("#gallery img").css("display","block");
	$("#gallery").innerfade({animationtype: 'fade', speed: 1000, timeout: 10000});
	
	/*SLIDER IMMAGINI*/
	var margine=0;
	var i=0;
	var limite=0;
	$("#slider img").each(function(){i++;limite=346*(i-1);}); 
	  $("#nav a.next").click(function (event){
		if(margine > -limite){margine=margine-346;}
		else{margine=0;}
		$("#slider").animate({ marginLeft: margine}, 500 );
		event.preventDefault();
		$(this).blur();
	  });
	  $("#nav a.prev").click(function (event){
		if(margine == 0){margine=-limite;}
		else{margine=margine+346;}
		$("#slider").animate({ marginLeft: margine}, 500 );
		event.preventDefault();
		$(this).blur();
	  });

	/*DIDASCALIE IMMAGINI*/
	$(".didascalia, .more").animate({opacity:0},0);
	$(".image").hover(function(){
		$(this).children(".didascalia").stop().animate({opacity:1},500);
		}, function(){
		$(this).children(".didascalia").stop().animate({opacity:0},1000);
	});
	$(".blocco").hover(function(){
		$(this).children(".more").stop().animate({opacity:1},500);
		}, function(){
		$(this).children(".more").stop().animate({opacity:0},1000);
	});
	$("#nav a.next, #nav a.prev").click(function(){
		setTimeout(function(){$(".didascalia").stop().animate({opacity:1},500,function(){
			setTimeout(function(){$(".didascalia").stop().animate({opacity:0},1000);},1500);});
		},500);
	});
	
	/*BUTTON DETTAGLI
	$(".more").hover(function(){
		$(this).stop().animate({backgroundColor: "#202e40"}, 150);
		}, function(){
		$(this).stop().animate({backgroundColor: "#6897cf"}, 300);
	});*/

  /*  $("#listcats li").click(function(){
		var classe=$(this).attr("class");
		if(classe=="top"){$('html, body').animate({scrollTop: 0}, 1000);}
		else
		{
			var scrolling=$("#"+ classe).offset().top;
			$('html, body').animate({scrollTop: scrolling}, 1000);
			return false;
		}
	});

	$("#listcats").slideUp(0);
	$("#topmenu a, button").animate({opacity: "0.5"}, 1000);
	$("#topmenu a, button").hover(function(){
		$(this).stop().animate({opacity: "1", color: "#ff0000"}, 250);
		}, function(){
		$(this).stop().animate({opacity: "0.5", color: "#ffffff"}, 500);
	});	
	$("#right img").animate({opacity: "1"}, 0);
	$("#right img").hover(function(){
		$(this).stop().animate({opacity: "0.5"}, 250);
		}, function(){
		$(this).stop().animate({opacity: "1"}, 500);
	});
	$("#right a, #pdf a").hover(function(){
		$(this).stop().animate({color: "#ff0000"}, 250);
		}, function(){
		$(this).stop().animate({color: "#ffffff"}, 500);
	});
	
	$("#form a").addClass("down");
	$("#form a").click(function(event){
		var classe=$(this).attr("class");
		if(classe=="down")
		{
			$("#listcats").slideDown();
			$(this).addClass("up");
			$(this).removeClass("down");
			event.preventDefault();
			$(this).blur();
			return false;
		}
		else
		{
			$("#listcats").slideUp();
			$(this).addClass("down");
			$(this).removeClass("up");
			event.preventDefault();
			$(this).blur();
			return false;	
		}
	});
	$("#listcats li").hover(function(){
		//$(this).stop().animate({backgroundColor: "#990000", color: "#ffffff"}, 250);
		$(this).siblings().stop().animate({opacity: "0.5"}, 1000);
		}, function(){
		//$(this).stop().animate({backgroundColor: "#ffffff", color: "#333333"}, 500);
		$(this).siblings().stop().animate({opacity: "1"}, 1000);
	});
	$("#listcats li").click(function(){
		$("#form a").addClass("down");
		$("#form a").removeClass("up");
		$("#listcats").slideUp();
	});
});

$(function(){
	$(window).scroll(function(){
		var scrollTop=$(window).scrollTop();
		if(scrollTop!=0){$("#ricerca").stop().animate({opacity:"0.2"},500);}
		else{$("#ricerca").stop().animate({opacity:"1"},250);}
	});

	$("#ricerca").hover(function(e){
		var scrollTop=$(window).scrollTop();
		if(scrollTop!=0){$("#ricerca").stop().animate({opacity:"1"},250);}
		},	function(e){
		var scrollTop=$(window).scrollTop();
		if(scrollTop!=0){$("#ricerca").stop().animate({opacity:"0.2"},500);}
	});*/
});
