// TODO : PNG fix pour IE 6,7,8... çà marche ???

/* IE PNG fix multiple filters */
(function ($) {
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "x.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
})(jQuery);

/**
 * Eléments du menu (li)
 */
var aMenus = new Array();

/**
 * Eléments de 'Développeur Web Freelance'
 */
var aDWFImages = new Array();

/**
 * vCard
 */
var vCardShow = false;
var vCardInterval;

$(document).ready( function() {
	if ($('input#premiere-visite').val() == '1')
	{
		// Première visite
		
		// Cache la page
		//$('div.ombre_page').hide();
		
		// Cache les éléments
		$('div#entete-logo').hide();
		$('img#logo-ryan-gilles').hide();
		$('div.menu ul li').hide();
		
		// Afichage de la page
		//$('div.ombre_page').fadeIn(500, function () {	
			// Affichage progressif du titre 'ryan gilles'
			$('div#entete-logo').fadeIn(1000, function() {
				// Affichage progressif du logo 'RG'
				$('img#logo-ryan-gilles').animate(
					{ 
						'opacity' : 'show',
						'width' : '74px',
						'height' : '78px'
					},
					2000,
					'easeOutBounce',
					function() { /* alert('ok'); */ }
				);
				
				var i = 0;
				$('div.menu ul li').each(function() {
					aMenus[i] = $(this);
					i++;
				});
				
				afficheElementMenu(0, true);
			});
			
			// Cache les éléments
			$('div.description-haut div.realisation-site-web-oise img').hide();
			
			// Animation 'Développeur Web Freelance'
			var i = 0;
			$('div.description-haut div.realisation-site-web-oise img').each(function() {
				aDWFImages[i] = $(this);
				i++;
			});
			
			for (i in aDWFImages)
			{
				if ((i % 2) == 0)
					aDWFImages[i].css('margin-left', '-200px');
				else
					aDWFImages[i].css('margin-left', '200px');
				
				aDWFImages[i].animate(
					{ 
						'opacity' : 'show',
						'marginLeft' : (i * 10) + 'px'
					},
					2000,
					'easeOutCirc',
					function() { /* alert('ok'); */ }
				);
			}
			
		//});
	}
	else
	{
		// Pas d'introduction
		
		$('div#entete-logo').fadeIn(1000, function() {
			// Affichage progressif du logo 'RG'
			$('img#logo-ryan-gilles').animate(
				{ 
					'opacity' : 'show',
					'width' : '74px',
					'height' : '78px'
				},
				2000,
				'easeOutBounce',
				function() { /* alert('ok'); */ }
			);
			
			var i = 0;
			$('div.menu ul li').each(function() {
				aMenus[i] = $(this);
				afficheElementMenu(i, false);
				i++;
			});
			
			// Mise en place 'Développeur Web Freelance'
			var i = 0;
			$('div.description-haut div.realisation-site-web-oise img').each(function() {
				aDWFImages[i] = $(this);
				i++;
			});
			
			for (i in aDWFImages)
			{
				aDWFImages[i].css('marginLeft', (i * 10) + 'px');
			}
		});
	}
	
	// vCard
	oVCard = $('<a id="vcard" href="ryan-gilles.vcf" target="_blank"><strong>Ryan Gilles, D&eacute;veloppeur PHP, CMSMS, jQuery, Auto-entrepreneur</strong></a>');
	
	if (!$.browser.msie) 	
		oVCard.fadeTo(0, 0.5);
	else
		oVCard.show();
		
	vCardInterval = setInterval(function() {
		
		if (vCardShow)
		{
			if (!$.browser.msie)
				$('a#vcard').fadeTo(900, 0.5);
			else
				$('a#vcard').hide();
		}
		else
		{
			if (!$.browser.msie)
				$('a#vcard').fadeTo(900, 1);
			else
				$('a#vcard').show();
		}
		
		vCardShow = !vCardShow;
		
	}, 1000);
	
	$('body').append(oVCard);
	
	setTimeout(function () {
		clearInterval(vCardInterval);
		if (!$.browser.msie)
			$('a#vcard').fadeTo(900, 0.5);
		else
			$('a#vcard').show();
	}, 5000);
	
	$('a#vcard').hover(
		function() {
			clearInterval(vCardInterval);
			$('a#vcard').css('backgroundPosition', '0px -189px');
			if (!$.browser.msie)
				$('a#vcard').fadeTo(0, 1);
			else
				$('a#vcard').hide
			$('a#vcard').animate(
				{ 
					'marginLeft' : '-30px',
					'marginTop' : '-130px'
				},
				300,
				'linear',
				function() { /* alert('ok'); */ }
			);
		},
		function() {
			$('a#vcard').css('backgroundPosition', '0px 0px');
			if (!$.browser.msie)
				$('a#vcard').fadeTo(0, 0.5);
			else
				$('a#vcard').show();
			$('a#vcard').animate(
				{ 
					'marginLeft' : '-85px',
					'marginTop' : '-70px'
				},
				300,
				'linear',
				function() { /* alert('ok'); */ }
			);
		}
	);
});

/**
 * Affiche l'élément du menu
 * @param idx
 */
function afficheElementMenu(idx, chargement)
{
	if (chargement)
	{
		aMenus[idx].animate(
			{ 
				'opacity' : 'show',
				'width' : '116px',
				'height' : '44px'
			},
			500,
			'easeOutExpo'
		);
		
		if (idx < (aMenus.length - 1))
			setTimeout(function() { afficheElementMenu(idx + 1, true); }, 100);
	}
	else
	{
		aMenus[idx].css('opacity', 'show');
		aMenus[idx].css('width', '116px');
		aMenus[idx].css('height', '44px');
	}
}
