/* funzioni ------------------------------------------------------- */

function showDevices() {
	$('#mobile').fadeIn('fast',function(){
		$('#multimedia').fadeIn('fast',function(){
			$('#community').fadeIn('fast',function(){
				$('#notebook').fadeIn('fast');			
			});
		});							 
	});
}

function centerElement(element) {
	var w1 = $(window).width();
	var w2 = $('#'+element).width();
	var h1 = $(window).height();
	var h2 = $('#'+element).height();
	var left = (w1/2)-(w2/2);
	var top = (h1/2)-(h2/2);
	$('#'+element).css('left',left);
	$('#'+element).css('top',top);
}

function positionElement(element) {
	var w = $(window).width() / 2;
	var h = $(window).height() / 2;
	switch(element) {
		case 'mobile':
			$('#mobile').css('top',h-302+'px');
			$('#mobile').css('left',w-463+'px');
			break;	
		case 'multimedia':
			$('#multimedia').css('top',h-302+'px');
			$('#multimedia').css('left',w+20+'px');
			break;	
		case 'community':
			$('#community').css('top',h+'px');
			$('#community').css('left',w+13+'px');
			break;	
		case 'notebook':
			$('#notebook').css('top',h+'px');
			$('#notebook').css('left',w-456+'px');
			break;
		case 'plus-button':
		case 'plus-container':
		case 'finger-button':
		case 'finger-container':
			var h1 = $(window).height();
			var h2 = $('#'+element).height();
			$('#'+element).css('top',(h1/2)-(h2/2));
			break;
	}

}

/* comportamenti ------------------------------------------------------- */

//riposiziona gli oggetti ad ogni resize
$(window).resize(function() {
	centerElement('logo-container');	
	positionElement('mobile');
	positionElement('notebook');
	positionElement('multimedia');
	positionElement('community');
	positionElement('info-container');
	positionElement('kubox-container');
	positionElement('plus-button');
	positionElement('plus-container');
	positionElement('finger-button');
	positionElement('finger-container');
});

//mostra e nasconde le frecce per lo scrolling
$('#content-container').hover(
	function(){
		$('.jspVerticalBar').show();
		$('.jspArrow').fadeTo('slow',0.4);
	},
	function(){
		$('.jspVerticalBar').hide();
		$('.jspArrow').fadeTo('fast',1);
});

//mostra e nasconde la voce di menu attuale
$('#content-container li').hover(
	function(){$(this).fadeTo('fast',1)},
	function(){$(this).fadeTo('fast',0.5)}
);

//mostra il logo e i device in sequenza
$('#logo-container').fadeIn('slow',function(){
	showDevices();
});

//inizializza lo scroller
$('#content').jScrollPane({
	showArrows: true,
	arrowScrollOnHover: false
});
$('.jspVerticalBar').css('right',32);

//apre il plus box
$('#plus-button').click(function(){
	$('#plus-container').show().animate({width:'300px'}, 500);							 							 
});

//chiude il plus box
$('#plus-container').click(function(){
	$('#plus-container').animate({width:'0'}, 500, function(){
		$('#plus-container').hide();													   
	});	
});

//apre il finger box
$('#finger-button').click(function(){
	$('#finger-container').show().animate({width:'300px'}, 500);							 						 
});

//chiude il finger box
$('#finger-container').click(function(){
	$('#finger-container').animate({width:'0'}, 500, function(){
		$('#finger-container').hide();													   
	});	
});

//rende trasparenti le voci del menu
$('#content-container li').fadeTo('fast', 0.5);

//mostra e nasconde il contenuto del prisma
$('#flap').click(function(){
	if 	($(this).attr('src') == 'assets/templates/kubox/images/button_play_homepage.png') {				  
		$('#content-container').slideDown();
		$(this).attr('src','assets/templates/kubox/images/button_close_homepage.png');
		$(this).attr('alt','Close');
	} else {
		$('#content-container').slideUp();
		$(this).attr('src','assets/templates/kubox/images/button_play_homepage.png');
		$(this).attr('alt','Play');
	}
});


//se sono in homepage chiudo il prisma
if ($('#flap').attr('src') == 'assets/templates/kubox/images/button_play_homepage.png') {	
	$('#content-container').slideUp();
}

Shadowbox.init({counterType: 'skip'});
