﻿$(document).ready(function() {
       /* Cloud HTML */
		var astre ="<a id=\"astre\" class=\"astreSoleil\" href=\"#moon\"><img src=\"ressources/img/items/sunShine.png\" alt=\"Soleil\" width=\"225\" height=\"400\" /></a>";
		var Count=0;
		var timer="";
		var numberBalloon = 0;
		var cycle = $.cookie("cycle");		
		
		$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

       /* Retourne un nombre au hasard entre min et max */
       function rand(mini, maxi) {
               return Math.floor(Math.random() * (maxi - mini + 1)) + mini;
       };


		function seaLoop(){
			   $("footer .footer").animate(
					   {backgroundPosition:"50px 0px"},2500,function(){
							   $(this).animate({backgroundPosition:"0px 0px"},2500);
							   seaLoop();
							   }
			   )
		};

       $(function(){

				$("#pandora").css("display","block");
				$("#gototop").css("display","block");

				var ancre = window.location.hash;

				if(cycle=="jour"){
					$(".linkAction,").css("top","120px");
					$(".sun").css("top","-50px");
					$("#bth").attr("href","index.php#sun");
					var soleil = true;
				}

				if(cycle=="nuit"){
					$(".linkAction").css("top","120px");
					$(".sun img").attr("src","ressources/img/items/moon-b.png");
					$(".sun").css("top","-50px");
					$("#bth").attr("href","index.php#moon");
					var lune = true;
				}

				var scrHeight = $(window).height();
				var scrWidth = $(window).width();
				var nbr_nuage = 0;
				var nbrHoverBalloon = 0;
				var posY;
				var posX;

				$().dblclick(function(e){
					posY=e.pageY;
					posX=e.pageX;
					checkCount(posX,posY,scrWidth);
				});
				
				$().mousemove(function(e){
					   posY = e.pageY;
				});

				$(window).resize(function(e){
					   scrHeight = $(window).height();
					   scrWidth = $(window).width();
				});

				$(".linkAction").toggle(function(){
					$(".linkAction").animate({top:"120px"},1200);
					$(".sun").animate({top:"-50px"},1200);
					if(soleil==true){
						var date = new Date();
						date.setTime(date.getTime() + (60 * 60 * 1000));
						$.cookie("cycle","jour",{path:'/',expires: date});
						}
					else if(lune==true){
						var date = new Date();
						date.setTime(date.getTime() + (60 * 60 * 1000));
						$.cookie("cycle","nuit",{path:'/',expires: date});
						}
					else
						{
						var date = new Date();
						date.setTime(date.getTime() + (60 * 60 * 1000));
						$.cookie("cycle","jour",{path:'/',expires: date});
						}
				},function(){
					$(".linkAction").animate({top:"-180px"},1200);
					$(".sun").animate({top:"-350px"},1200);
					$("#bth").attr("href","index.php#pandora");
						var date = new Date();
						date.setTime(date.getTime() + (60 * 60 * 1000));
						$.cookie("cycle","none",{path:'/',expires: date});
				});

				// Init seaLoop
				if(!$.browser.msie6){
				   seaLoop();
				}
       });

});
