//////////////////////////////////////////////////////////////////////////////
// PROTOTYPE
//////////////////////////////////////////////////////////////////////////////

// Fire when the dom is loaded : before images
document.observe("dom:loaded", function() {

	// 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");

	// Init the lightbox effects
	new Lightbox();

	resizeWebsite();

});

Event.observe(document.onresize ? document : window, "resize", function() { resizeWebsite(); });


/**
 *
 * @access public
 * @return void
 **/
function resizeWebsite(){

	$("site_content").setStyle({
		width: ($("main").getWidth() - 270) + "px"
	});

	$("nav_top").setStyle({
		marginLeft: ($("main").getWidth() - 112) + "px"
	});

	$("block_2").setStyle({
		marginLeft: ($("main").getWidth() - 230) + "px"
	});

	var aLiBottom	 = $$("ul#nav_bottom li");
	var iLiBottom	 = aLiBottom.length;
	var iBottomWidth = $("bottom").getWidth() - 4 - 2 - (iLiBottom * 4);
	var i = 0;
	aLiBottom.each(function(oItem) {
		//oItem.setAttribute("style","width:" + Math.floor(iBottomWidth/iLiBottom) + "px");
		oItem.setStyle({
			width: Math.floor(iBottomWidth/iLiBottom) + "px"
		});
	});

}


ddaccordion.init({ //top level headers initialization
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

ddaccordion.init({ //2nd level headers initialization
	headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
	contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})