/*--FUNCTIONS.JS--*/

function fieldFocus(element){
	if(element.value == element.defaultValue){
		element.value = '';
	}
}
function fieldBlur(element){
	if(element.value == ''){
		element.value = element.defaultValue;
	}
}

/*-----------  SLIDE  -----------*/
//Afficher un slide
function displaySlide(target, data, id){

	//on stocke l'élément déclencheur
	var trigger = $$('#'+target+' .pagination li:not(.previous)')[id];

	//Si un affichage de SLIDE n'est pas déjà en cours et que l'élément cliqué n'a pas déjà la classe ACTIVE
	if($(target).readAttribute('status') == 'finished' && !$(trigger).hasClassName('active')){
		$(target).writeAttribute('status', 'running');
		
		//On retire les précédentes classes ACTIVE
		$$('#'+target+' .pagination li.active').each(function(el){
			el.removeClassName('active');
		});
		var trigger = $$('#'+target+' .pagination li:not(.previous)')[id];
		//On applique la classe ACTIVE au <LI> trigger
		$(trigger).addClassName('active');
		
		$(target).writeAttribute('current', id);

		new Effect.Opacity($$('#'+target+' .baseline')[0], {
			from: 1,
			to: 0,
			duration: 0.3,
			afterFinish: function(){
				new Effect.Opacity($$('#'+target+' .background')[0], {
					from: 1,
					to: 0,
					duration: 0.3,
					afterFinish: function(){
						$$('#'+target+' .baseline')[0].innerHTML = '';
						$$('#'+target+' .baseline')[0].setOpacity(1);
						$$('#'+target+' .baseline')[0].setStyle({'display' : 'block'});
						displaySlide_proceed(target, data);
					}
				});
			}
		});
	}
	
}
//Rendu d'affichage du slide
function displaySlide_proceed(target, data){
	
	//On applique l'image de fond à SLIDE BACKGROUND
	$$('#'+target+' .background')[0].setStyle({'backgroundImage' : 'url('+data.img+')'});
	
	//On prépare le contenu du SLIDE
	//var slide = '<div class="title">'+data.title+'</div>';
	//slide += '<div class="desc">'+data.desc+'</div>';
	
	//On insère le contenu du SLIDE
	//$$('#'+target+' .baseline')[0].insert({top : slide});
	
	/*----Annimation----*/
	slideAnimation(target);
	
}
//Slide previous
function slidePrevious(target){

	//On récupère l'ID du slide en cours
	var id = $(target).readAttribute('current');
	id = parseInt(id);
	id--;
	
	
	//Si on a dépassé le dernier, on reviens à 0
	if(id < 0){
	
		//On récupère le nombre de slides possibles
		var size = $(target).readAttribute('length');
		size = parseInt(size);
		
		id = size-1;
	}
	
	//On lance l'animation
	displaySlide(target, slide_data[id], id);
	
}
//Slide next
function slideNext(target){

	//On récupère l'ID du slide en cours
	var id = $(target).readAttribute('current');
	id = parseInt(id);
	id++;
	
	//On récupère le nombre de slides possibles
	var size = $(target).readAttribute('length');
	size = parseInt(size);
	
	//Si on a dépassé le dernier, on reviens à 0
	if(id >= size){
		id = 0;
	}
	
	//On lance l'animation
	displaySlide(target, slide_data[id], id);
	
}
//Génération du Diaporama et de la pagination au chargement de la page
function slideGenerator(target, pagination_mode){
	if($(target)){
		/*--------------------------------------------------GÉNÉRATION DE LA PAGINATION-------------------------------------------------------------------*/
		//On masque le titre de référencement
		if($$('#'+target+' h1').length){
			$$('#'+target+' h1').each(function(el){
				el.setStyle({'display' : 'none'});
			});
		}
		//On stocke le nombre de slides dans un attribut custom du DIV #slide
		$(target).writeAttribute('length', slide_data.length);
		$(target).writeAttribute('auto', 'on');
		//Création de la pagination
		var pagination = '<ul class="pagination">';
		pagination += '<li class="previous" onclick="$(\''+target+'\').writeAttribute(\'auto\', \'off\');slidePrevious(\''+target+'\');"></li>';
		//En fonction de la longeur du JSON, on crée autant de boutons
		for(var i=1; i<=slide_data.length; i++){
		
			if(i <= 3){
				//On précharge les 3 premières images du slide
				$$('body')[0].insert({bottom : '<img src="'+(slide_data[i-1].img)+'" style="display:none;" alt="" />'});
			}
			
			var cnt = i+'';
			//Si on est < 10, on ajoute un "0" devant
			cnt.length < 2 ? cnt = '0'+cnt : '';
			
			pagination += '<li onclick="$(\''+target+'\').writeAttribute(\'auto\', \'off\');displaySlide(\''+target+'\', slide_data['+(i-1)+'], '+(i-1)+');">'+cnt+'</li>';
		}
		pagination += '<li class="next" onclick="$(\''+target+'\').writeAttribute(\'auto\', \'off\');slideNext(\''+target+'\');"></li>';
		pagination += '</ul>';
		//Une fois la pagination prête, on l'insère à la fin de SLIDEDATA
		$(target).writeAttribute('status', 'finished');
		$(target).insert({top : '<div class="background"></div>'});
		$(target).insert({bottom : pagination});
		if(typeof(pagination_mode) != 'undefined' && pagination_mode && slide_data.length > 1){
			$$('#'+target+' .pagination')[0].setStyle({'display' : 'block'});
		}
		else{
			$$('#'+target+' .pagination')[0].setStyle({'display' : 'none'});
		}
		/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
		
		/*--------------------------------------------------------ON AFFICHE LE SLIDE #1--------------------------------------------------------------------------*/
		displaySlide(target, slide_data[0], 0);
		/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	}
}
//Fonction personalisée d'affichage de la zone .baseline
/*-CI-DESSOUS : EXEMPLE-*/
function slideAnimation(target){
	//=> Fade In sur le BACKGROUND
	new Effect.Opacity($$('#'+target+' .background')[0], {
		from: 0,
		to: 1,
		duration: 0.5,
		afterFinish: function(){
			//Callback => Statut FINISHED
			$(target).writeAttribute('status', 'finished');
			if($(target).readAttribute('auto') == 'on'){
				setTimeout("slideNext('"+target+"')", (slide_timer*1000));
			}
		}
	});
}

/*-----------  SQUARE  -----------*/
//Initialisation du carré rouge
function squareSetup(){
	//On spécifie qu'on est pas en cours d'annimation
	$('square').writeAttribute('status', 'ok');
	//Pour chaque <LI> du menu
	$$('#square li').each(function(el){
		//Effet de roll-over
		Event.observe(el, 'mouseenter', function(){
			this.siblings().each(function(el){
				el.addClassName('off');
			});
		});
		//Effet de roll-out
		Event.observe(el, 'mouseleave', function(){
			this.siblings().each(function(el){
				el.removeClassName('off');
			});
		});
		//Si il n'y a pas de lien <a>
		var firstChild = el.childElements()[0];
		if(typeof(firstChild) != 'undefined' && firstChild.tagName != 'A'){
			//Effet de click
			Event.observe(el, 'click', function(event){
				//Si on est pas déjà en cours d'annimation ou en train d'acceder à un lien
				if($('square').readAttribute('status') != 'running' && $('square').readAttribute('accessing') != 'accessing'){
					//On spécifie qu'une annimation est en cours
					$('square').writeAttribute('status', 'running');
					//On sélectionne le NIVEAU suivant
					var level = this.select('> .level')[0];
					//Si l'élément n'est pas déjà affiché
					if(level.getStyle('display') != 'block'){
						//On cache les sous-niveaux éventuellement préalablement déployés
						this.select('.level').each(function(el){
							el.setStyle({'display':'none'});
						});
						//On masque les NIVEAUX équivalent préalablement ouverts
						this.siblings().each(function(el){
							var level = el.select('> .level')[0];
							if(typeof(level) != 'undefined' && level.getStyle('display') == 'block'){
								level.setStyle({'display':'none'});
							}
						});
						//Si il existe
						if(typeof(level) != 'undefined' && level.getStyle('display') != 'block'){
							//On l'ffiche en l'annimant
							level.morph('width:130px;padding-left:10px;padding-right:10px;', {
								duration: 0.3,
								transition: Effect.Transitions.sinoidal,
								//Avant l'effet
								beforeSetup: function(){
									level.setStyle({'overflow':'hidden', 'width':'0', 'paddingLeft':'0', 'paddingRight':'0', 'display':'block'});
								},
								//Après le commencement de l'effet
								afterSetup: function(vars){
									//On check si les enfants sont éventuellement plus grands
									squareLevelCheckHeight(vars.element);
								},
								//Après l'annimation effectuée
								afterFinish: function(vars){
									//Si le niveau n'est pas ajusté
									if(vars.element.readAttribute('adjusted') != 'on'){
										//On rétablit l'overflow
										vars.element.setStyle({'overflow':'visible'});
									}
									//On spécifie que l'annimation est terminée
									$('square').writeAttribute('status', 'ok');
								}
							});
						}
					}
					else{
						level.setStyle({'display':'none'});
						$('square').writeAttribute('status', 'ok');
					}
					return false;
					event.stop();
				}
			});
		}
		else{
			Event.observe(el, 'click', function(event){
				$('square').writeAttribute('accessing', 'accessing');
				return true;
				event.stop();
			});
		}
	});
	//Pour chaque <LI> du menu
	$$('#square .level').each(function(el){
		//Si on click dessus
		Event.observe(el, 'click', function(event){
			//Si on est pas en train d'accéder à un lien
			if($('square').readAttribute('accessing') != 'accessing'){
				//On stope la propagation du click
				event.stop();
			}
		});
	});
}
//Vérification si le nombre d'élément d'un niveau du menu ne dépasse pas la hauteur maximale
function squareLevelCheckHeight(level){
	//Hauteur du niveau
	var levelHeight = level.getDimensions().height;
	//Heuteur du menu
	var levelUlHeight = level.select('> ul')[0].getDimensions().height;
	//Si le menu est plus haut qque son conteneur...
	if(levelUlHeight > levelHeight){
		//Si on est sur mobile
		if(Prototype.Browser.MobileSafari || (typeof(blackberry) != 'undefined' && blackberry)){
			/*//on crée un <select> pour faciliter l'accès aux liens
			squareMobileSelectorInitialize(level);*/
			level.setStyle({'height':'auto'});
		}
		//Sur les autres
		else{
			//On spécifie qu'il vient d'être ajusté
			level.writeAttribute('adjusted', 'on');
			//On masque l'overflow
			level.setStyle({'overflow':'hidden'});
			if(!level.select('.shadowTop').length){
				level.insert({
					bottom:'<span class="shadowTop png_bg"></span><span class="shadowBottom png_bg"></span>'
				})
			}
			//On recale à 0
			level.childElements()[0].setStyle({'top':'0px'});
			//On calcule la position du <UL> dans le document
			var offsetTop = level.childElements()[0].cumulativeOffset().top;
			//On calcule la hauteur du .LEVEL
			var containerHeight = level.getDimensions().height;
			//On calcule la hauteur du la zone à scroller
			var diffHeight = level.childElements()[0].getDimensions().height - level.getDimensions().height + 55;
			Event.observe(level.childElements()[0], 'mousemove', function(event){
				//On calcule la position de la souris dans le <UL>
				var realOffset = event.clientY - offsetTop;
				//On calcule la valeur à déplacer
				var top = Math.ceil((diffHeight * realOffset)/containerHeight);
				//On l'applique
				this.setStyle({'top':(-top + 5)+'px'});
			});
		}
	}
}
/*//POUR LES MOBILES
//On crée le <select>
function squareMobileSelectorInitialize(level){
	//Si il éxiste déjà
	if(typeof($$('#mobileCountrySelector')[0]) != 'undefined'){
		//On le supprime
		$('mobileCountrySelector').remove();
	}
	//On concatène notre nouveau <select>
	var select = '<select id="mobileCountrySelector" onchange="return squareMobileSelectorAccess();">';
	level.select('a').each(function(el){
		select += '<option value="'+(el.readAttribute('href'))+'">'+(el.innerHTML)+'</option>';
	});
	select += '</select>';
	//On l'insère en tête de page
	$$('body')[0].insert({
		top: select
	});
	//On affiche un message indiquant qu'il faut cliquer pour sélectionner le pays
	level.insert({
		bottom: '<div class="message" onclick="return squareMobileSelector(event);">'+mobileSelectMessage+'</div>'
	});
}
//Lorsque l'on clique sur le message
function squareMobileSelector(event){
	//On donne le focus à [#mobileCountrySelector]
	$('mobileCountrySelector').focus();
	//On stope la propagation de l'évènement
	event.stop();
	return false;
}
//Au changement de la valeur du <select>
function squareMobileSelectorAccess(event){
	//On atteind le site concerné
	document.location.href = $('mobileCountrySelector').select('option:selected')[0].value;
	return false;
}*/

//Ajuster le bouton de défilement du diaporama
function adjustBtnNext(){
	if(document.viewport.getWidth() > 1079){
		var adjustBtnNext = Math.floor((document.viewport.getWidth() - 1079) / 2);
		$$('#slide .pagination li.next')[0].setStyle({'right':adjustBtnNext+'px'});
	}
	else{
		$$('#slide .pagination li.next')[0].removeAttribute('style');
	}
}

/*-----------  GREYBOX  -----------*/
//Config générale récurente
var greyBoxDefaultConfig = {
	top: 50,
	duration: 0.6,
	opacity: 0.5
};
//Variable définissant la durée de la transition
var greyBoxEffectDuration = Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000;
//Fonctions GREYBOX
function greyBoxShow(b,c,d,a){if(!$("overlay")){$$("body")[0].insert({bottom:'<div id="overlay" onclick="greyBoxHide();"></div>'});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){new Event.observe(window,"scroll",function(){$("overlay").setStyle({top:$$("body")[0].cumulativeScrollOffset().top+"px"})})}}if(!$("greyBox")){$$("body")[0].insert({bottom:'<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"></div></div>'})}if(typeof(a)!="undefined"){if(typeof(a.duration)=="undefined"){greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000}else{greyBoxEffectDuration=Math.round((a.duration*1000)/2)/1000}if(typeof(a.top)=="undefined"){a.top=greyBoxDefaultConfig.top}if(typeof(a.opacity)=="undefined"){a.opacity=greyBoxDefaultConfig.opacity}if(typeof(a.title)=="undefined"){a.title=greyBoxDefaultConfig.title}if(typeof(a.height)=="undefined"&&typeof(greyBoxDefaultConfig.height)!="undefined"){a.height=greyBoxDefaultConfig.height}if(typeof(a.closeText)=="undefined"&&typeof(greyBoxDefaultConfig.closeText)!="undefined"){a.closeText=greyBoxDefaultConfig.closeText}if(typeof(a.background)=="undefined"&&typeof(greyBoxDefaultConfig.background)!="undefined"){a.background=greyBoxDefaultConfig.background}if(typeof(a.style)=="undefined"&&typeof(greyBoxDefaultConfig.style)!="undefined"){a.style=greyBoxDefaultConfig.style}if(typeof(a.className)=="undefined"&&typeof(greyBoxDefaultConfig.className)!="undefined"){a.className=greyBoxDefaultConfig.className}if(typeof(a.loading)=="undefined"&&typeof(greyBoxDefaultConfig.loading)!="undefined"){a.loading=greyBoxDefaultConfig.loading}if(typeof(a.data)=="undefined"&&typeof(greyBoxDefaultConfig.data)!="undefined"){a.data=greyBoxDefaultConfig.data}if(typeof(a.customFunction)=="undefined"&&typeof(greyBoxDefaultConfig.customFunction)!="undefined"){a.customFunction=greyBoxDefaultConfig.customFunction}}else{greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000;a=greyBoxDefaultConfig}$("overlay").removeAttribute("style");$$("#greyBox .close")[0].innerHTML="";if($("greyBoxTitle")){$("greyBoxTitle").remove()}$("greyBox").writeAttribute("class","");$("greyBox").removeAttribute("class");$("greyBoxContent").removeAttribute("style");if(typeof(a.height)!="undefined"&&d!="iframe"&&d!="youtube"&&d!="dailymotion"){$("greyBoxContent").setStyle({overflow:"auto",height:a.height+"px"})}if(typeof(a.closeText)!="undefined"){$$("#greyBox .close")[0].innerHTML=a.closeText}if(typeof(a.title)!="undefined"){$("greyBox").insert({top:'<h1 id="greyBoxTitle">'+a.title+"</h1>"})}if(typeof(a.background)!="undefined"){$("overlay").setStyle({background:a.background})}if(typeof(a.style)!="undefined"){$("greyBoxContent").writeAttribute("style",a.style)}if(typeof(a.className)!="undefined"){$("greyBox").addClassName(a.className)}$("greyBoxContent").innerHTML='<div id="greyBoxLoader"></div>';if(typeof(a.loading)!="undefined"){$("greyBoxLoader").innerHTML=a.loading}$("greyBox").setStyle({width:c+"px",left:"-"+(Math.ceil(c/2))+"px"});if(typeof(a.customFunction)=="undefined"){switch(d){case"html":var e=function(){$("greyBoxContent").innerHTML=b};greyBoxDisplay(e,a.opacity,a.top);break;case"get":var e=function(){new Ajax.Updater("greyBoxContent",b,{evalScripts:true})};greyBoxDisplay(e,a.opacity,a.top);break;case"post":var e=function(){new Ajax.Updater("greyBoxContent",b,{parameters:a.data,evalScripts:true})};greyBoxDisplay(e,a.opacity,a.top);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML='<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>'};greyBoxDisplay(e,a.opacity,a.top);break;case"youtube":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML='<object width="100%" height="'+f+'"><param name="movie" value="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" allowfullscreen="true" width="100%" height="'+f+'"></embed></object>'};greyBoxDisplay(e,a.opacity,a.top);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML='<object width="100%" height="'+f+'"><param name="movie" value="http://www.dailymotion.com/swf/video/'+b+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="sameDomain"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+b+'" width="100%" height="'+f+'" allowfullscreen="true" allowscriptaccess="sameDomain"></embed></object>'};greyBoxDisplay(e,a.opacity,a.top);break;case"image":var e=function(){$("greyBoxContent").innerHTML=$("greyBoxContent").innerHTML+'<img src="'+b+'" alt="" style="display:none;" id="greyBoxImage" />';new Event.observe("greyBoxImage","load",function(){$("greyBoxImage").setOpacity(0);$("greyBoxImage").setStyle({display:"block"});$("greyBoxLoader").remove();new Effect.Opacity("greyBoxImage",{duration:0.5,from:0,to:1,afterSetup:function(){$("greyBox").setStyle({width:"auto"});$("greyBox").setStyle({left:"-"+(Math.ceil($("greyBoxContent").getDimensions().width/2))+"px"})}})})};greyBoxDisplay(e,a.opacity,a.top);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity,a.top)}return false}function greyBoxDisplay(c,a,b){if($("greyBox").readAttribute("status")!="running"){$("greyBox").writeAttribute("status","running");$("greyBox").setStyle({top:($$("body")[0].cumulativeScrollOffset().top+b)+"px"});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$("overlay").setStyle({position:"absolute",height:document.viewport.getHeight()+"px",top:$$("body")[0].cumulativeScrollOffset().top+"px"});$("greyBoxLoader").setStyle({height:"200px"})}$("overlay").setOpacity(0);$("overlay").setStyle({display:"block"});$$("object:not(.keep-visible), embed").each(function(d){d.setStyle({visibility:"hidden"})});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$$("select").each(function(d){d.setStyle({visibility:"hidden"})})}new Effect.Opacity("overlay",{duration:greyBoxEffectDuration,from:0,to:a,afterFinish:function(){$("greyBox").setOpacity(0);$("greyBox").setStyle({display:"block"});new Effect.Opacity("greyBox",{duration:greyBoxEffectDuration,from:0,to:1,afterFinish:function(){$("greyBox").writeAttribute("status","done");c()}})}})}}function greyBoxHide(){if($("greyBox").readAttribute("status")!="running"){$("greyBox").writeAttribute("status","running");new Effect.Opacity("greyBox",{duration:greyBoxEffectDuration,from:1,to:0,afterFinish:function(){$("greyBox").setOpacity(0);$("greyBox").setStyle({display:"none"});new Effect.Opacity("overlay",{duration:greyBoxEffectDuration,from:$("overlay").getOpacity(),to:0,afterFinish:function(){$("overlay").setOpacity(0);$("overlay").setStyle({display:"none"});$$("object:not(.keep-visible), embed").each(function(a){a.setStyle({visibility:"visible"})});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$$("select").each(function(a){a.setStyle({visibility:"visible"})})}$("greyBox").writeAttribute("status","done")}})}})}};

//Opacité du rollOver du menuDéroulant
var rollOpacity = 0.4;

/*if((Prototype.Browser.IE6=Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6) || (typeof(mobileTestVar) != 'undefined' && mobileTestVar)){
	Event.observe(window,'scroll',function(){
		if(!$('mainMenuContainer').hasClassName('section00')){
			var offset = $('body').cumulativeScrollOffset().top + document.viewport.getDimensions().height - 33;
			$('mainMenuContainer').setStyle({'position':'absolute','top':offset+'px'});
		}
	});
}*/
function toolbar_bottom_ie6fix_math(divName){
	var offset = $$('body')[0].cumulativeScrollOffset().top + document.viewport.getDimensions().height - $(divName).getDimensions().height;
	return offset;
}
function toolbar_bottom_ie6fix(divName){
	if($(divName)){
		Event.observe(window,'load',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'resize',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'scroll',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
	}
}

var carouselTimer = 5;	//secondes
function carousel(){
	if($$('#carousel li').length > 3){
		$('carousel').writeAttribute('current', 0);
		$('carousel').writeAttribute('status', 'ok');
		$('carousel').writeAttribute('mode', 'auto');
		var ulHeight = 0;
		var offset = 0;
		var ctp = 0;
		$$('#carousel li').each(function(el){
			if(ctp < 3){
				ulHeight += el.getDimensions().height;
			}
			el.writeAttribute('offset', offset);
			var height = el.getDimensions().height;
			el.writeAttribute('calc_height', height);
			offset += height
			ctp++;
		});
		$$('#carousel ul')[0].setStyle({'overflow':'hidden', 'position':'relative'})
		$('carousel').setStyle({'overflow':'hidden', 'height':ulHeight+'px', 'marginTop':'10px', 'marginBottom':'10px'});
		$('carousel').writeAttribute('calc_height', ulHeight);
		$('carousel').insert({
			before: '<div id="carouselTop" onclick="$(\'carousel\').writeAttribute(\'mode\', \'manual\');carouselPrev();"></div>',
			after: '<div id="carouselBottom" onclick="$(\'carousel\').writeAttribute(\'mode\', \'manual\');carouselNext();"></div>'
		});
		setTimeout('carouselRecursiveCall(carouselTimer);' , carouselTimer*1000);
	}
}
function carouselRecursiveCall(){
	if($('carousel').readAttribute('mode') == 'auto'){
		carouselNextAuto();
		setTimeout('carouselRecursiveCall(carouselTimer);' , carouselTimer*1000);
		var current = parseInt($('carousel').readAttribute('current', 0));
		if(current == 0){
			$('carousel').writeAttribute('mode', 'manual');
		}
	}
}
function carouselPrev(){
	var current = parseInt($('carousel').readAttribute('current', 0));
	//current -= recursiveCalcHeight(-1, current, 0, 0);
	current--;
	if(current < 0){
		current = 0;
	}
	carouselAccess(current);
}
function carouselNext(){
	var current = parseInt($('carousel').readAttribute('current', 0));
	var previous = current;
	//current += recursiveCalcHeight(1, current, 0, 0);
	current ++;
	if(current >= $$('#carousel li').length){
		current = previous;
	}
	carouselAccess(current);
}
function carouselNextAuto(){
	var current = parseInt($('carousel').readAttribute('current', 0));
	var previous = current;
	//current += recursiveCalcHeight(1, current, 0, 0);
	current ++;
	if(current >= $$('#carousel li').length){
		current = 0;
	}
	carouselAccess(current);
}
function recursiveCalcHeight(increment, id, ctp, totalIncrement){
	if(typeof($$('#carousel li')[id]) != 'undefined'){
		ctp += parseInt($$('#carousel li')[id].readAttribute('calc_height'));
		if(ctp <= parseInt($('carousel').readAttribute('calc_height'))){
			totalIncrement++;
			id = id + increment;
			return recursiveCalcHeight(increment, id, ctp, totalIncrement);
		}
		else{
			return totalIncrement;
		}
	}
	else{
		return totalIncrement;
	}
}
function carouselAccess(id){
	if($('carousel').readAttribute('status') == 'ok'){
		$('carousel').writeAttribute('current', id);
		var offset = parseInt($$('#carousel li')[id].readAttribute('offset'));
		$('carousel').writeAttribute('status', 'running');
		$$('#carousel > ul')[0].morph('top:-'+offset+'px', {
			duration: 0.7,
			afterFinish: function(){
				$('carousel').writeAttribute('status', 'ok');
			}
		});
	}
}

Event.observe(window,'load',function(){
	
	if($('square')){
			//Effet d'apparition du carré
			new Effect.Opacity('square', {
				from:0,
				to:1,
				duration:0.5,
				beforeSetup: function(){
					$('square').setOpacity(0);
					$('square').setStyle({'display':'block'});
				},
				afterFinish: function(){
					$('square').morph('width:297px;', {
						duration: 0.5,
						transition: Effect.Transitions.sinoidal,
						afterFinish: function(){
							$('square').morph('height:297px;', {
								duration: 0.5,
								transition: Effect.Transitions.sinoidal,
								afterFinish: function(){
									$('square').setStyle({'overflow':'visible'});
									squareSetup();
								}
							});
						}
					});
				}
			});
	}
	
	/*if(Prototype.Browser.IE6=Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){
		if(!$('mainMenuContainer').hasClassName('section00')){
			var offset = $('body').cumulativeScrollOffset().top + document.viewport.getDimensions().height - 33;
			$('mainMenuContainer').setStyle({'position':'absolute','top':offset+'px'});
		}
	}*/
	
	//Bouton d'expansion du FOOTER
	Event.observe('expandFooter', 'click', function(){
		this.toggleClassName('collapse');
		$('footerMore').toggleClassName('expanded');
		if(this.hasClassName('collapse')){
			document.location.href = '#footer';
		}
	});
	
	/*---------------------------------------Correction de l'affichage des iFrame sur IE---------------------------------------*/
	//var navigatorVersion = Prototype.Browser.IE6=Prototype.Browser.IE;
	/*var navigatorVersion = true;
	if(navigatorVersion){
		$$('iframe').each(function(el){
			alert(el.descendants()[0]);
		});
		
	}*/
	
	/*$$('#mainMenu dl.menuLang dt .content a.border[target=_blank]').each(function(el){
		Event.observe(el, 'mouseover', function(){
			var src = this.immediateDescendants()[0].readAttribute('src');
			src = src.substr(0, (src.length-4));
			src = src+'_hover.gif';
			this.immediateDescendants()[0].writeAttribute('src', src);
		});
		Event.observe(el, 'mouseout', function(){
			var src = this.immediateDescendants()[0].readAttribute('src');
			src = src.substr(0, (src.length-10));
			src = src+'.gif';
			this.immediateDescendants()[0].writeAttribute('src', src);
		});
	})*/
	
	/*---------------------------------------Gestion des rollOver du menu déroulant---------------------------------------*/
	$$('#mainMenu dl dd').each(function(el){
		if(el.previous().descendants()[0].target!='_blank')
			el.previous().descendants()[0].writeAttribute('href', 'javascript:void(0);');
		
		
		Event.observe(el.previous(), 'click', function(){
			
			if(this.next().getStyle('display') != 'block'){
				$$('#mainMenu dl dd').each(function(el){
					el.setStyle({'display':'none'});
				});
				$$('#mainMenu dl dt').each(function(el){
					el.removeClassName('activeRoll');
				});
				this.addClassName('activeRoll');
				
				this.next().setStyle({'display':'block'});
				if(!this.next().hasClassName('colAdjusted')){
					var maxHeight = 0;
					this.next().descendants()[0].immediateDescendants().each(function(el){
						if(!el.hasClassName('close')){
							if(el.getHeight() > maxHeight){
								maxHeight = el.getHeight();
							}
						}
					});
					this.next().descendants()[0].immediateDescendants().each(function(el){
						if(!el.hasClassName('close')){
							el.setStyle({'height':maxHeight+'px'});
						}
					});
					this.next().addClassName('colAdjusted');
					
					this.next().descendants()[0].next().setStyle({'bottom':'25px'});
				}
				/*if($('flashArea')){
					$('flashArea').squareFadeOut();
					$('flashArea').flashStandby('stop');
				}*/
			}
			else{
				this.removeClassName('activeRoll');
				
				this.next().setStyle({'display':'none'});
				
				/*if($('flashArea')){
					$('flashArea').squareFadeIn();
					$('flashArea').flashStandby('play');
				}*/
			}
			
			return false;
		});
	});
	
	$$('#mainMenu dl dd div.close').each(function(el){
		Event.observe(el, 'click', function(){
			this.ancestors()[0].setStyle({'display':'none'});
			this.ancestors()[1].descendants()[0].removeClassName('activeRoll');
			/*if($('flashArea')){
				$('flashArea').squareFadeIn();
				$('flashArea').flashStandby('play');
			}*/
		});
	});
	
	$$('#flashArea, #cnt, #footer').each(function(el){
		Event.observe(el, 'mouseover', function(){
			$$('#mainMenu dl dd').each(function(el){
				if(el.getStyle('display') == 'block'){
					el.setStyle({'display':'none'});
					el.previous().removeClassName('activeRoll');
				}
			});
			/*if($('flashArea')){
				$('flashArea').squareFadeIn();
				$('flashArea').flashStandby('play');
			}*/
		});
	});
	
});


































