// pour ajouter un évènement au onload !
function addEvent(obj, event, fct) {
	if (obj.attachEvent){
		obj.attachEvent("on" + event, fct); 
	}	
	else{
		obj.addEventListener(event, fct, true);
	}
}

$(function() {
	// fonction preload
	var cache = [];
	$.preLoadImages = function() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
	}


	$('#background-wrap img').css('opacity',0);
	$('#background-wrap img').delay(300).animate({ opacity: 1}, 3000);

	
	/* Menu ! */
	var $el, leftPos, newWidth;
	$mainNav2 = $("#menu_principal");
	$mainNav2.append("<li id='magic-line-two'></li>");

	var $magicLineTwo = $("#magic-line-two");

	$magicLineTwo
		.width($(".menu_principal_selected").width())
		.height($mainNav2.height())
		.css("left", $(".menu_principal_selected a").position().left)
		.data("origLeft", $(".menu_principal_selected a").position().left)
		.data("origWidth", $magicLineTwo.width())
		.data("origColor", $(".menu_principal_selected a").attr("rel"));
			
	$("#menu_principal a").hover(function() {
		$el = $(this);
		leftPos = $el.position().left;
		newWidth = $el.parent().width();
		$magicLineTwo.stop().animate({
			left: leftPos,
			width: newWidth,
			backgroundColor: $el.attr("rel")
		})
	}, function() {
		$magicLineTwo.stop().animate({
			left: $magicLineTwo.data("origLeft"),
			width: $magicLineTwo.data("origWidth"),
			backgroundColor: $magicLineTwo.data("origColor")
		});    
	});

	/* Kick IE into gear */
	$(".menu_principal_selected a").mouseenter();
	

});
