// INDEX //

$(window).load(function() {
	if($.browser.msie && jQuery.browser.version == "6.0" || $.browser.msie && jQuery.browser.version == "7.0" || $.browser.msie && jQuery.browser.version == "8.0"){
		$('#wrap .container').append('<div class="msc_ban"><a class="over_palla_ie" href="/msc"><img src="/style/images/palla_msc.png" alt=""/></a></div>');

		
	} else {
	$('body').css('background','#fff   url(../../style/images/bg.jpg) no-repeat center 684px');
	
	}
	// riposizionamento globale
	
	function give_position(){
	$('#wrap').css('height',$(window).height());
	$('#index #content').css('height',$('#wrap').height()-76-82);
	 $('#parallax').css('width',$(window).width()+'px');

	$('#logo').css('top',$('#index #content').height()-34-$('#logo').height()+'px');
	$('#index .destra .box').css('padding-top',240-(684-$('#index #content').height()));
	$('#barra_logo').css('width',($(window).width()-(parseInt($('#logo img').css('width'))+$('#logo img').offset().left))+'px');
	$('#copy').css('left',60+(20/110)*(684-$('#index #content').height())+'px');
	$('#itemSunsation').css('width',($(window).width()-$('.sinistraContent').offset().left)+'px');
	$('#itemSunsation').css('top',-((30/110)*(684-$('#index #content').height()))+'px');
	$('#lights').css('top',parseInt($('#itemSunsation').css('top'))-15+'px');
	$('#copy,#credits').css('bottom',-80+(40/110)*(684-$('#index #content').height())+'px');
	$('#player').css('bottom',-51+(40/110)*(684-$('#index #content').height())+'px');
	$('#crediti').css('bottom',-40+(27/110)*(684-$('#index #content').height())+'px');

	}
	
	give_position();
	
	Cufon.replace('#index .destra .box h1',{ fontFamily: 'Lane' ,  hover: false });
	
	// solo per IE8-
	
	if($.browser.msie && jQuery.browser.version == "6.0" || $.browser.msie && jQuery.browser.version == "7.0" || $.browser.msie && jQuery.browser.version == "8.0"){
		$('#parallax').remove();
		$('#sun_1').css('left','171px');
		$('#sun_2').css('left','400px');
	} else { 
		
	// tutto il resto
	$('body').css('background-position','50% '+$('#index #content').height()+'px');
	// condizioni iniziali
//		Cufon.replace('#index .destra .box p',{ fontFamily: 'HelveticaLT' ,  hover: true });
	$('#sun_1').css('left','450px');
	$('#sun_1').css('opacity','0');
	$('#sun_2').css('left','600px');
	$('#sun_2').css('opacity','0');
	$('#index .destra .box h1').css('marginLeft','100px');
	$('#index .destra .box h1').css('opacity','0');

	$('#index .destra .box p').css('marginLeft','103px');
	$('#index .destra .box p').css('opacity','0');
	


	
	// due soli
	
	$('#lights').css('display','none');
	$('#palla01').css('display','none');
	$('#palla02').css('display','none');
	$('#palla03').css('display','none');
	$('#palla04').css('display','none');
	$('#palla05').css('display','none');
	$('#palla06').css('display','none');
	$('#palla07').css('display','none');
	
	
	// intro pagina
	$('#sun_1').oneTime(400, function(){
		
		$('#sun_1').animate({
		  opacity:1,
		   left:171,
		 }, 1000,'easeOutQuart');
	
		$('.sole_grande').animate({
		 rotate:'-30deg',
		  
		 }, 200,'easeOutCubic');});
	
	$('.sole_grande').oneTime(600, function(){$('.sole_grande').animate({
		 rotate:'0deg',
		  
	 }, 3200,'easeOutElastic');});
	
	$('#sun_2').oneTime(700, function(){
		
		$('#sun_2').animate({
		  opacity:1,
		   left:400,
		 }, 900,'easeOutQuart');
	
		$('.sole_piccolo').animate({
		 rotate:'-20deg',
		  
		 }, 200,'easeOutCubic');});
	
	$('.sole_piccolo').oneTime(900, function(){$('.sole_piccolo').animate({
		 rotate:'0deg',
		  
	 }, 2400,'easeOutElastic');});
	$('#palla01').oneTime(2460, function(){$('#palla01').fadeIn(500);});	
	$('#palla02').oneTime(2540, function(){$('#palla02').fadeIn(500);});	
	$('#palla03').oneTime(2600, function(){$('#palla03').fadeIn(500);});	
	$('#lights').oneTime(1600, function(){$('#lights').fadeIn(800);});
	$('#palla04').oneTime(2700, function(){$('#palla04').fadeIn(600);});	
	$('#palla05').oneTime(2760, function(){$('#palla05').fadeIn(600);});	
	$('#palla06').oneTime(2820, function(){$('#palla06').fadeIn(600);});
	$('#palla07').oneTime(3000, function(){$('#palla07').fadeIn(600);});
	
	
	//$('#sun_1 .sole_grande').animate({rotate: '0deg'}, 1700,'easeOutElastic');
	
	$('#index .destra .box h1').oneTime(3500, function(){
	
		

		$('#index .destra .box h1').animate({
		  opacity:1,
		   marginLeft:0,
		    
	  }, 1200,'easeOutCubic');});
	
	$('#index .destra .box p').oneTime(3700, function(){
		
		$('#index .destra .box p').animate({
		  opacity:1,
		   marginLeft:0,
		    
	  }, 1200,'easeOutCubic');});
	
	
	$('#parallax').css('width',$(window).width()+'px');
	
	
	$('#parallax').css('height',$('#index #content').css('height'));	
	
	$('#palla01').css('width',$(window).width()+100+'px');
	$('#palla02').css('width',$(window).width()+150+'px');
	$('#palla03').css('width',$(window).width()+200+'px');
	$('#palla04').css('width',$(window).width()+50+'px');
	$('#palla05').css('width',$(window).width()+100+'px');
	$('#palla06').css('width',$(window).width()+150+'px');
	$('#palla07').css('width',$(window).width()+300+'px');
	
	
	
	$('#sfondo_luce').css('display','block');

	var parallax_y_max_move; 
	parallax_y_max_move= 100-70/110*(684-$('#index #content').height())
	$('#parallax').jparallax({frameDuration:25},{ytravel:''+parallax_y_max_move+'%'},{ytravel:''+parallax_y_max_move+'%'},{ytravel:''+parallax_y_max_move+'%'},{ytravel:''+parallax_y_max_move+'%'},{ytravel:''+parallax_y_max_move+'%'},{ytravel:''+parallax_y_max_move+'%'},{xtravel:'5%',ytravel:''+parallax_y_max_move+'%'},{xtravel:'70%'});

    
	// rimbalzino soli
	
	 var i_grande=0;
	 var mousePos_1_grande = 0;
	 var mousePos_2_grande = 0;
	 var stop1_grande = false;
	 var stop2_grande = false;
	 var animating_grande = false;
	 
	 var i_piccolo=0;
	 var mousePos_1_piccolo = 0;
	 var mousePos_2_piccolo = 0;
	 var stop1_piccolo = false;
	 var stop2_piccolo = false;
	 var animating_piccolo = false;
     
	 
	 
	 // tentativo 2
	 /*function start_drag_sole_grande(){
		 if (animating == false){
		 $('.sole_grande').unbind('mouseenter',start_drag_sole_grande);
		 $('body').bind('mousemove',drag_sole_grande);
		 }
	 };
	 
	 function stop_drag_sole_grande(){
		 $('.sole_grande').bind('mouseenter',start_drag_sole_grande);
		 $('body').unbind('mousemove',drag_sole_grande);
		 animating = true;
		 $('.sole_grande').animate({
			 rotate:'0deg',
			  
		 }, 2000,'easeOutElastic', function(){animating = false;});
	 };

	function drag_sole_grande(e){
		if(e.pageX > $('#sun_1 .sole_grande').offset().left && e.pageX < $('#sun_1 .sole_grande').offset().left+$('#sun_1 .sole_grande').width() &&  e.pageY > $('#sun_1 .sole_grande').offset().top+250 && e.pageY < $('#sun_1 .sole_grande').offset().top+$('#sun_1 .sole_grande').height() && animating == false){
			$('#sun_1 .sole_grande').css('transform', 'rotate('+Math.round(30-((e.pageX-$('#sun_1 .sole_grande').offset().left)/3.5))+'deg)');
			
		}
	}
	 



	$('.sole_grande').bind('mouseenter',start_drag_sole_grande);
	$('.sole_grande').bind('mouseleave',stop_drag_sole_grande);*/
	 
	
	 
	 function controlla_hit_sole_grande(e){
		if(e.pageX > $('#sun_1 .sole_grande').offset().left && e.pageX < $('#sun_1 .sole_grande').offset().left+$('#sun_1 .sole_grande').width() &&  e.pageY > $('#sun_1 .sole_grande').offset().top+250 && e.pageY < $('#sun_1 .sole_grande').offset().top+$('#sun_1 .sole_grande').height() && animating_grande == false) {
		
		if(!stop1_grande){
			mousePos_1_grande = e.pageX;
			stop1_grande = true;
		}
		
		mousePos_2_grande = e.pageX;
		
		if(!stop2_grande){
			stop2_grande = true;
			setTimeout(function (){
			
				
				if(mousePos_2_grande > mousePos_1_grande){
				$('.sole_grande').stop().animate({
					 rotate:-((mousePos_2_grande-mousePos_1_grande)/8)+'deg'
					  
				 }, 200,'easeOutCubic');
				} else {
					$('.sole_grande').stop().animate({
						 rotate:((mousePos_1_grande-mousePos_2_grande)/8)+'deg'
						  
					 }, 200,'easeOutCubic');
					
				}
				$('.sole_grande').oneTime(200, function(){$('.sole_grande').stop().animate({
					 rotate:'0deg',
					  
				 }, 1800,'easeOutElastic');});
				
				
			},50);
		}
	}
}
	 $('body').bind('mousemove',controlla_hit_sole_grande);
	 $('#sun_1 .sole_grande').mouseleave(function(){
			stop1_grande = false
			stop2_grande = false;	 
	 }); 
	 
 
 
	 function controlla_hit_sole_piccolo(e){
		if(e.pageX > $('#sun_2 .sole_piccolo').offset().left && e.pageX < $('#sun_2 .sole_piccolo').offset().left+$('#sun_2 .sole_piccolo').width() &&  e.pageY > $('#sun_2 .sole_piccolo').offset().top+250 && e.pageY < $('#sun_2 .sole_piccolo').offset().top+$('#sun_2 .sole_piccolo').height() && animating_piccolo == false) {
		
		if(!stop1_piccolo){
			mousePos_1_piccolo = e.pageX;
			stop1_piccolo = true;
		}
		
		mousePos_2_piccolo = e.pageX;
		
		if(!stop2_piccolo){
			stop2_piccolo = true;
			setTimeout(function (){
			
			
				if(mousePos_2_piccolo > mousePos_1_piccolo){
				$('.sole_piccolo').stop().animate({
					 rotate:-((mousePos_2_piccolo-mousePos_1_piccolo)/6)+'deg'
					  
				 }, 200,'easeOutCubic');
				} else {
					$('.sole_piccolo').stop().animate({
						 rotate:((mousePos_1_piccolo-mousePos_2_piccolo)/6)+'deg'
						  
					 }, 200,'easeOutCubic');
					
				}
				$('.sole_piccolo').oneTime(201, function(){$('.sole_piccolo').stop().animate({
					 rotate:'0deg',
					  
				 }, 1800,'easeOutElastic');});
				
				
			},50);
		}
		}
	 }
	
}	
	$('body').bind('mousemove',controlla_hit_sole_piccolo);
	 $('#sun_2 .sole_piccolo').mouseleave(function(){
			stop1_piccolo = false
			stop2_piccolo = false; 
	 });	
	
	 $(window).resize(function (){
		 
		 give_position(); 	
		 $('#parallax').css('width',$(window).width()+'px');	
		 if($.browser.msie && jQuery.browser.version == "6.0" || $.browser.msie && jQuery.browser.version == "7.0" || $.browser.msie && jQuery.browser.version == "8.0"){
		 } else {
			$('body').css('background-position','50% '+$('#index #content').height()+'px');}
			$('#parallax').css('height',$('#index #content').css('height'));
			
			
			
	});
	
	
   
    
	


	
});
