$(document).ready(function()
{
	/*TEMPLATES*/
	$("#plus").click(function(event){event.preventDefault();});
	$("#infotemplate").animate({opacity:0},0);
	$("#a1,#a2,#a3,#a4").animate({opacity:0.5},0);
	$("#template").hover(function(){
		$(this).stop().animate({width:100},500);
		$("#infotemplate").stop().animate({"top":115, opacity:1},500);
		}, function(){
		$(this).stop().animate({width:30},500);
		$("#infotemplate").stop().animate({"top":120, opacity:0},500);
	});
	$("#a1,#a2,#a3,#a4").hover(function(){
		$(this).stop().animate({opacity:1},250);
		}, function(){
		$(this).stop().animate({opacity:0.5},250);
	});
	
	/*CATEGORIE*/
    $("#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);	
	$("#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").click(function(){
		$("#form a").addClass("down");
		$("#form a").removeClass("up");
		$("#listcats").slideUp();
	});
});

/*SCROLLING*/
$(function(){
	$(window).scroll(function(){
		var scrollTop=$(window).scrollTop();
		if(scrollTop>160){setTimeout(function(){$("#ricerca").stop().animate({top:scrollTop-160},250);},1000)}
		else{setTimeout(function(){$("#ricerca").stop().animate({top:0},250);},1000)}
	});
});

