FH = (	function(){
						function _getMeta(n){
								var _m = document.getElementsByTagName("meta");
								for (i = 0;i<_m.length;i++) 
									try {if (_m[i].name == n) return _m[i].content;}catch(ee){};
								return "";
						};

						function _pparams(p){
							var regex = new RegExp( "[\\?&#]"+p.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")+"=([^&#]*)" );  
							var results = regex.exec( window.location.href );  
							return ( results == null )?"":results[1];                                                   
						};
						
						function _cookie( name ) {
							var start = document.cookie.indexOf( name + "=" );
							var len = start + name.length + 1;
							if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
								return null;
							}
							if ( start == -1 ) return null;
							var end = document.cookie.indexOf( ';', len );
							if ( end == -1 ) end = document.cookie.length;
							return unescape( document.cookie.substring( len, end ) );
						};


						function _getLang() {
								var _h = document.getElementsByTagName("html")[0];
								try {return _h.attributes["xml:lang"].value;} catch(ee){};
								try {return _h.attributes["lang"].value;} catch(ee){};
								try {/\/([a-z]{2})\//.exec(document.location);return RegExp.$1;}catch(ee){};
								return "en";
							};
						
						function _en2gb (l){return (l=='en')?'gb':l};
							
						
						var _log = false;  
 						 
						return { 	
							lang : _getLang(),
							version : _getMeta("X-Accor-version"),
							rid :   _getMeta("X-Accor-rid"),
							brand : _getMeta("X-Accor-brand"),
							mark :  _getMeta("X-Accor-mark"),
							mediatype : _getMeta("X-Accor-mediatype"),
							imgpath : _en2gb(_getLang()),
							
							log: function(msg){
								if (_log && window.console)console.log(msg);
							},
							
							getVersion : function() {
								return _getMeta("Generator").substring(9);
							},
							
							getLang : function() {
								return _getLang();
							},
						
							getRid : function(){
								return _getMeta("X-Accor-rid");
							},
							
							getBrand : function(){
								return _getMeta("X-Accor-brand");
							},
							
							getMark : function(){
								return _getMeta("X-Accor-mark");
							},
						
							getMediatype : function(){
								return _getMeta("X-Accor-mediatype");
							},
							
							en2gb : function (l){return (l=='en')?'gb':l},
							
							gb2en : function (l){return (l=='gb')?'en':l},
										
							$ : function (e) {
								return document.getElementById(e);
							},
							
							loadJs : function (jsurl,_def){
						      var _r = "";
						      new Ajax.Request(jsurl, {
  									method: 'get',
  									asynchronous : false,
  									onSuccess: function(transport) {
    									_r = transport.responseText;
  									},
  									onFailure:function(transport){
  										_r = (!_def)?"":_def;
  									}
									});
							    return _r;
							},
							
							getParam : function (p) {              
						    return _pparams(p);                                               
							},                                                         
						  
							getPos : function (p) {                                    
							  return _pparams(p);                                               
							},
							
							cookie: function(name){
								return _cookie(name);
							}
							

						};
					}
)();

FH.fhdyn = {
	
	init : function(O,forceWindowOnLoad) {
		if (Prototype.Browser.IE || forceWindowOnLoad) 	 
			Event.observe(window,"load",function(){O.fhdyn.init();FH.popup.init();FH.tip.init();}); 	 
    else
			Event.observe(document,"dom:loaded",function(){O.fhdyn.init();FH.popup.init();FH.tip.init();});
		
	},
	
	callJson: function (beans,success,failure){

		return	new Ajax.Request(
			'/bean/getViewBeans.action?httpSessionId='+FH.cookie("JSESSIONID")+'&beans='+beans+'&lang='+FH.lang+'&referer='+escape(window.document.referrer), 
			{
  		method: 'get',
  		onSuccess: function(t){success(t.responseJSON)},
  		onFailure: function(t){failure(t.responseJSON)}
			});

	},
	
	callFhJsp : function(){
		return FH.loadJs("/scripts-v60b/fh.jsp?referer="+escape(window.document.referrer),
										'd_webapp = "'+FH.context.getWebapp()+'";d_isUserLoggedIn = false;d_NavBarInfo = new NavBarInfo(false, "","","");d_lienResa = "";d_lienGuide = "";function Reservation(context, identifier, isHotelClosed) {this.context = context;this.identifier = identifier;this.isHotelClosed = isHotelClosed;};d_reservation = new Reservation("", "", true);'
		);
	}
	
}

FH.context = (function(){
		var _webapps = { 
			'travelagencies' : {'code' : 'ALL','mapo':'accor'     ,'domainelement':'travelagencies.accorhotels'},
		  'meetings'       : {'code' : 'ALL','mapo':'accor'     ,'domainelement':'meetings.accorhotels'},
		  'accorhotels'    : {'code' : 'ALL','mapo':'accor'     ,'domainelement':'accorhotels'},
		  'sofitel'        : {'code' : 'SOF','mapo':'SOF'   ,'domainelement':'sofitel'},
			'novotel'        : {'code' : 'NOV','mapo':'NOV'   ,'domainelement':'novotel'},
			'mercure'        : {'code' : 'MER','mapo':'MER'   ,'domainelement':'mercure'},
	    'ibis'           : {'code' : 'IBI','mapo':'IBI'      ,'domainelement':'ibis'},
	    'etaphotel'      : {'code' : 'ETP','mapo':'ETP' ,'domainelement':'etap'},
	    'formule1'       : {'code' : 'FOR','mapo':'formule1'  ,'domainelement':'formule'},
	    'suitehotel'     : {'code' : 'SUI','mapo':'SUI','domainelement':'suite'},
	    'thalassa'       : {'code' : 'THA','mapo':'THA'  ,'domainelement':'thalassa'},
	    'allseasons'     : {'code' : 'ASE','mapo':'accor','domainelement':'all-seasons'},
	    'pullman'        : {'code' : 'PUL','mapo':'PUL'   ,'domainelement':'pullman'},
	    'mgallery'       : {'code' : 'MGA','mapo':'MGA'   ,'domainelement':'mgallery'}
		};
	
	return {
	 
	getWebapp : function (){
    var _h = document.location.host;
    for (var _w in _webapps){
    	if (_h.indexOf(_webapps[_w].domainelement)>-1){return _w}; 
    }
    return 'accorhotels';
	},
	
	getSiteOrigine : function (){
	    var ret = _webapps[FH.context.webapp].code;
      return (ret)?ret:'ALL';
	},
	getMapoContext : function () {
		var ret = _webapps[FH.context.webapp].mapo;
      return (ret)?ret:'accor';
	}
		
	};
})();


FH.context.MEETINGS = "meetings"; 
FH.context.TRAVELAGENCIES = "travelagencies"; 
FH.context.ACCORHOTELS = "accorhotels";
FH.context.SOFITEL = "sofitel";
FH.context.NOVOTEL = "novotel";
FH.context.MERCURE = "mercure";
FH.context.IBIS = "ibis";
FH.context.ETAPHOTEL = "etaphotel";
FH.context.FORMULE1 = "formule1";
FH.context.SUITEHOTEL = "suitehotel";
FH.context.THALASSA = "thalassa";
FH.context.ALLSEASONS = "allseasons";
FH.context.PULLMAN = "pullman";
FH.context.MGALLERY = "mgallery";


FH.context.webapp = FH.context.getWebapp();
FH.context.isMeetings = (FH.context.webapp==FH.context.MEETINGS);
FH.context.isTravelagencies = (FH.context.webapp==FH.context.TRAVELAGENCIES);
FH.context.isAccorhotels = (FH.context.webapp==FH.context.ACCORHOTELS);
FH.context.isSofitel = (FH.context.webapp==FH.context.SOFITEL);
FH.context.isNovotel = (FH.context.webapp==FH.context.NOVOTEL);
FH.context.isMercure = (FH.context.webapp==FH.context.MERCURE);
FH.context.isIbis = (FH.context.webapp==FH.context.IBIS);
FH.context.isEtaphotel = (FH.context.webapp==FH.context.ETAPHOTEL);
FH.context.isFormule1 = (FH.context.webapp==FH.context.FORMULE1);
FH.context.isSuitehotel = (FH.context.webapp==FH.context.SUITEHOTEL);
FH.context.isThalassa = (FH.context.webapp==FH.context.THALASSA);
FH.context.isPullman = (FH.context.webapp==FH.context.PULLMAN);
FH.context.isAllseasons = (FH.context.webapp==FH.context.ALLSEASONS);	
FH.context.isMgallery = (FH.context.webapp==FH.context.MGALLERY);	


/** 
Gestion liens maporama.
*/    
                 
FH.mapo = ( 
		function() {

			function _load() {
				if(FH.mapo.loaded){return;}
			  FH.mapo.loaded=true;
				$('iframemapo').src='http://maps.maporama.com/idl/'+FH.context.getMapoContext()+'/Partner.aspx?MD_height=530&MD_width=735&_rawxml=1&MD_scale=0.00013333&xsl=popup&xml=common&MD_txtStyle=standard&Lang='+FH.gb2en(FH.getLang())+'&siteOrigine='+FH.context.getSiteOrigine()+'&PBC_1_config=2&PBC_1_list='+FH.getRid()+'&PBC_1_extended=free,yes';
				
			};
		
			return {
				
				loaded : false,
				
				toggle : function() {
		  		var _conteneur = $('conteneur_mapo');
					if (_conteneur.style.visibility == "hidden") {
		  			_conteneur.style.visibility = "visible";
		  			_load();
		  		}
		  		else { 
		  			_conteneur.style.visibility = "hidden";
					}
				},
				
				init_map : function(div,lnk) {
					var d = $(div);
					if (!d){return;};
					if (!$(lnk)){lnk=$(div)};
					Event.observe(lnk,'click',function(e){Event.stop(e);FH.mapo.toggle();});
					
					var i = '<div id="conteneur_mapo">';
            i += '<div id="intitule">';
            i += '<h1><img src="/imagerie/reservation/pict_monde.gif"/><img id="titrecarte" src="/'+FH.en2gb(FH.getLang())+'/images/reservation/titre_carte.gif"><div id="txt_cliquez"><img src="/imagerie/reservation/fleche_mapo.gif" id="fleche_mapo"/><a href="#">'+I18N._('fh','Click here to move to move the map')+'</a></div><a href="#" id="lnk_closemapo"><img src="/imagerie/reservation/pict_clot.gif" id="bt_fermer"/></a></h1>';
            i += '<div id="contiframe">';
            i += '<iframe id="iframemapo" name="iframemapo" frameborder="0"/>';
            i += '</div>';
            i += '</div>';
        		i += '</div>';
        		
        	Element.insert($(div),{'after':i});
        	new Draggable('conteneur_mapo');		
					$('conteneur_mapo').style.visibility="hidden";
					Event.observe('lnk_closemapo','click',function(e){Event.stop(e);FH.mapo.toggle();});
					return lnk;
				},
				
				init_iti : function (div) {
					$(div).href = 'http://maps.maporama.com/idl/'+FH.context.getMapoContext()+'/Partner.aspx?xml=common&xsl=driveme&PBC_1_config=2&PBC_1_list='+FH.getRid()+'&Lang='+FH.gb2en(FH.getLang())+'&SiteOrigine='+FH.context.getSiteOrigine();	
				}
				
				
			};
		}
)();

/**
Gestion de la gallerie photo mutualisée.
*/
FH.gallery = {
	
	display	: function (div){
			    
			    var swf = "/flash/fichehotel/galerie.swf", h = "610", w = "490";
			    if (FH.getBrand()=='ibi'){
			    	swf = "/flash/fichehotel/galerie_ibi.swf"; h = "610"; w = "570";
			    } else if (FH.getBrand()=='pul'){
			    	swf = "/flash/fh/galerie.swf"; h = "610"; w = "590";
			    }
			    
			    var so = new SWFObject(swf, "movie", h, w, "7", "#FFFFFF");
               so.addVariable("code", FH.getRid());
               so.addVariable("mark", FH.getMark().toUpperCase());
               so.addVariable("brand", FH.getBrand().toUpperCase());
               so.addVariable("lang", FH.en2gb(FH.getLang()));

            if (FH.getParam('media'))
                so.addVariable("media", FH.getParam('media'));

            if (FH.getParam('cat')) {
                so.addVariable("cat", FH.getParam('cat'));
            } else {
                so.addVariable("cat", "H");
            }

           so.write(div);

		
	}
	
}

/**
Gestion du changmeent d'ipix.
*/
FH.ipix = {
	
	display	: function (ipixName){
		
			var inner  = '<applet name="IpixViewer" height="300" width="400" align="baseline" codebase="/java/" archive="IpixViewer.jar" code="IpixViewer.class">';
			 		 inner +=		'<param name="Toolbar"   value="large">';
			 		 inner +=   '<param name="SpinStyle" value="flat">';
			 		 inner +=   '<param name="URL"       value="/photos/'+ipixName+'">';
			 		 inner += '</applet>';

		$$('applet')[0].replace(inner);
		
	}
	
}

FH.popup = {

	init : function (){
		$$('.popup').each(
			function(a){
				$w(a.className).each(
					function(c){
						if (null != (xy = /p(\d+)-(\d+)(s?)(r?)/i.exec(c)) ) {
							var scrol = (xy[3]=='s')?"yes":"no";
							var res = (xy[4]=='r')?"yes":"no";
							Event.observe(a, 'click', function(e) {Event.stop(e);window.open(a.href,'pop','scrollbars='+scrol+',resizable='+res+',width='+xy[1]+',height='+xy[2]);});
						};
					}
				);
			}
		);
			$$('.openpopup').each(
		function(a){
			$w(a.className).each(
				function(c){
					if (null != (xy = /p(\d+)-(\d+)(s?)(r?)/i.exec(c)) ) {
						var scrol = (xy[3]=='s')?"yes":"no";
						var res = (xy[4]=='r')?"yes":"no";
						Event.observe(a, 'click', function(e) {Event.stop(e);window.open(a.href,'pop','scrollbars='+scrol+',resizable='+res+',width='+xy[1]+',height='+xy[2]);});
					};
				}
			);
		}
	);
		
	}

}

FH.tip = {
	
	//function _promotip (){
	//	jQuery('div#gp').hover(
	//		function(){jQuery(this).find('.tip:hidden').show();},
	//		function(){jQuery(this).find('.tip:visible').hide();}
	//	);
	//};
	init : function(){
	$$('span.picto').each(function(t){
		t.observe('mouseover',function() {t.select('.tip')[0].show();});
		t.observe('mouseout',function() {t.select('.tip')[0].hide();});
		});
	
	}			
}