$(window).load(function(){

	$(".centrale h2 a").each(function(){ $(this).attr({"name":"int-" + $(this).attr("name")}); });

	$("#menu a").mouseenter(function(){ $(this).animate({top:0}, {duration: 500, easing: 'easeOutExpo'}); });
	$("#menu a").mouseleave(function(){ $(this).animate({top:0}, {duration: 500, easing: 'easeOutExpo'}); });
	$(".fiere li a img, .opacity img, .lang li img").mouseenter(function(){ $(this).css({"opacity":0.6}); });
	$(".fiere li a img, .opacity img, .lang li img").mouseleave(function(){ $(this).css({"opacity":1}); });
	$("#menu li").children("a").prepend("<img src='/images/bg-menu-sx.png' class='sx'/><img src='/images/bg-menu-dx.png' class='dx'/>");
	$(".scrollable").scrollable({circular:true}).navigator().autoscroll({interval:8000,autoplay:true,autopause:false});

	if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
		$(".preview a").attr({"rel":"prod"}).fancybox({"hideOnContentClick":true});
		$(".zoom").parent().fancybox({"hideOnContentClick":true});
	} else {
		$("#content .hid").css({"display":"none"});
		$(".preview").attr({"class":"preview02"});
		$("#content .preview02").mouseenter(function(){$(this).find("h3").css({"background":"#ab0000"});});
		$("#content .preview02").mouseleave(function(){$(this).find("h3").css({"background":"#303030"});});
		$(".scheda").css({"width":900});

		var temp = 1;
		$("#content .preview02").each(function(){
			var img = $(this).find("a").attr("href");
			var title = $(this).find("h3").html();
			$(this).find("a").attr({"href":"#data"+temp,"class":"gal","rel":"prod"}).fancybox({"hideOnContentClick":true});
			$(this).find("div").children("div").attr({"id":"data"+temp});
			$(this).find("h3").click(function(){ $(this).parent().find("a").trigger("click"); });
			$(this).find("div").children("div").prepend("<img src='"+img+"'/><h2>"+title+"</h2>");
			temp ++;
		});
	}

	if (location.hash != '') {
	    var a = $("a[name=int-" + location.hash.substring(1) + "]");
	    if (a.length) {
	        $('html,body').animate({
	            scrollTop: $(a).offset().top - 20
	        }, 'slow');
	    }
	}
	$("#bar li a").click(function(){
		var a = $("a[name=int-" + $(this).attr("href").split("#")[1] + "]");
	    if (a.length) {
	        $('html,body').animate({
	            scrollTop: $(a).offset().top - 20
	        }, 'slow');
	    }	 
	});

	$(".media").fancybox();

	$(".player").each(function(){
		var ident = $(this).attr("rel");
		$(this).fancybox({
			'hideOnContentClick': false,
			'onStart': function(){
				$f(ident, "/media/flowplayer-3.2.7.swf", "http://assets.vitamino.it/refrigera/"+ident+".mp4").load();
			},
			'callbackOnClose': function() {
				$f(ident).unload();
				$("#fancy_content").empty();
			}
		});
	});

	/* --- Fix per webkit: remove deprecated layerX e layerY --- */
	(function(){
	    var all = $.event.props, len = all.length, res = [];
	    while (len--) {
	      var el = all[len];
	      if (el != 'layerX' && el != 'layerY') res.push(el);
	    }
	    $.event.props = res;
	}());
});
