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

SUI.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();
	};
	
	
	function _failure(json){
		FH.log(json);
	};
	
	function _nav(active,link_all,link_prev,link_next){
			if (active){
				var nav = $("explorer");
			nav.innerHTML='<li><a href="'+link_prev+'" title="'+I18N._('fh','Previous hotel')+'" ><img src="/'+FH.imgpath+'/images/fh/link-prev-hotel.gif" alt="'+I18N._('fh','Previous hotel')+'" /></a></li>'
			+'<li><a href="'+link_all+'" title="'+I18N._('fh','List of hotels')+'" ><img src="/'+FH.imgpath+'/images/fh/link-list-hotel.gif" alt="'+I18N._('fh','List of hotels')+'" /></a></li>'
			+'<li><a href="'+link_next+'" title="'+I18N._('fh','Next hotel')+'" ><img src="/'+FH.imgpath+'/images/fh/link-next-hotel.gif" alt="'+I18N._('fh','Next hotel')+'" /></a></li>';

			} else {
				//
			}
	};
	
	function _favorites(profileViewBean){
		var fav = $('lnk_fav');
  	if (profileViewBean){fav.href = '/managePreferredHotels.svlt?action=addHotel&code_hotel='+FH.rid+'&code_chaine=sui';} 
  	else {fav.href = '/'+FH.imgpath+'/fh/pop_favoris.html';}
	};
	
	
	function _resaEngine(ficheHotelViewBean){
	  
		
		if (ficheHotelViewBean.estReservationAutorisee && ficheHotelViewBean.flagOuverture) {
			$('lnk_resa').href='/express/search.action?search.hotelTarsCode='+FH.rid;
			src= '/'+FH.imgpath+'/fh/bloc_moteur_fh-v66.htm#rid='+FH.rid;
	  } else  {
			try{$('lnk_resa').remove();}catch(ee){}
			src= '/'+FH.imgpath+'/fh/bloc_moteur_empty_fh-v66.htm#rid='+FH.rid;
	  }
	
	  var ifres = $('iframe_resa');
		ifres.replace('<iframe scrolling="no" src="'+src+'" frameborder="0" id="iframe_resa" allowtransparency="1"></iframe>');
		
	};
	
	
	 function _oas(){
		try{
			var src= '/'+FH.imgpath+'/fh/push_oas.htm#lang='+FH.lang+'&hotelcode='+FH.rid+'&page='+new String(window.top.location.href).slice(7).split('#')[0];
			var ifres = $('iframe_oas');
			ifres.replace('<iframe src="'+src+'" scrolling="no" frameborder="0" id="iframe_oas" allowtransparency="1"></iframe>');
		} catch(ee){};
	};

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

