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 _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()),
							
							en2gb : function (l){return (l=='en')?'gb':l},
							gb2en : function (l){return (l=='gb')?'en':l},
							
							log: function(msg){
								if (_log && window.console)console.log(msg);
							},
							
							loadJs : function (jsurl,_def){
						      var _r = "";
						      jQuery.ajax( {
						      	url : jsurl,
  									cache : false,
  									type: 'get',
  									async : false,
  									success: function(transport) {
    									_r = transport;
  									},
  									error:function(transport){
  										_r = (!_def)?"":_def;
  									}
									});
							    return _r;
							},
							
							getParam : function (p) {              
						    return _pparams(p);                                               
							}

						};
					}
)();


FH.display = {
	init : function(O,forceWindowOnLoad) {
		jQuery(document).ready(function(){
			O.fh.display.init();
			FH.availabilities.init();
			FH.popup.init();
			FH.currencies.init();
		});
	}
	
}

FH.dyn = {
	
	init : function(O,forceWindowOnLoad) {
		jQuery(document).ready(function(){
			O.fh.dyn.init();
			});
	},
	
	callJson: function (beans,success,failure){
		return jQuery.ajax({url:'/bean/getViewBeans.action?beans='+beans+'&lang='+FH.lang+'&referer='+escape(window.document.referrer),dataType:'json',success:success,error:failure});
	},
	
	callFhJsp : function(){
		return FH.loadJs("/scripts-v56/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.
*/    

/**
mapo en popin draggable, a l'ancienne
*/                 
FH.mapo1 = ( 
		function() {

			function _load(_rids) {
				jQuery('#iframemapo').attr("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.lang)+'&siteOrigine='+FH.context.getSiteOrigine()+'&PBC_1_config=2&PBC_1_list='+_rids+'&PBC_1_extended=free,yes');
			};
			
			function _create(div){
				if(FH.mapo.created){return;}
				FH.mapo.created = true;
					var i = '<div id="conteneur_mapo">';
            i += '<div id="intitule">';
            i += '<h1><img src="/imagerie/reservation/pict_monde.gif"/><img id="titrecarte" src="/'+FH.imgpath+'/images/reservation/titre_carte.gif"><div id="txt_cliquez"><img src="/imagerie/reservation/fleche_mapo.gif" id="fleche_mapo"/><a >'+I18N._('fh','Click here to move to move the map')+'</a></div><a  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" scrolling="no" frameborder="0"/>';
            i += '</div>';
            i += '</div>';
        		i += '</div>';
        	jQuery(div).after(i);
          jQuery('#conteneur_mapo').draggable().hide();
					jQuery('#lnk_closemapo').click(function(e){e.preventDefault();e.stopPropagation();FH.mapo.toggle();});
			};
		
			return {
				created : false,
				rids : FH.rid,
				toggle : function(_rids) {
		  		
		  		var _conteneur = jQuery('#conteneur_mapo');
					_load(_rids);
					_conteneur.toggle();
					
				},
				
				init_map : function(lnk,rids,div) {
					jQuery(lnk).attr("href","#");
					var d = jQuery(div);
					_create (div);	
					
					if (!d){return;};
					if (!lnk){lnk=jQuery(div)};
					
					jQuery(lnk).click(function(e){e.preventDefault();e.stopPropagation();FH.mapo.toggle(rids);});
					
					return lnk;
				},
				
				init_iti : function (div) {
					jQuery(div).attr('href', 'http://maps.maporama.com/idl/'+FH.context.getMapoContext()+'/Partner.aspx?xml=common&xsl=driveme&PBC_1_config=2&PBC_1_list='+FH.rid+'&Lang='+FH.imgpath+'&SiteOrigine='+FH.context.getSiteOrigine());	
				}
				
				
			};
		}
)();

/**
mapo en modal avec nyroModal, a perfectionner
*/
FH.mapo2 = { 
		init_map : function(lnk,rids) {
		var urlmapo = '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.imgpath+'&siteOrigine='+FH.context.getSiteOrigine()+'&PBC_1_config=2&PBC_1_list='+rids+'&PBC_1_extended=free,yes';
		jQuery(lnk)
				.attr('href',urlmapo)
				.attr("target","_blank") //fct curieux de nyroModal
				.nyroModal(
					{
						titleFromIframe: false,
						minWidth: '780',
						minHeight: '600',
						autoSizable: 'false',
						resizable: 'false',
						type: 'iframeForm',
						closeButton: '<span id="modalClose"><a href="#" class="nyroModalClose" id="closeBut" title="close">'+I18N._('popup','Close')+'</a></span>',
						//modal: 'true',
						css: {
							bg: { 
								background: 'white'
							},
							content: {
								 'overflow':'visible'
							},
							wrapper: {
						
								border: 'solid 1px',
								opacity:'1',
								background:'white',
      				  position: 'absolute',
      					'margin-left': '-350px',
							  'margin-top': '-250px'
							  }
						}
					}
				);
		
		}
				
}

FH.mapo = FH.mapo1;

/**
Gestion de la galerie photo.
*/
FH.gallery = {
	
	display	: function (div){
			    var so = new SWFObject("/flash/fh/gallery.swf", "galeriePhotos", "632", "324", "8", "#ffffff");
			so.addParam("quality", "best");
			so.addParam("allowScriptAccess", "true");
			so.addParam("wmode", "transparent");
			so.addVariable("lang", FH.lang);
			so.addVariable("rid", FH.rid);
			so.addVariable("mark", FH.mark);
			so.addVariable("brand", FH.brand);
			so.write(document.getElementById(div));
			    
	}
	
}

/**
Gestion du changmeent d'ipix.
*/
FH.ipix = {
	
	display	: function (ipixName){
		
			var inner  = '<applet name="IpixViewer" height="300" width="400" align="baseline" archive="/java/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>';

			e = jQuery('#virtual-tour').get(0);e.removeChild(e.childNodes[0]);// '.remove' '.inner("")' throws errors
			jQuery('#virtual-tour').html(inner);
		
	}
	
}

FH.popup = {

	init : function (){
		jQuery(".popup").each(function(){
				var a = jQuery(this);
				jQuery(a.attr("class").split(' ')).each(
					function(i,c){
						var xy;
						if (null != (xy = /p(\d+)-(\d+)(r?)(s?)/i.exec(c)) ) {
							var res = (xy[3]=='r')?"yes":"no";
							var scrol = (xy[4]=='s')?"yes":"no";
							a.click( function(e) {e.preventDefault();e.stopPropagation();window.open(a.attr('href'),'po'+c.replace('-','_'),'scrollbars='+scrol+',resizable='+res+',width='+xy[1]+',height='+xy[2])});
						};
					}
				);
			}
		);
	}

}

FH.currencies = ( 
	function() {
		
		function  _adjust(prices){
			prices = prices || jQuery(".price");
			//changement d'ordre
			prices.each(
				function(){
					var c = jQuery(this).find(".currency").html();
					var cur = jQuery(this).find(".currency");
					var amo = jQuery(this).find(".amount");
					var origCur = jQuery(this).find(".origCurrency");
					var origAmo = jQuery(this).find(".origAmount");
						
					if (c=="USD" || c=="GBP" || c=="JPY" || c=="BRL"){
						jQuery(this).empty().append(cur).append("&nbsp;").append(amo).append(origAmo).append(origCur);
					} else {
						jQuery(this).empty().append(amo).append("&nbsp;").append(cur).append(origAmo).append(origCur);
					}
					//changement de signe
			    cur.html(cur.html().replace('EUR',"&euro;").replace('USD',"US$").replace('GBP',"&pound;").replace('JPY',"&yen;").replace('BRL',"R$"));
				}
			);
		};
		
		function _svg(prices){
				(prices || jQuery(".price")).each(
					function(){
						var cur = jQuery(this).find(".currency");
						var amo = jQuery(this).find(".amount");
						jQuery(this).empty().append(amo).append("&nbsp;").append(cur)
							.append(amo.clone().removeClass('amount').addClass('origAmount').hide())
							.append(cur.clone().removeClass('currency').addClass('origCurrency').hide());
					} 
				);
		};
		
		function _revert(prices){
			prices = prices || jQuery(".price");
				prices.each(
					function(){
						
						jQuery(this).find(".currency").html(jQuery(this).find(".origCurrency").html());
						jQuery(this).find(".amount").html(jQuery(this).find(".origAmount").html());
					}
				);
		}
		
		function _convert(rates,currency,prices){
			prices = prices || jQuery(".price");
				prices.each(
					function(){
						var cur = jQuery(this).find(".currency");
						var amo = jQuery(this).find(".amount");
						var origCur = jQuery(this).find(".origCurrency").html();
						var origAmo = jQuery(this).find(".origAmount").html();
						if (origCur!='---' && rates[currency] && rates[origCur] && rates[origCur]!=0 ) {
							cur.html(currency);
						  amo.html((origAmo/ (rates[currency] / rates[origCur])).toFixed(2));
						} else {
							_revert(jQuery(this)); 
						} 
						if (origCur==currency) {_revert(jQuery(this)); /*evite .00*/}
					}
				);
		}
		
		return {
			init:function(prices){
				prices = prices || jQuery(".price");
				_svg(prices);
				_adjust(prices);
			},
			
			convert:function(rates,currency,prices){
				prices = prices || jQuery(".price");
				_convert(rates,currency,prices);
				_adjust(prices);
			},
			
			revert:function(prices){
				prices = prices || jQuery(".price");
				_revert(prices);
				_adjust(prices);
				
			}
		}
	}
)();


FH.availabilities = {

		init : function (){
			
			var  lnk = "/"+FH.imgpath+"/reservation/dispo_calendar.shtml#hotelCode="+FH.rid;
			jQuery('#lnk_avail')
				.attr('href',lnk)
				.attr("target","_blank") //fct curieux de nyroModal
				.nyroModal(
					{
						titleFromIframe: false,
						minWidth: '700',
						minHeight: '650',
						autoSizable: 'false',
						type: 'iframeForm',
						closeButton: '<span id="modalClose"><a href="#" class="nyroModalClose" id="closeBut" title="close">'+I18N._('popup','Close')+'</a></span>',
						//modal: 'true',
						css: {
							bg: { background: '#cacaca', opacity: '.5'},
							content:{overflow:'visible',border:'0'},
							wrapper: {
								border:'0',
								opacity:'1',
								background:'white',
      				  position: 'absolute',
      					'margin-left': '-350px',
							  'margin-top': '-315px'
							  }
						}
					}
				);
		}	

}
		