// jQuery Document Ready
$(function(){
	var i;
	for (i in document.images) {
		if (document.images[i].src) {
			var imgSrc = document.images[i].src;
			if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
				document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
			}
		}
	}			
		
	//jQuery.noConflict();
				
	QueryLoader.selectorPreload = "body";
	QueryLoader.init();	
	
	$("#home").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-900"},{duration:2000, easing:'easeInOutExpo'}).animate({"opacity": "0"},500);
		$("#container").stop().delay(800).animate({"margin-left": "-900"},{duration:2000, easing:'easeInOutExpo'});
		$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
		$("#gallery_wrapper").stop().animate({"opacity": "0"},500,function() { $("#gallery_wrapper").hide(); });
	}); 
	
	
			
	$("#biografia").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-2800"},{duration:2000, easing:'easeInOutExpo'}).animate({"opacity": "0"},500,nascondi);
		$("#container").stop().delay(800).animate({"margin-left": "-2800"},{duration:2000, easing:'easeInOutExpo'});
		$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
		$("#gallery_wrapper").stop().animate({"opacity": "0"},500,function() { $("#gallery_wrapper").hide(); });
	}); 
	
	
	
	$("#filmografia").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-4200"},{duration:2000, easing:'easeInOutExpo'}).animate({"opacity": "0"},500,nascondi);
		$("#container").stop().delay(800).animate({"margin-left": "-4200"},{duration:2000, easing:'easeInOutExpo'});
		$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
	$("#gallery_wrapper").stop().animate({"opacity": "0"},500,function() { $("#gallery_wrapper").hide(); });
	}); 
	
	
	$("#news").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-5400"},{duration:2000, easing:'easeInOutExpo'}).animate({"opacity": "0"},500,nascondi);
		$("#container").stop().delay(800).animate({"margin-left": "-5400"},{duration:2000, easing:'easeInOutExpo'});
		$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
		$("#gallery_wrapper").stop().animate({"opacity": "0"},500,function() { $("#gallery_wrapper").hide(); });
	}); 
	
	
	$("#galleria").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-5800"},{duration:2000, easing:'easeInOutExpo'});//.animate({"opacity": "0"},500,nascondi);
		$("#container").stop().delay(800).animate({"margin-left": "-5800"},{duration:2000, easing:'easeInOutExpo'});
		$("#gallery_wrapper").show();
		$("#gallery_wrapper").stop().delay(2500).animate({"opacity":"1"},500);
		//$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		//$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
	}); 
	
	$("#contatti").click( function() {
		$("#nero_top").stop();			
		$("#nero_bottom").stop();
		$("#container2").stop();
		$("#container").stop();
		$("#container2").show();
		$("#nero_top").stop().animate({"height": "70px"},{duration:1000, easing:'easeInOutExpo'});			
		$("#nero_bottom").stop().animate({"margin-top": "181px"},{duration:1000, easing:'easeInOutExpo'});
		$("#container2").stop().delay(300).animate({"opacity": "1"},500).animate({"margin-left": "-7130"},{duration:2000, easing:'easeInOutExpo'}).animate({"opacity": "0"},500,nascondi);
		$("#container").stop().delay(800).animate({"margin-left": "-7130"},{duration:2000, easing:'easeInOutExpo'});
		$("#nero_top").delay(1300).animate({"height": "1px"},{duration:1000, easing:'easeInOutExpo'});	
		$("#nero_bottom").delay(1300).animate({"margin-top": "248px"},{duration:1000, easing:'easeInOutExpo'});
		$("#gallery_wrapper").stop().animate({"opacity": "0"},500,function() { $("#gallery_wrapper").hide(); });
	}); 
	

	//ROLLOVER MENU
	$("#menu_oriz a").hover(
		function () {
			$(this).stop().animate({"margin-top": "5px"}, 200);},
		function () {
			$(this).stop().animate({"margin-top": "0px"}, 200);}
	);

	function nascondi(){
		$("#container2").hide();
	}
	function visualizza(){
		$("#container2").show();
	}
	
	
	//SLIDEBOX
	var autoPlayTime=10000;
	autoPlayTimer = setInterval( autoPlay, autoPlayTime);
	
	function autoPlay(){
		Slidebox('next');
	}
	
	$('#slidebox .next').click(function () {
		Slidebox('next','stop');
	});
	
	$('#slidebox .previous').click(function () {
		Slidebox('previous','stop');
	});
	
	var yPosition=($('#slidebox').height()-$('#slidebox .next').height())/2;
	
	$('#slidebox .next').css('top',yPosition);
	$('#slidebox .previous').css('top',yPosition);
	$('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb');
	
	$("#slidebox .content").each(function(i){
		slideboxTotalContent=i*$('#slidebox').width();	
		$('#slidebox .container').css("width",slideboxTotalContent+$('#slidebox').width());
	});
	
	
	
	//SHADOWBOX
	Shadowbox.init({
		handleOversize: "resize",
		modal: true,
		onFinish:function(){
						$("#sb-overlay").one("click",function() { Shadowbox.close(); });
						}
	});
	
	
	
});


//RESIZE
$(window).load(function() {
	
	//TINYSCROLL
	$('#biocontent').tinyscrollbar();
	
	$('#newscontent').tinyscrollbar();
	
	
	$("#tS1").thumbnailScroller({
        scrollerType:"clickButtons",
        scrollerOrientation:"horizontal",
        scrollEasingAmount:600,
        scrollSpeed:1000
    });
	
	$("#gallery_wrapper").hide();
	$("#gallery_wrapper").css("opacity",0);

});
