//------------------------------------------
// Fonctions génériques
//------------------------------------------
var jz = {
		
	extend : function (target, ob)
	{
		for(var el in ob) {target[el] = ob[el];}
	},
	
	ev_target : function (ev) {return ev.target || ev.srcElement;},
	
	rollver : function (ev) //qqchose1.abc devient qqchose2.abc et vice-versa
	{
		var elsrc = jz.ev_target(ev);
		var sext = elsrc.src.substring((elsrc.src.length-4), (elsrc.src.length)).toString();
		var xnum = (elsrc.src.substring((elsrc.src.length-5), (elsrc.src.length-4)).toString() == "1") ? 2 : 1;
		elsrc.src = elsrc.src.substring(0, (elsrc.src.length-5)) + xnum + sext;
	},
	
	precharg : function (imgsource) //jz.precharg(["img/edit2.gif", "img/supp2.gif"]);
	{
		var imgprecharge = new Array();
		
		for(var i = 0; i< imgsource.length; i++)
		{
			imgprecharge[i] = new Image();
			imgprecharge[i].src = imgsource[i];
		}
	},
	
	include : function(file)
	{
		if(typeof file == "undefined") return false;
		var ext = file.substring(file.length - 3, file.length);
		
		if(ext == "css")
		{
			var ncss = document.createElement('link');
			ncss.setAttribute("rel", "stylesheet");
			ncss.setAttribute("type", "text/css");
			ncss.setAttribute("media", "screen");
			ncss.setAttribute("href", file);
			document.getElementsByTagName("head")[0].appendChild(ncss);
			return ncss;
		}
		else if(ext == ".js")
		{
			var njs = document.createElement('script');
			njs.setAttribute("type", "text/javascript");
			njs.setAttribute("src", file);
			document.getElementsByTagName("body")[0].appendChild(njs);
			return njs;
		}
		return false;
	},
	
	soum : function () {document.forms[0].submit();},
	
	soumkey : function (ev)
	{
		ev = (ev) ? ev : window.event; 
		ev = (ev.keyCode) ? ev.keyCode : ev.charCode;
		if(ev == 13){soum();}
	}
};

//------------------------------------------
// DOM chargé
//------------------------------------------
$(document).ready(function()
{
	//------------------------------------------
	//Page complètement chargée
	//------------------------------------------
	$(window).bind("load", function()
	{
		//------------------------------------------
		//CV - animation du texte des pièces de puzzle
		//------------------------------------------	
		for(var cp1 = 1, attente = -299, duree = 1300; cp1 < 7; cp1++)
		{
			setTimeout(
				"$('.eye_candy_cv .cv" + (7- cp1) + "')" + 
					".css({'opacity' : '0', 'visibility' : 'visible'})" +
					".animate({'opacity' : '1'}, " + (duree += 40) + ", 'easeInExpo')"
			, attente += 300);
		}
	});

	//------------------------------------------
	//le browser n'est pas IE6
	//------------------------------------------
	if(/MSIE ([0-9]{1,})/.exec(navigator.userAgent) == null || RegExp.$1 != "6")
	{
		//------------------------------------------
		//Ajuste le logo
		//------------------------------------------
		if(RegExp.$1 == "7") //IE7
		{
			$('.logo span').css({'marginLeft' : '-3px'});
		}
		
		//------------------------------------------
		//Page complètement chargée
		//------------------------------------------
		$(window).bind("load", function()
		{
			//------------------------------------------
			//Accueil - animation eye candy (avion)
			//------------------------------------------
			setTimeout(function() {
			
				$('.eye_candy_avion').append('<div></div>');
				$('.eye_candy_avion div')
					.css({
						'position' : 'relative',
						'visibility' : 'visible',
						'top' : '-275px',
						'left' : '-600px'
						
					})
					.animate({
						'top' : '0px',
						'left' : '0px'
					}, 2500, 'easeInOutExpo');
			}, 500);
			
			//------------------------------------------
			//A propos - animation eye candy (texte binaire)
			//------------------------------------------
			$.fn.typewriter = function(opt, callback)
			{
				var typeone = function(self, text, content)
				{
					if(text.length > 0)
					{
						var next = text.match(/(\s*(<[^>]*>)?)*(&.*?;|.?)/)[0];
						
						text = text.substr(next.length);
						$(self).html(content+next);
						
						setTimeout(function()
						{
							typeone(self, text, content+next);
						}, opt['delay']);
					}
					else if(callback != null) callback();
				}
				this.each(function()
				{
					opt = opt || { 'delay': 100 };
					
					$(this).height($(this).height());
					$(this).width($(this).width());
					$(this).css({'visibility' : 'visible'});
					typeone(this, $(this).html(), '');
				});
			}
							
			$(".bin3 span").typewriter({'delay': 80}, function()
			{
				setTimeout(function()
				{
					$(".bin4 span").typewriter({'delay': 100});
				}, 100);
			});
			
			//------------------------------------------
			//Article - eye candy (flèche)
			//------------------------------------------
			$('.article_fh')
				.css({
					'height' : '142px',
					'top' : '37px',
					'width' : '381px',
					'visibility' : 'visible'
				})
				.animate({
					'height' : '20px',
					'top' : '156px'
				}, 1300, 'easeInCubic', function()
				{
					$('.article_fo')
						.css({
							'opacity' : '0',
							'visibility' : 'visible'
						})
						.animate({
							'opacity' : '1'
						}, 1000, 'linear');
						
					$('.article_fb')
						.css({
							'height' : '30px',
							'width' : '380px',
							'top' : '156px',
							'visibility' : 'visible'
						})
						.animate({
							'height' : '205px',
							'top' : '45px'
							
						}, 1000, 'easeOutCubic');
						
					$('.article_fh')
						.animate({
							'height' : '142px',
							'top' : '37px'
						}, 1000, 'easeOutCubic');
				});		
			
			//------------------------------------------
			//Création - animation eye candy (bande)
			//------------------------------------------
			$('.eye_candy_creation div').each(function(i)
			{
				var el_cr = $(this);
				el_cr.css("opacity", "0");
				
				setTimeout(function()
				{
					el_cr.animate({
						'height' : '249px',
						'opacity' : '1'
					}, 2000, 'easeInOutCubic');
					
				}, 100 * i);
			});
			
			//------------------------------------------
			//Contact - animation eye candy
			//------------------------------------------
			$('.eye_candy_contact')
				.css({
					'backgroundPosition' : '0px -800px',
					'position' : 'relative'
				})
				.animate({
				
					path : new $.path.bezier({
						start:
						{
						  x: -800,
						  y: 0,
						  angle: -40,
						  length:0.8
						},
						end:
						{
						  x:-70,
						  y:0,
						  angle: 40,
						  length:0.5
						}
					})
				}, 6000, 'easeInOutCubic');
				
			//------------------------------------------
			// Animation du menu
			//------------------------------------------	
			$('.menu li').hover(
			
				function ()
				{
					$(this).addClass('menu_li_hover');
					$('div',$(this))
						.stop()
						.css({
							'zIndex' : '10',
							'height' : '52px'
						})
						.animate({
							'top' : '30px'
						}, 400, 'easeOutCubic'); //}, 1300, 'easeOutElastic');
				},
				function ()
				{
					$(this).removeClass('menu_li_hover');
					$('div',$(this))
						.stop()
						.css({
							'zIndex' : '-1'
						})
						.animate({
							'height' : '40px',
							'top' : '0px'
						},1000, 'easeInCubic');
				}
			);
		});
	}
	//------------------------------------------
	//le browser est IE6
	//------------------------------------------
	else
	{	//------------------------------------------
		//Accueil - animation de l'avion
		//------------------------------------------
		$('.eye_candy_avion').append('<div></div>');
		$('.eye_candy_avion div').css({'visibility' : 'visible'});
		
		//------------------------------------------
		//A propos - animation du texte binaire
		//------------------------------------------
		$(".eye_candy_binaire span").css({'visibility' : 'visible'});
	}
		
	//------------------------------------------
	//Page complètement chargée
	//------------------------------------------
	$(window).bind("load", function()
	{
		if($(".gimg_eff").get()[0]) //élément trouvé
		{
			//------------------------------------------
			//affichage de l'image en grand
			//------------------------------------------
			jz.include("css/fancybox.css");
			
			$(".gimg_eff").fancybox({
				'titleShow'		: true,
				'titlePosition'	: 'outside',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'easingIn'		: 'easeInExpo',
				'easingOut'		: 'easeInBack',
				'speedIn'		: 400,
				'speedOut'		: 450
			})
			
			//------------------------------------------
			//bouton de naviguation des images miniatures
			//------------------------------------------
			$(".gflecheg").each(function(i) {
				
				$(this).bind("click", function()
				{
					var el_before = $(this).closest(".gbloc_img").find("a:not(.gimg_invisible)");
					var el_after = el_before.prev(".gimg_invisible");
					
					//affiche la bonne image
					el_before.addClass("gimg_invisible");
					el_after.removeClass("gimg_invisible");
					
					//affiche ou non le bouton de naviguation droit
					(el_after.prev(".gimg_invisible").get()[0]) ?
						$(this).removeClass("invisible") :
						$(this).addClass("invisible");
					
					//affiche le bouton de naviguation gauche
					$(this).closest(".gbloc_img").find(".gfleched")
						.removeClass("invisible");
				});
			}) 
			
			$(".gfleched").each(function(i) {
				
				$(this).bind("click", function()
				{
					var el_before = $(this).closest(".gbloc_img").find("a:not(.gimg_invisible)");
					var el_after = el_before.next(".gimg_invisible");
					
					//affiche la bonne image
					el_before.addClass("gimg_invisible");
					el_after.removeClass("gimg_invisible");
					
					//affiche ou non le bouton de naviguation droit
					(el_after.next(".gimg_invisible").get()[0]) ?
						$(this).removeClass("invisible") :
						$(this).addClass("invisible");
					
					//affiche le bouton de naviguation gauche
					$(this).closest(".gbloc_img").find(".gflecheg")
						.removeClass("invisible");
				});
			}) 
		}
	});
});

//------------------------------------------
// Google Analytics
//------------------------------------------
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17147436-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

