﻿$(document).ready(function() {
   /* Cloud HTML */
	var cloudHtml = "<div class=\"cloud\">\n<a href=\"\">\n<img src=\"ressources/css/img/items/cloud.png\" alt=\"Cloud\" height=\"84\" width=\"200\" />\n</a>\n</div>";
	var blackCloudHtml = "<div class=\"cloud\">\n<a href=\"#eclair\">\n<img src=\"ressources/css/img/items/black-cloud.png\" alt=\"Cloud\" height=\"84\" width=\"200\" />\n</a>\n<img class=\"licht\" src=\"ressources/css/img/items/blank.png\" alt=\"flash\" height=\"410\" width=\"141\"/>\n</div>";
	var flashLight = "ressources/css/img/items/light.gif";
	var playerDeezer ="<a class=\"close\" href=\"#close\"></a><div class=\"object\"><object width=\"180\" height=\"236\">\n <param name=\"movie\" value=\"http://www.deezer.com/embedded/widget.swf?path=14365200&lang=FR&colorBack=0xFFFFFF&colorVolume=0xFFFFFF&colorScrollbar=0xFFFFFF&colorText=0x000066&autoplay=1&autoShuffle=0&id=3523788\">\n </param>\n <embed src=\"http://www.deezer.com/embedded/widget.swf?path=14365200&lang=FR&colorBack=0xFFFFFF&colorVolume=0xFFFFFF&colorScrollbar=0xFFFFFF&colorText=0x000066&autoplay=1&autoShuffle=0&id=3523788\" type=\"application/x-shockwave-flash\" width=\"180\" height=\"236\">\n </embed>\n </object></div>";
	var playerjiwa="<object width=\"160\" height=\"245\" id=\"music-widget\">\n<param name=\"wmode\" value=\"transparent\" />\n<param name=\"type\" value=\"application/x-shockwave-flash\" />\n<param name=\"allowScriptAccess\" value=\"always\" />\n<param name=\"movie\" value=\"http://www.jiwa.fm/res/widget/compact.swf?playlistId=187627&skin=bright&arrows=FFFFFF&loadedBar=FFFFFF&volumePreview=666699&volume=333399&trackinfos=FFFFFF&tint=FCFDFF;0;0;0\" />\n<embed src=\"http://www.jiwa.fm/res/widget/compact.swf?playlistId=187627&skin=bright&arrows=FFFFFF&loadedBar=FFFFFF&volumePreview=666699&volume=333399&trackinfos=FFFFFF&tint=FCFDFF;0;0;0\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" name=\"music-widget\" width=\"160\" height=\"245\" allowScriptAccess=\"always\">\n</embed>\n</object>";
	var bird ="<div class=\"oiseau\"><a href=\"#musique\"><img src=\"ressources/css/img/items/piaf.gif\" width=\"40\" height=\"20\" alt=\"oiseau\" /></a></div>";
	var birdLinkLess ="<div class=\"oiseauMusicLess\"><img src=\"ressources/css/img/items/piaf.gif\" width=\"40\" height=\"20\" alt=\"oiseau\" /></div>";
	var birdLinkFull ="<div class=\"oiseau\"><a href=\"#musique\"><img src=\"ressources/css/img/items/piaf.gif\" width=\"40\" height=\"20\" alt=\"oiseau\" /></a></div>";
	var redBalloon ="<a href=\"#mRed\" rel=\"ressources/css/img/motifs/main-red.png\" class=\"balloon\"><img src=\"ressources/img/items/little-montgollfiere-red.png\" alt=\"montgolfiére\" height=\"63\" width=\"50\"/></a>";
	var purpleBalloon ="<a href=\"#mPurple\" rel=\"ressources/css/img/motifs/main.png\" class=\"balloon\"><img src=\"ressources/img/items/little-montgollfiere-purple.png\" alt=\"montgolfiére\" height=\"63\" width=\"50\"/></a>";
	var greenBalloon ="<a href=\"#mGreen\" rel=\"ressources/css/img/motifs/main-green.png\" class=\"balloon\"><img src=\"ressources/img/items/little-montgollfiere-green.png\" alt=\"montgolfiére\" height=\"63\" width=\"50\"/></a>";
	var brownBalloon ="<a href=\"#mBrown\" rel=\"ressources/css/img/motifs/main-brown.png\" class=\"balloon\"><img src=\"ressources/img/items/little-montgollfiere-brown.png\" alt=\"montgolfiére\" height=\"63\" width=\"50\"/></a>";
	var astre ="<a id=\"astre\" href=\"#moon\"><img src=\"ressources/img/items/sunShine.png\" alt=\"Soleil\" width=\"225\" height=\"400\" /></a>";
	var jeu ="<div id=\"popupInte\" class=\"popup\"><a href=\"#close\" class=\"popupClose\" id=\"closeInter\"><img src=\"ressources/img/bt/closed.png\" alt=\"fermer la popup\" height=\"25\" width=\"25\" /></a><p>Bienvenue cher internaute! Ce site s'adresse à mes <em>interlocuteurs professionnels</em>, qu'ils soient employeurs ou clients.<br />Vous trouverez donc ici des informations concernant mon parcours professionnel, des exemples de réalisations, mon CV et les ressources que j'utilise dans ma vie professionelle.<br /><strong>Peut-être</strong> voudriez-vous en connaitre davantage sur ma personnalité, <strong>en dehors du cadre strictement professionel, afin de mieux me cerner ?</strong><br />Ou, plus simplement, vous souhaiteriez un peu d'animations ?<br /><em>Et bien tout cela est possible !</em><br />Ce site cache de nombreuses surprises pour aller au delà des apparences... mais c'est à vous de les découvrir ! Soyez curieux, cliquez deci delà et de petits trésors s'offriront à vous !<br /><br />Bonne navigation !</p><strong>Le webmestre - Simon ERTEL</strong></div>";
	var voeux ="<div id=\"popupVoeux\" class=\"popup\"><a href=\"#close\" id=\"closeVoeux\" class=\"popupClose\" id=\"closeInter\"><img src=\"ressources/img/bt/closed.png\" alt=\"fermer la popup\" height=\"25\" width=\"25\" /></a>"+
				'<p>Faites un voeux !</p><form target="_blank" id="cse-search-box" action="http://www.google.fr/cse"><div><input type="hidden" value="partner-pub-8560042762072888:265g6abeazf" name="cx"/><input type="hidden" value="UTF-8" name="ie"/><input type="text" size="31" name="q" style="border: 1px solid rgb(126, 157, 185); padding: 2px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"/><input type="submit" value="Rechercher" name="sa"/></div></form></div>';
	var Count=0;
	var timer="";
	var numberBalloon = 0;
	var nbrPopup = 0;
	var nbrPopup2 = 0;
	
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

	function birdMvmt(speedBird){
		$("#clouds .oiseauMusicLess").each(
			function Mvmt(e){
				var topBird=parseFloat($(this).css("top"))-rand(-200, 200);
				$(this).animate({right:0,top:topBird}, speedBird,"linear",function(){$(this).remove();})
			}
		)
		$("#clouds .oiseau").each(
			function(){
				var topBird=parseFloat($(this).css("top"))-rand(-200, 200);
				$(this).animate({right:0,top:topBird}, speedBird,"linear",function(){$(this).remove();})
				.one("click",function(e){ e.preventDefault();
									bird=birdLinkLess;
									$(this).attr("class","oiseauMusicLess");
									$(playerDeezer).appendTo("#radio");
									$("#radio").css("display","block")
											   .children('.close').click(function(e){
														  $(this).parents("#radio").css("display","none").children().remove();
														   bird=birdLinkFull;
												});
								  })
			}
		)
	};

	function dayToNight(){
		$("body").css("backgroundImage","url('ressources/css/img/motifs/main-night.png')");
		$("body").removeClass("day").addClass("night");
		$("#header .header .contact img").attr("src","ressources/img/bt/contact-night.png");
		$(".footer .smooth img").attr("src","ressources/img/arrows/totop-night.png");
		$(".ef").bind("mousemove",starFalling);
			var date = new Date();
			date.setTime(date.getTime() + (60 * 60 * 1000));
			$.cookie("cycle","nuit",{path:'/',expires: date});
	}

	function nightToDay(){
		$("body").css("backgroundImage","url('http://simonertel.net/ressources/css/img/motifs/main.png')");
		$("body").removeClass("night").addClass("day");
		$("#header .header .contact img").attr("src","http://simonertel.net/ressources/img/bt/contact-off.png");
		$(".footer .smooth img").attr("src","ressources/img/arrows/totop.png");
		$(".ef").unbind("mousemove",starFalling);
			var date = new Date();
			date.setTime(date.getTime() + (60 * 60 * 1000));
			$.cookie("cycle","jour",{path:'/',expires: date});
	}

	function checkCount(posX,posY,scrWidth){
	//	if(Count==3){
			posX=scrWidth-posX;
			speedBird=posX*15;
			$(bird)
			.appendTo("#clouds")
			.css({top:posY+"px",right:posX+"px"})
			.show();
			birdMvmt(speedBird);
	//	}
		Count=0;
	}

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

       function initNuageAnim(nbr, posY, scrHeight) {
			   forty=nbr%10;
               var hauteur = rand(posY-500, posY+(scrHeight));
	   
			if(forty==9){
				   $(blackCloudHtml)
				   .appendTo("#clouds")
				   .css("top", hauteur+"px")
				   .show()
				   .animate({right:"0%"}, 30000, "linear", function() {
						   $(this).remove();
				   })
				   .children("a").click(function(e){
												 e.preventDefault();
												 $(this).next("img.licht")
												 		.css("display","block")
														.attr("height","410")
														.attr("src",flashLight);
												 $("#rainbow").show()
																.animate({opacity:"0.5"},3000);
												                var date = new Date();
																date.setTime(date.getTime() + (60 * 60 * 1000));
																$.cookie("state","arcEnCiel",{path:'/',expires: date});
												setTimeout('$(".licht").attr("height",1);',500);
										});
			}else{
				$(cloudHtml)
               .appendTo("#clouds")
               .css("top", hauteur+"px")
               .show()
			   .click(function(e){e.preventDefault();$(this).remove();})
               .animate({right:"0%"}, 30000, "linear", function() {
                       $(this).remove();
               });
			}
		};

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

		function initGame(){
			$("#pandora").hide();
			$("#alterworld img").show();
			$("#gototop").fadeOut("slow");
			$("#footer").fadeIn("slow");
			$("#footer").css({bottom:"0px"});
		}
		
		function makeBalloon(number){
		var Balloon;
		if(number==0){Balloon=redBalloon;}
		if(number==1){Balloon=purpleBalloon;}
		if(number==2){Balloon=greenBalloon;}
		if(number==3){Balloon=brownBalloon;}
		if(number==4){Balloon=redBalloon;numberBalloon=0;}
			$(Balloon)
			.appendTo("#footer")
			.css("left",rand(0,100)+"%")
			.animate({bottom:"1000px"},50000, "linear", function(e){
					$(this).remove();
			})
			.click(function(e){
				e.preventDefault();
				$("body.hresume").css("backgroundImage","url("+$(this).attr("rel")+")");
			})
		};

		function popup(){
			if(nbrPopup==0){
				$("#header .header").after(jeu);
				nbrPopup++;
					$("#closeInter").click(function(e){
						e.preventDefault();
						nbrPopup = 0;
						$("#popupInte").remove();
					});
			}
		}
		
		function popup2(){
			if(nbrPopup2==0){
				$("#header .header").after(voeux);
				nbrPopup2++;
					$("#closeVoeux").click(function(e){
						e.preventDefault();
						nbrPopup2 = 0;
						$("#popupVoeux").remove();
					});
			}
		}

		function starFalling(){
		$("#shootingStar").css({display:"block",opacity:"0"});
		$(".ef").unbind("mousemove");
		$("#shootingStar").show().animate({left:"600px",opacity:"0.8"},
								  800,
								  "linear",
								  function(){
											$(this).animate({opacity:"0",left:"1000px"},
															 800,
															 "linear",
															 function(){
																		$(this).css({left:'200px',display:'none'});
																		$(".ef").bind("mousemove",starFalling);
																		});
											});
		}
		
/*       $(function(){ */
				
				$("#pandora").css("display","block");
				$("#gototop").css("display","block");
				
				if(window.location.hash=="#pandora"){
					initGame();
				}

				var biscuit = $.cookie("state");
				var cycle = $.cookie("cycle");
				var ancre = window.location.hash;
				var scrHeight = $(window).height();
				var scrWidth = $(window).width();
				var nbr_nuage = 0;
				var nbrHoverBalloon = 0;
				var posY;
				var posX;
				
				$(".ef").click(function(e){e.preventDefault();})
				$(".ef").unbind("mousemove",starFalling);

				if(cycle=="jour"){
					initGame();
					$(astre).appendTo("#header");
					$("#astre").addClass("astreSoleil");
					nightToDay();
				}
				
				if(cycle=="nuit"){
					initGame();
					$(astre).appendTo("#header");
					dayToNight();
					$("#astre").addClass("astreLune");
					$("#astre img").attr("src","http://simonertel.net/ressources/img/items/moon.png");
				}

				if(biscuit=="arcEnCiel"){
					initGame();
					$("#rainbow").show().animate({opacity:"0.5"},3000);
				}
				
				$(".montgolfieres").mouseover(function(e){
					frenquency=nbrHoverBalloon%2;
						if(!frenquency){
						makeBalloon(numberBalloon);
						numberBalloon++;
						}
					nbrHoverBalloon++;
				})

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

				$(".close").click(function(e){
					e.preventDefault();
					$("#avertissements").remove();
				});
		
				$().mousemove(function(e){
					   posY = e.pageY;
				});

				$("#pandora").click(function(e){
					$(this).fadeOut("slow",function(){
						 $("#footer").show().animate({bottom:"0px"},1200);
						 $("#alterworld img").show();
						 $("#gototop").fadeOut("slow");
					});
				})

				$("#avertissements").hide();
				$("#ie6 #avertissements").css("display","block").children("#javascript").css("display","none");
				$("#ie6 #avertissements #javascript").css("display","none");

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

				$(".nuages").mouseover(function(){
					   initNuageAnim(nbr_nuage, posY, scrHeight);
					   nbr_nuage++;
				});

				$(".astreSoleil").toggle(function(){
					$("#astre img").animate({width:"5px",paddingLeft:"50%"},500,function(){
						$(this).attr("src","http://simonertel.net/ressources/img/items/moon.png");
						dayToNight();
						$(this).animate({width:"225px",paddingLeft:"0px"},500);
						$("#astre").removeClass("astreSoleil").addClass("astreLunaire");
					});
				},function(){
					$("#astre img").animate({width:"5px",paddingLeft:"50%"},500,function(){
						$(this).attr("src","http://simonertel.net/ressources/img/items/sunShine.png");
						nightToDay();
						$(this).animate({width:"225px",paddingLeft:"0px"},500);
						$("#astre").removeClass("astreLunaire").addClass("astreSoleil");
					});
				});

				$(".astreLune").toggle(function(){
					$("#astre img").animate({width:"5px",paddingLeft:"50%"},500,function(){
						$(this).attr("src","http://simonertel.net/ressources/img/items/sunShine.png");
						nightToDay();
						$(this).animate({width:"225px",paddingLeft:"0px"},500);
						$("#astre").removeClass("astreLunaire").addClass("astreSoleil");
					});
				},function(){
					$("#astre img").animate({width:"5px",paddingLeft:"50%"},500,function(){
						$(this).attr("src","http://simonertel.net/ressources/img/items/moon.png");
						dayToNight();
						$(this).animate({width:"225px",paddingLeft:"0px"},500);
						$("#astre").removeClass("astreSoleil").addClass("astreLunaire");
					});

				});

				$(".linkAction").toggle(function(){
					$(".linkAction").animate({top:"120px"},1200);
					$(".sun").animate({top:"-50px"},1200);
					$("#bth").attr("href","index.php#sun");
				},function(){
					$(".linkAction").animate({top:"-180px"},1200);
					$(".sun").animate({top:"-350px"},1200);
					$("#bth").attr("href","index.php#pandora");
				});

				$("#rainbow").toggle(function(){
						$("#interogations img").attr("src","ressources/img/items/rss.png");
						$("#interogations img").attr("title","Allez sur la page de mon flux rss google").attr("alt","Allez sur la page de mon flux rss google");
						$("#interogations").unbind('click');
						$("#interogations").attr("id","fluxrss").attr("href","flux.php");
				},function(){
						$("#fluxrss img").attr("src","ressources/img/items/inte.png");
						$("#fluxrss img").attr("title","?").attr("alt","?");
						$("#interogations").unbind('click');
						$("#fluxrss").attr("id","interogations").attr("href","#Quete").click(function(){popup();});
				});

				$("#interogations").bind('click',function(e){
					e.preventDefault();
					popup();
				});
				
				$("#shootingStar").bind('click',function(e){
					e.preventDefault();
					popup2();
				});
				
				$('a.smooth[href*=#]').click(function(e){
					e.preventDefault();
					if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
					&& location.hostname == this.hostname) {
						var $target = $(this.hash);
						$target = $target.length && $target
						|| $('[name=' + this.hash.slice(1) +']');
						if ($target.length) {
							var targetOffset = $target.offset().top;
							$('html,body')
							.animate({scrollTop: targetOffset}, 1000);
							  if($.browser.msie6){
								return true;
							  }else{
								 return false;
							  }
						}
					}
				});

				$("#mail").submit(function(e){
					   e.preventDefault();
					   $(this).fadeTo("slow", 0.33);
					   var reg = /^[a-z0-9._-]+@[a-z0-9\.-]{2,}\.[a-z]{2,}$/;
					   var mail = $("#mail #email").val();
					   var nom = $("#mail #nom").val();
					   var texte = $("#mail textarea").val();
				
					   if(reg.exec(mail) != null) {
							   $.post("check.php", {contenu:texte,mail:mail,name:nom},
									   function(retour) {
											   if (retour == "ok") {
													   $("#mail").hide();
													   $("div.mssg")
															   .text("Votre message a bien été envoyé. Merci.")
															   .slideDown("slow");
											   }
											   else {
													   alert("Désolé, nous avons rencontré un problème d'envoi des données :s");
													   $(this).fadeTo("slow", 100);
											   }
									   });
					   }
					   else {
							   alert("Désolé, votre adresse email est incorrecte.");
							   $(this).fadeTo("slow", 100);
					   }
				
				});

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

});