
(function() {
	var path = '/js/';
	var ts = (new Date()).getTime();
	var scripts = [
		'FW.core.js',
		'FW.decorations.js',
		'objects.js',
		'FW.modules.js',
		'FW.main.js',
		'swfobject.js'
		];
	
	for (var i=0; i<scripts.length; i++) {
		document.write('<script type="text/javascript" charset="utf-8" src="' + path + scripts[i] + '" ></script>');
	}
	
})();

/**
**
**/


function pngFix(elm, noOverflow) {
	elm.style.filter = ' ';
	if (!(document.all && window.print && /MSIE [56]/.test(navigator.userAgent))) return;
	var exec = (function(elm, noOverflow, scale) {
		return function() {
			
		
			var options = { noOverflow:noOverflow};
			var repeat = elm.currentStyle.backgroundRepeat.toLowerCase()=='repeat';
			elm.style.filter = ' ';
				// si l'ÃƒÂ©lÃƒÂ©ment est un tag img, on va en faire creer une balise qui encadrera cette image et ensuite traiter la balise comme si c'etait un ÃƒÂ©lÃƒÂ©ment qui avait une image de fond
				if (elm.nodeName.match(/^(IMG|INPUT)$/)) {
					if (!elm.src.match(/.*\.png$/)) return;
					
					elm.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='image', src='"+ elm.src + "')";
					
					elm.width = elm.offsetWidth;
					elm.height = elm.offsetHeight;
					
					/* recuperation de l'url du pixel transparent */
					var url = elm.currentStyle.backgroundImage.match(/^url\(["'](.*\.gif)["']\)$/); //seulement les .png
					elm.src = url[1];
					elm.className = elm.className.replace(/pngFix/g,'');
					
				}
				else {
					if (elm.currentStyle.backgroundImage == "" || elm.currentStyle.backgroundImage == "url()") return;
					var url = elm.currentStyle.backgroundImage.match(/^url\(["'](.*\.png)["']\)$/); //seulement les .png
					if (!url || url.length<2) return;
					var pngLayer = document.createElement('i'); // on genere un <i> en position:absolute (layer), qui viendra se placer sous le contenu du div  qui avait besoin du style.
					with(pngLayer.style) {
						if (options.noOverflow) {
							width = elm.offsetWidth + 'px';
							height = elm.offsetHeight + 'px';
						} else {
						 	width = '32000px';
							height = '32000px'; 
						}
						position = 'absolute';
						zIndex = -1;
						fontSize = '1%';
						filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='" + (options.noOverflow ? 'crop' : 'image') + "', src='"+url[1]+"')";
						background = 'none'; //forcing car parfois il peut arriver qu'on ai une CSS qui vienne rajouter des images / couleurs de fond
						/* positionnement de l'image en fonction du background-position sur l'element */
						if (!repeat) {
							switch((elm.currentStyle.backgroundPositionX+'').toLowerCase()) {
								case 'left' : left=0; break; 
								case 'right' : right = 0; break;
								case 'center' : 
									left='50%'; 
									setTimeout(function(pngLayer) {
										return function() {
											pngLayer.style.marginLeft = -(pngLayer.offsetWidth/2)+'px'; 
										}
									}(pngLayer), 50);
									break;
								default : 
									left = elm.currentStyle.backgroundPositionX; 
							}

							switch((elm.currentStyle.backgroundPositionY+'').toLowerCase()) {
								case 'top' : top = 0; break;
								case 'bottom' : bottom = 0; break;
								case 'center' : 
									top='50%'; 
									setTimeout(function(pngLayer) {
										return function() {
											pngLayer.style.marginTop=-(pngLayer.offsetHeight/2)+'px'; 
										}
									}(pngLayer), 100);
									break;
								default : 
									top = elm.currentStyle.backgroundPositionY || 0; 
							}
						} else {
							left = 0; //elm.currentStyle.backgroundPositionX +'';
							top = 0; //elm.currentStyle.backgroundPositionY +'';
						}
					} 
					
						/* gestion automatique du sizingMethod='scale' ou sizingMethod='image', ne pouvant pas tester le backgroundRepeat correctement, on passe par une methode un peu plus tricky */
						setTimeout(function(elmN, pngLayerN, repeatN) {
							return function() {
								if (!elmN || elmN.parentNode || !pngLayerN || !pngLayerN.parentNode) return;
								if (pngLayerN.filters['DXImageTransform.Microsoft.AlphaImageLoader'].sizingMethod=='image') {
									if (pngLayerN.offsetWidth<elmN.offsetWidth && repeatN) {
										pngLayerN.filters['DXImageTransform.Microsoft.AlphaImageLoader'].sizingMethod='scale';
									} else if (pngLayerN.offsetWidth>elmN.offsetWidth && elm.currentStyle.backgroundPositionX.match(/^(left|0%|0px|0)$/) || elm.currentStyle.backgroundPositionY.match(/^(top|0%|0px|0)$/)){
										pngLayerN.filters['DXImageTransform.Microsoft.AlphaImageLoader'].sizingMethod='crop';
									}
								} else {
									pngLayerN.sizingMethod = 'image';
								}
								if (elm.currentStyle.width.match(/^(0|[12](%|px)?)$/)) {
									pngLayerN.filters['DXImageTransform.Microsoft.AlphaImageLoader'].sizingMethod='image';
								}
								if (pngLayerN.style.right != 'auto' && pngLayerN.style.right !='')
									setTimeout(function() {
										pngLayerN.style.right = parseInt(pngLayerN.style.right) - (elm.offsetWidth%2 ? 1 : 0) + 'px';
									}, 50)
							}
						}(elm, pngLayer, repeat), 200);
					
					with (elm.style) {
						position = elm.currentStyle.position=="static" || elm.currentStyle.position=="" ? 'relative' : position;
						if (elm.currentStyle.overflow!='auto' && elm.currentStyle.overflow!='hidden') overflow = options.noOverflow ? 'visible' : (elm.currentStyle.width.match(/^(0|[12](%|px)?)$/) ? 'visible' : 'hidden');
						backgroundImage = 'none';
					}
					elm.appendChild(pngLayer);
			
			}
		}
	})(elm, noOverflow);
	try{
		pngFixLoader.useOnload ? pngFixLoader.addFunc(exec) : exec();
	} catch(e) {};
}



/* pngFixLoader 
	@unction 		:	objet pour permet le lancement des modifications des png via pngFix en dÃƒÂ©calÃƒÂ© sur le onload de la page.
							cela permet de contourner un bug d'internet explorer qui affiche un message d'erreur si le DOM est modifiÃƒÂ© pendant le chargement de la page.
*/
var pngFixLoader = {
	useOnload : true, // true : active l'execution du fixPng sur le load, et false, execute le fixPng dÃƒÂ¨s qu'il est appelÃƒÂ© par la CSS
	functions : [], // toutes les fonctions Ãƒ  ÃƒÂ©xÃƒÂ©cuter sur le onload de la page
	addFunc : function(func) {
		pngFixLoader.functions.push(func);
	},
	launch : function() {
			pngFixLoader.useOnload = false; //une fois la page chargÃƒÂ©e, il faut laisser s'executer automatiquement la fonction pour d'autres actions (ex : ouverture layer)
			var counter = 1;
			while(pngFixLoader.functions.length>0) {
				//setTimeout(pngFixLoader.functions.pop(), 20*counter);
				pngFixLoader.functions.pop()();
				counter++;
			}
	},
	init : function() {
		if (pngFixLoader.useOnload && window.attachEvent && document.all) {
			window.attachEvent('onload', function() {
				setTimeout(pngFixLoader.launch, 100);
			});
		}
	}
}
pngFixLoader.init();




/* *************************
	SKINABLE INPUT
************************* */

(function (){
	var fs = document.forms;
	for(var i=0;i<fs.length;i++){
		if(fs[i].className.match(/skeenable/)) new skeenableForm(fs[i])
	}
})()

function skeenableForm (form){
	//console.log(form)
	var sels = form.getElementsByTagName('select');
	for(var i=0;i<sels.length;i++){
		new skinableSelect(sels[i])
	}
}



/* *************************
	SKINABLE SELECT
************************* */
var IS_IE = document.all && window.print && !window.opera && ( !document.compatMode || /MSIE [56]/.test(navigator.userAgent) || (document.compatMode && document.compatMode=="BackCompat"));
var IE_NG = document.all && window.print && !window.opera && /MSIE [7-9]/.test(navigator.userAgent) && document.compatMode && document.compatMode!="BackCompat"; //variable pour IE7 et + si besoin.
var IS_quirks = IS_IE && document.compatMode && document.compatMode=="BackCompat"; // variable qui declare le quirksmode seulement utile pour IE
var IS_Webkit = /Konqueror|Safari|KHTML/.test(navigator.userAgent);
var IS_FF = /Firefox/.test(navigator.userAgent);
var IS_MS = /MSIE /.test(navigator.userAgent);
var heightPropertyToUse = IS_IE ? "height" : "minHeight"; //variable utilisee pour l'alignement en hauteur des elements.
var TrDisplayPropertyToUse =  IS_MS ? "block" : "table-row";  // utilisÃ©e pour le toggle des trs d'un table
document.documentElement.className =" hasJS";
document.documentElement.className+= IS_IE ? " IS_IE" : "";




log = function (txt){ 
	if(IS_FF && window.console) console.log(txt);
}

/**
REMPLACE UN SELECT OPTION PAR UN A - UL LI A 
le UL gere l'aspect graphique du select
TOUT L'ASPECT GRAPHIQUE EST GERE  VIA CSS
*/

window.onload = function (){
	select2Skin.init();
	// Non integre dans le launcher d'Arnaud parce que ca buggue dans ce cas
	var _aUls = document.getElementsByTagName('ul');
	var _iUl = _aUls.length;
	while(--_iUl >= 0) {
		if(/\bskeenable\b/.test(_aUls[_iUl].className)) {
			var _aAs = _aUls[_iUl].getElementsByTagName('a');
			var _iA = _aAs.length;
			while(--_iA >= 0) {
				FW(_aAs[_iA]).addEvent(
					'click',
					function(oSelf) {
						return function(e) {
							FW.event.stop(e);
							if(oSelf.href != 0) {
								if(oSelf.href.match(/http/)) {
									window.open(oSelf.href, "_blank");
								}
								else {
									document.location.href = oSelf.href;
								}
							}
						}
					}(_aAs[_iA])
				);
			}
		}
	};
}

var select2Skin = {
	/* recuperation de tous les selects et instanciation si la class "skinableSelect" est detectee */
	init : function (){
		var sels = document.getElementsByTagName('select');
		this.selectObj = [];
		for(var www = sels.length-1; www >=  0; www--){
			if(sels[www] && sels[www].className.match(/\bskeenable\b/g)) {
				var a = new skinableSelect(sels[www]);
				//console.log(sels[www])
				this.selectObj.push(a);
			}
		}
		//console.info(this.selectObj);
	},
	/* fermeture de tous les skinableSelect de la page*/
	closeAll : function (obj){
		for(var i=0; i<this.selectObj.length;i++){
			if(obj != this.selectObj[i]) this.selectObj[i].displayOptions(false);
		}
		
	},
	/* Execution de la mÃ©thode reinit() sur chaque instance de skinableSelect*/
	reinit : function (){
		for(var i=0; i<this.selectObj.length;i++){
			this.selectObj[i].reinit();
		}
	}
}
var skinableSelect = function (elm){
	// check	
	if(elm.nodeName != "SELECT") return;
	//console.log(elm)	//
	
	this.elm = elm;
	
	// set
	this.open = false; // ul masquÃ© par dÃ©faut
	this.above = elm.className.match(/skinableSelect_top/) ? true : false;
	this.comeFromTheClick = false;
	this.maxSize = 150;

	// recupere le label associe	
	this.lab= this.getLabel(elm);
	if(this.lab) this.lab.style.display = "none";
	this.headText = this.lab ? this.lab.innerHTML : this.elm.options[0].innerHTML;

	// recupere les options du select
	this.opts = elm.getElementsByTagName('option');
	
	// modification et masquage su select d'origine
	elm.onchange = function (obj){
		return function (){
			//log()
			obj.update(obj.lis[this.selectedIndex-1].getElementsByTagName('a')[0])
		}
	}(this)
	
	elm.onfocus = function (obj){
		return function (){
			//log()
			obj.a.focus();
		}
	}(this)
	
	//elm.disabled = "disabled";
	//elm.style.visibility = "hidden"; 
	
	// A SPAN remplacant le select  ==> select pour regler la largeur
	this.a = document.createElement('a');
	this.a.className = elm.className;
	this.a.href = "javascript:;";
	this.a.style.position = "absolute";
	//this.a.style.display = "-moz-inline-box";
	//this.a.style.display = "inline-block";
	this.a.style.width = this.elm.offsetWidth + 'px';
	
	
	this.span = document.createElement('span');
	this.span.innerHTML = this.headText;
	this.a.appendChild(this.span);
	
	
	
	this.a.onmousedown = function (obj){
		return function (){
			select2Skin.closeAll(obj);
			obj.displayOptions(!obj.open);
			if(!obj.initialized) obj.fixPosition();
//			skinableSelect.ZINDEX++;
//			obj.ul.style.zIndex = skinableSelect.ZINDEX;
			
			return false;
		}
	}(this)
	
	this.a.onfocus = function (obj){
		return function (){
			obj.currentFocus = -1;
			obj.manageKeyboardEvent(obj, true);
			if(obj.comeFromTheClick) obj.manageKeyboardEvent(obj, false);
			return false;
		}
	}(this);
	
	
	// UL 
	this.ul = document.createElement('ul');
	this.ul.style.position = "absolute";
	this.ul.style.marginTop = 0;
	this.ul.style.paddingLeft = 0;
	this.ul.style.width = this.elm.offsetWidth + 'px';
	
	this.ul.className = elm.className;
//	this.ul.style.zIndex =  skinableSelect.ZINDEX;
	

	// LI A
	this.lis = [];
	this.as = [];
	
	
	
	for(var j = 0; j<this.opts.length; j++){
		var li  = document.createElement('li');
		var a  = document.createElement('a');
		a.href = this.opts[j].value;
		if(a.href == "#") a.href = this.opts[j].innerHTML;
		a.setAttribute('index',j);
		a.innerHTML = this.opts[j].innerHTML;

		a.onclick = function (obj){
			return function (){
				obj.update(this);
				obj.displayOptions(false);
				obj.a.focus();	
				
				return false;
			}
		}(this);
		a.onfocus = function (obj){
			return function (){
				obj.update(this);
			}
		}(this);
		li.appendChild(a);
		this.lis.push(li);
		this.as.push(a);
		this.ul.appendChild(li);
	};
	// insertion
	elm.parentNode.insertBefore(this.a, elm);
	elm.parentNode.insertBefore(this.ul, elm);
	this.ul.onblur = function (obj){
		return function (){
			obj.displayOptions(false);
			return false;
		}
	}(this);
												//elm.parentNode.replaceChild(this.a, elm);
												//$('reservation').appendChild(this.ul);
	
	//
	
	this.ul.style.display = "none";
	var ind = this.lis[this.elm.selectedIndex-1] ? this.elm.selectedIndex : 0;
	//this.update(this.lis[ind].getElementsByTagName('a')[0])
}

// MAJ des champs au select
skinableSelect.prototype.update = function (a){
	this.span.innerHTML = a.innerHTML.length > 19 ? a.innerHTML.slice(0,19)+"..." : a.innerHTML;
	//this.fixSpan();
	this.span.className += " selected";
	if(this.open) this.comeFromTheClick = true;
	this.elm.selectedIndex = a.getAttribute('index');
}

// harmonisation des largeurs
skinableSelect.prototype.fixWidth = function (el){
	el.style.whiteSpace = "nowrap";
	var bL = getCSSRule(el, "borderLeftWidth", true);
	var bR = getCSSRule(el, "borderRightWidth", true);
	this.aWidth = el.offsetWidth - bL - bR;
	el.style.whiteSpace = "normal";
	this.maxWidth = this.aWidth;
	for(var i = 0; i<this.lis.length; i++){
		if(this.as[i].offsetWidth > this.maxWidth) this.maxWidth = this.as[i].offsetWidth;
	}
	
	
	if(this.aWidth < this.maxWidth) {
		this.ul.style.width = this.maxWidth + "px";
		this.span.style.paddingRight = this.maxWidth - this.aWidth  + bL + bR + "px";
		this.initPad = getCSSRule(this.span, 'paddingRight', true);
	}
	else if (this.aWidth > this.maxWidth){
		this.ul.style.width = this.maxWidth + bL + bR + "px";
	}
	else {
		this.ul.style.width = this.maxWidth - bL - bR + "px";
	}
	
	this.ul.style.position = "absolute";

	
}
skinableSelect.prototype.fixSpan = function (el){
	if(this.a.offsetWidth < this.maxWidth) {
		this.span.style.paddingRight = this.maxWidth - this.a.offsetWidth  + "px";
	}
	
	else if (this.a.offsetWidth - getCSSRule(this.a, "borderLeftWidth", true) - getCSSRule(this.a, "borderRightWidth", true) > this.maxWidth){
		this.span.style.paddingRight = "662px";
	}
	else {
		this.span.style.paddingRight = "";	
	}

}

// des ahuteurs
skinableSelect.prototype.fixHeight = function (ul){
	//alert((ul.offsetHeight));
	//alert()
	if(ul.scrollHeight > this.maxSize) {
		ul.style.height = this.maxSize + "px";
	}
	
} 


skinableSelect.prototype.fixPosition = function (){
	// fixPosition
	
	
	
	this.ul.style.left = this.a.offsetLeft - getCSSRule(this.a, "borderLeftWidth", true) - getCSSRule(this.a, "borderRightWidth", true) + "px";
	if (IS_MS) {
		this.ul.style.marginTop = this.a.offsetHeight - getCSSRule(this.a, "borderTopWidth", true) + "px";
	}
	if(this.above) this.ul.style.marginTop = - ( this.ul.offsetHeight + this.a.offsetHeight - getCSSRule(this.a, "borderTopWidth", true)) + 1 + "px";
	this.initialized = true;
	return;
	
}

// gestion de l'evtListener sur les touches fleches haut et bas
skinableSelect.prototype.manageKeyboardEvent = function(obj, giveEvent){
	switch(giveEvent){
		case true:
			document.onkeydown = function (e){
				if (!e) e = window.event;

				if(e.keyCode == 40) {obj.manageFocus(1);return false;} //fl bas
				if(e.keyCode == 35 || e.keyCode == 34) {sens = this.above ? -obj.as.length : obj.as.length; obj.manageFocus(sens);return false;} //fl bas
				
				if(e.keyCode == 38) {obj.manageFocus(-1);return false;} //fl haut
				if(e.keyCode == 33 || e.keyCode == 36) {sens = this.above ? obj.as.length : -obj.as.length; obj.manageFocus(sens);return false;} //fl haut
				
			};
			break;
		case false:
			document.onkeydown = null;
			break;
	}
}

// gestion de l'evt des touches pour gerer le deplacement du focus Ã  l'interieur du ul 
skinableSelect.prototype.manageFocus = function (sens){
	this.currentFocus += sens;
	if(this.currentFocus >= this.as.length) this.currentFocus = this.as.length-1;
	if(this.currentFocus < 0) this.currentFocus = 0;
	if(this.open){
		if(this.as[this.currentFocus]) this.as[this.currentFocus].focus();
	}
	else {
		this.update(this.as[this.currentFocus]);
		this.comeFromTheClick = false;		
	}
};

// affiche / masque les lis du ul (sauf le 1er)
skinableSelect.prototype.displayOptions = function (willBeVisible){
	this.ul.style.display = willBeVisible ? "block" : "none";
	//this.fixWidth(this.a);
	//this.fixHeight(this.ul);
	this.manageKeyboardEvent(this, willBeVisible);
	if(willBeVisible) {
		this.span.innerHTML = this.headText;
		this.span.className = this.span.className.replace(/selected/g, "");
		this.elm.selectedIndex = 0;
		this.ul.className += " open";
	}
	else {
		this.ul.className = this.ul.className.replace(/open/g, "");
	}
	this.open = willBeVisible;
};
 // fermer par defaut


skinableSelect.prototype.getLabel = function(field) {
	var labs = document.getElementsByTagName('label');
	for(var i = 0; i < labs.length; i++){
		var theFor = labs[i].getAttribute('for') || labs[i].getAttribute('htmlFor');
		if(theFor == field.id) {
			return labs[i];
		}
	}
} 

skinableSelect.prototype.reinit = function() {
	this.span.innerHTML = this.headText;
	this.span.className = this.span.className.replace(/selected/g, '')
	this.elm.selectedIndex = 0;
	if(this.open) this.comeFromTheClick = false;
}




