// init namespace (a utiliser pour eviter toute collision)
if(!NOV) {var NOV = {};}

NOV.fhdyn = (function (){
	
	
	function _success(json){
		if (!json.viewBeans){
				_failure(json);
				return;
		}
		if (json.viewBeans.FicheHotelViewBean){
				with(json.viewBeans.FicheHotelViewBean){
					_nav(estListeHotel,urlLH,'/frm_fiche_hotel.svlt?liste=1&indice='+(positionDansListeHotel-1),'/frm_fiche_hotel.svlt?liste=1&indice='+(positionDansListeHotel+1));
					//_groupeLoisir(codeEncart=="LEI");
				}
		}
		
		_favorites(json.viewBeans.ProfileViewBean);
			
		_resaEngine(json.viewBeans.FicheHotelViewBean);	
		
		_oas();
		_mapo();
		
	};
	
	
	function _failure(json){
		FH.log(json);
	};
	
	function _nav(active,link_all,link_prev,link_next){
			if (active){
			  var nav = $("context-link");
				nav.innerHTML='<li class="list"><a href="'+link_all+'">'+I18N._('fh','List of hotels')+'</a></li>'
          +'<li class="previous"><a href="'+link_prev+'">'+I18N._('fh','Previous hotel')+'</a></li>'
          +'<li class="next"><a href="'+link_next+'">'+I18N._('fh','Next hotel')+'</a></li>';
			} else {
				//
			}
	};
	
	function _favorites(profileViewBean){
		var fav = $('lnk_favorites');
		var iframe_profile_src = '/'+FH.imgpath+'/fh/bloc_identification.htm';
			if (profileViewBean){
			fav.href = '/managePreferredHotels.svlt?action=addHotel&code_hotel='+FH.rid+'&code_chaine=NOV';
		} else {
			fav.href = '/'+FH.imgpath+'/fh/pop_favoris.html';
		}
		var ifres = $('iframe_profile');
		if ('iframe'==ifres.tagName.toLowerCase())
			ifres.src=iframe_profile_src;
		else 
			ifres.replace('<iframe id="iframe_profile" src="'+iframe_profile_src+ '" frameborder="0" allowtransparency="true" scrolling="no"></iframe>');
		
		
	};
	
	
	function _resaEngine(ficheHotelViewBean){
		var src;
		if (ficheHotelViewBean.estReservationAutorisee) {
			src= '/'+FH.imgpath+'/fh/bloc_moteur_fh-v66.htm#rid='+FH.rid;
	  	var alt= I18N._('fh','Rates and reservation');
			var inn ='<a href="/express/search.action?search.hotelTarsCode='+FH.rid+'" ><img alt="'+alt+'" src="/'+FH.imgpath+'/images/fh/btn_tarifs_resa.gif" onclick="xt_med(\'C\',getCodeLangue(\''+FH.lang+'\'),\'fiche_hotel::' + FH.rid + '::rates\',\'N\')"/></a>';
	    try {$('btn_resa').innerHTML =inn;} catch(ee){};  
	  } else {
	  	src= '/'+FH.imgpath+'/fh/bloc_moteur_empty_fh-v66.htm#rid='+FH.rid;
	  } 
	  var ifres = $('iframe_resa');
		ifres.replace('<iframe id="iframe_resa" src="'+src+'" frameborder="0" allowtransparency="true" class="bloc-moteur"></iframe>');
	};
  
	function _oas(){
		
		var oas = $('iframe_oas');
		if(oas==null) {return;}
		oas.src= '/'+FH.imgpath+'/fh/push_oas.htm#lang='+FH.lang+'&hotelcode='+FH.rid+'&page='+new String(window.top.location.href).slice(7).split('#')[0];
	};
	
	 function _mapo(){
  	try{FH.mapo.init_map('mapo','lnk_map');}catch(ee){};
  };

	
	return {
	
		init : function(){
			FH.fhdyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);	
		}
	}
}
)();
FH.fhdyn.init(NOV);
	





