ypSlideOutMenu.writeCSS();

/**
 *
 * @access public
 * @return void
 **/
function buildSubNavigation(){

	var iB = $$("body")[0].getWidth();
	var iM = $("main").getWidth();
	var iMarge = (iB-iM)/2;
	iMarge = (iMarge >= 0 ? iMarge : 0);
	var sD = "";
	var iLeft = 0;
	var sWidth = "";

	var aList = new Array();
	aList.push(0);
	$$("li[rel='navItem']").each(function(oItem){
		aList.push(aList[aList.length - 1] + oItem.getWidth() + 6);
		iLeft	 = iMarge + aList[aList.length - 2] + 136 + 136 + 3;
		oId		 = "menu" + (parseInt(oItem.down("a").id.substr(3))+1) +"Container";
		if($(oId)) $(oId).writeAttribute("style","left:"+iLeft+"px;");
		sD += " - " + iLeft + "\n";
	});

	$("zone_langue").writeAttribute("style","left:"+ (iMarge-32-2) +"px;");

}

//////////////////////////////////////////////////////////////////////////////
// PROTOTYPE
//////////////////////////////////////////////////////////////////////////////

// Fire when the dom is loaded : before images
document.observe("dom:loaded", function() {

	buildSubNavigation();

	// Coloration au survol des lignes du tableau 'Fiche' pour chaque champ de formulaire actif
	//var aField = $$("form#formContactVendeur input","form#formContactVendeur select","form#formContactVendeur textarea");
	var aField = $$("form[rel='autocheck'] input","form[rel='autocheck'] select","form[rel='autocheck'] textarea");
	var i = 0;
	aField.each(function(oItem) {
		var tmpOnBlur = oItem.onblur;
		// Suppression du style 'survol' quand on quitte l'élément
		oItem.onblur		 = function(){
			checkField(this);
			if(tmpOnBlur) tmpOnBlur();
			this.up("div").removeClassName("fieldFocused");
			//this.removeClassName("fieldFocused");
		};
		var tmpOnFocus = oItem.onfocus;
		// Suppression du style 'survol' quand on quitte l'élément
		oItem.onfocus		 = function(){
			if(this.getAttribute("type") != "submit") this.up("div").addClassName("fieldFocused");
			//this.addClassName("fieldFocused");
			if(tmpOnFocus) tmpOnFocus();
		};
		i++;
	});

	aField = $$("div#menubar h3");
	var i = 0;
	aField.each(function(oItem) {
		var tmpOnMouseOver = oItem.onmouseover;
		// Au 'survol' du titre afficher la description
		oItem.tmpI = i;
		oItem.onmouseover = function(){
			if(tmpOnMouseOver) tmpOnMouseOver();
			$("eli_description").update(_G_MENU_DESCRIPTION[this.tmpI]).show();
		};
		var tmpOnMouseOut = oItem.onmouseout;
		// Quand on quitte le 'survol' on vide la zone
		oItem.onmouseout = function(){
			$("eli_description").update("").hide();
			if(tmpOnMouseOut) tmpOnMouseOut();
		};
		i++;
	});

	// Masquer toutes les aides de formulaire
	$$("span.help").invoke("hide");

	// Masquer les blocks d'informations
	if($('block_2')) $('block_2').hide().removeClassName("hidden");
	if($('block_3')) $('block_3').hide().removeClassName("hidden");

	// Init the lightbox effects
	new Lightbox();

});


Event.observe(document.onresize ? document : window, "resize", function() { buildSubNavigation(); });

window.onload = function(){

	if($("diaporama_automatique")){
		new PeriodicalExecuter(function(pe) {
			var iItem = Math.floor(Math.random()*aDiaporama.length);
			$("diaporama_automatique").writeAttribute("style","background:url("+ aDiaporama[iItem] +") no-repeat 50% 50%;");
		}, 5);
	}

};
