Event.observe(window, 'load', function(){
 ASE_External.load();
 ASE_Slideshow.load();
 ASE_Noheto.load();
 ASE_Noheto_plus.load();
 ASE_Noheto_autresPlus.observe('previous');
 ASE_Noheto_autresPlus.observe('next');
 ASE_SpecialOffers.load(); 
 
});
 
ASE_SpecialOffers = {
 max : 0,
 load: function(){
  $$('#offres li').each(function(li){ ASE_SpecialOffers.max = (li.getHeight() > ASE_SpecialOffers.max)?li.getHeight():ASE_SpecialOffers.max});
  $$('#offres li').each(function(li){ li.setStyle("height:"+ASE_SpecialOffers.max+"px") ;});
 }
}

ASE_External = {
	brand : 'all-seasons-hotels.com',
	load : function(){
		var regex = new RegExp(this.brand);
		if(!regex.test(window.document.URL))
			$$('body')[0].className = $$('body')[0].className + ' external';
	}
}

ASE_Slideshow = {

	lang : FH.getLang(),
	rid: FH.getRid(),
	mediaType: FH.getMediatype().substr(0,2),
	emplacement : 'slideshow',
	intitule : 'slideshow_ASE',
	load : function(){
		if($(this.emplacement)){		
			var photoslideshow = new SWFObject("/flash/fh/slideshow.swf", this.intitule, "905", "259", "8", "#ffffff");
			photoslideshow.addParam("quality", "best");
			photoslideshow.addParam("wmode", "transparent");
			photoslideshow.addParam("id", this.intitule);
			photoslideshow.addVariable("paramlang", this.lang);
			photoslideshow.addVariable("paramtype", this.mediaType);
			photoslideshow.addVariable("paramrid", this.rid);
			photoslideshow.addVariable("paramloc", $$('body')[0].hasClassName('external'));
			photoslideshow.write(this.emplacement);
		}
	},
	appel : function(str){
		document.getElementById("slideshow_ASE").echo(str);
	}
}

ASE_Noheto = {
	nbBlocs : 2,
	maxImgContent : 3,
	emplacement : 'noh',
	load : function(){
		for (var i=1; i<=this.nbBlocs; i++){
			var e = this.emplacement+i;
			if($(e)){
				var tab = $(e).getElementsBySelector('div.banner');
				if (tab.length <= this.maxImgContent)
					var nbBanniere = tab.length;
				else
					var nbBanniere = this.maxImgContent;
				if(tab.length >= 1){
					keyToShow = Math.randomMax(nbBanniere-1);
					tab[keyToShow].show();
				}else{
					$(e).hide();
				}
			}
		}
	}
}

ASE_Noheto_plus = {
	emplacement : 'les_plus',
	maxPlusContent : 4,
	load : function(){
		var e = this.emplacement;
		if($(e)){
			tab = $(e).getElementsBySelector('div.plus');
			if (tab.length <= this.maxPlusContent)
				var nbPlus = tab.length;
			else
				var nbPlus = this.maxPlusContent;
			if(tab.length >= 1){
				// Si 1 seul élément, on cache les liens "offre précédente" et "offre suivante"
				if(tab.length == 1){
					var offres = $(e).getElementsByClassName('autres_offres');
					for (x in offres){
						// Prototype rajoute des valeurs à notre tableau
						// Les éléments que nous avons cherché ont une clé numérique... Les leurs ont des clés indicées
						if (!isNaN(x))
							$(offres[x]).hide();
					}
				}
				keyToShow = Math.randomMax(nbPlus-1);
				tab[keyToShow].show();
			}else{
				$(e).hide();
			}
		}
	},
	autres_plus : function(position){
		var e = this.emplacement;
		if($(e)){
			var tousLesPlus = $(e).getElementsBySelector('div.plus');
			// S'il y a au moins 2 éléments "plus de l'hotel"
			if(tousLesPlus.length >= 2){
				for (x in tousLesPlus){
					if (!isNaN(x)){
						if(tousLesPlus[x].getStyle('display') != 'none'){
							tousLesPlus[x].hide();
							switch(position){
								case 'previous':
									if (x != 0){
										y = parseInt(x)-1;
									}else{
										y = tousLesPlus.length-1;
									}
									break;
								case 'next':
									if (x != tousLesPlus.length-1){
										y = parseInt(x)+1;
									}else{
										y = 0;
									}
									break;
								default:
									break;
							}
							// On a trouvé notre élément, on peut sortir de la boucle
							break;
						}
					}
				}
				tousLesPlus[y].show();
			}
		}
	}
}

ASE_Noheto_autresPlus = {
	observe : function(CSSclass){
		if ($('les_plus')!=null) {
			elmts = $('les_plus').getElementsByClassName(CSSclass);
		
			for (x in elmts){
				if (!isNaN(x)){
					Event.observe(elmts[x], 'click', function(){
						ASE_Noheto_plus.autres_plus(CSSclass);
					});
				}
			}
		}
	}
}

Math.randomMax = function(maxVal,asFloat){
	var val = Math.random()*maxVal;
	return asFloat?val:Math.round(val);
}

ASE_popup = {
	// Pop up taille VARIABLE AVEC ascenceur et NOM DE FENETRE et redimmensionnable
	pop_var : function(URL, larg, haut){
		window.open(URL, 'pop' + larg + haut, 'location=no, toolbar=no, directories=no, menubar=no, resizable=yes, scrollbars=yes, status=no, width=' + larg + ', height=' + haut);
	},
	// Pop up taille VARIABLE AVEC ascenceur et NOM DE FENETRE
	pop_va : function(URL, larg, haut){
		window.open(URL, 'pop' + larg + haut, 'location=no, toolbar=no, directories=no, menubar=no, resizable=no, scrollbars=yes, status=no, width=' + larg + ', height=' + haut);
	},
	// Pop up taille VARIABLE SANS ascenceur et NOM DE FENETRE
	pop_v : function(URL, larg, haut) {
		window.open(URL, 'pop' + larg + haut, 'location=no, toolbar=no, directories=no, menubar=no, resizable=no, scrollbars=no, status=no, width=' + larg + ', height=' + haut);
	},
	// Fermeture de pop up et chargement d'une page dans la fenetre principale
	close_load : function(URL) {
		window.opener.top.location.href = URL;
		window.close();
	},
	// Fermeture de pop up et chargement d'une page dans une autre fenetre
	close_load_blank : function(URL) {
		window.opener.open(URL,'','');
		self.close();
	},
	// Fermeture de pop up et ouverture nouveau pop up VARIABLE SANS ascenceur
	close_pop_v : function(URL, larg, haut) {
		pop_v(URL, larg, haut)
		self.close();
	},
	// Fermeture de pop up et ouverture nouveau pop up VARIABLE AVEC ascenceur
	close_pop_va : function(URL, larg, haut) {
		pop_va(URL, larg, haut)
		self.close();
	},
	// Pop up taille VARIABLE AVEC ascenceur et NOM DE FENETRE
	pop_vaide : function(URL, nom, larg, haut) {
		window.open(URL, nom, 'location=no, toolbar=no, directories=no, menubar=no, resizable=no, scrollbars=yes, status=no, width=' + larg + ', height=' + haut);
	},
	//popup centree
	popupCentrer : function(page, nom, largeur, hauteur, options) {
		var top  = (screen.height-hauteur)/2;
		var left = (screen.width-largeur)/2;
		window.open(page, nom, "top="+top+", left="+left+", width="+largeur+", height="+hauteur+", "+options);
	}
}

function changeLang(l){window.location='/i18n/setLangue.jsp?lang='+l+'&ref='+escape(window.location);}

