$(document).ready(function(){	
						
	var $lefty = $("#menu");
	$lefty.delay(600).animate({left: parseInt($lefty.css('left'),10) == 0 ? -$lefty.outerWidth() : 0});
				
	var $bottom = $("#credits");
	$bottom.delay(600).animate({bottom: parseInt($bottom.css('bottom'),10) == 0 ? -$bottom.outerHeight() : 0});
	
	var $pannelloAperto = false;
	
	$("body").supersleight();
		
	$("a[rel=gallery]").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("a[rel=gallery2]").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("a[rel=gallery3]").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
		
	$("a[rel=video]").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'		: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
		
		return false;
	});		

	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		transition: 6, // 0-none, 1-use random transition (0-7)
		transitionout: 1,
		vertical_center: 0,
		preload: 1,
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 20000, // interval for the slideshow
		randomimage: 1, // 0-none, 1-random image
		speed: 'slow' // animation speed
	};

	// initialize SuperBGImage
	$("#bg").superbgimage().hide();
	
	$('.scroller-1').scrollbar();
	$('.scroller-2').scrollbar();
	$('.scroller-3').scrollbar();
	
	$(window).resize(function() {
		if (!pannelloAperto) 
			$('#panel-1, #panel-2, #panel-3, #panel-4, #panel-5, #panel-6, #panel-7').css({'top': '-100%'});
	});
	
	Cufon.replace('#menuInt a, #cv a', {
	hover: true
	});
	Cufon.replace('h1, h2, #cv, .t');
	
	////////////////////////				   
	//FUNZIONI DI APERTURA//
	////////////////////////
	
	$(".btn-1").click(function() { funzioneDiApertura("1"); });
	$(".btn-2").click(function() { funzioneDiApertura("2"); });
	$(".btn-3").click(function() { funzioneDiApertura("3"); });
	$(".btn-4").click(function() { funzioneDiApertura("4"); });
	$(".btn-5").click(function() { funzioneDiApertura("5"); });
	$(".btn-6").click(function() { funzioneDiApertura("6"); });
	$(".btn-7").click(function() { funzioneDiApertura("7"); });
	
	////////////////////////				   
	//FUNZIONI DI CHIUSURA//
	////////////////////////
	
	$(".close-1").click(function() { funzioneDiChiusura("1"); });
	$(".close-2").click(function() { funzioneDiChiusura("2"); });
	$(".close-3").click(function() { funzioneDiChiusura("3"); });
	$(".close-4").click(function() { funzioneDiChiusura("4"); });
	$(".close-5").click(function() { funzioneDiChiusura("5"); });
	$(".close-6").click(function() { funzioneDiChiusura("6"); });
	$(".close-7").click(function() { funzioneDiChiusura("7"); });
	
});

function funzioneDiChiusura(k)
{
	var $topy = $("#panel-" + k);
	$topy.animate({top: parseInt($topy.css('top'),10) == 0 ? -$topy.outerHeight() : 0});
	  
	var $lefty = $("#menu");
	$lefty.delay(600).animate({left: parseInt($lefty.css('left'),10) == 0 ? -$lefty.outerWidth() : 0});
		  
	var $bottom = $("#credits");
	$bottom.delay(600).animate({bottom: parseInt($bottom.css('bottom'),10) == 0 ? -$bottom.outerHeight() : 0});
	  
	pannelloAperto = false;
}

function funzioneDiApertura(k)
{
	var $topy = $("#panel-" + k);
	$topy.delay(600).animate({top: [ parseInt($topy.css('top'),10) == 0 ? -$topy.outerHeight() : 0, 'easeOutCirc' ]});
	
	var $lefty = $("#menu");
	$lefty.animate({left: [ parseInt($lefty.css('left'),10) == 0 ? -$lefty.outerWidth() : 0, 'easeOutCirc' ]});
	
	var $bottom = $("#credits");
	$bottom.animate({bottom: parseInt($bottom.css('bottom'),10) == 0 ? -$bottom.outerHeight() : 0});
	
	pannelloAperto = true;
}




