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

FOR.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);	
		
		_checkprice();
		
	};
	
	
	function _failure(json){
		FH.log(json);
	};
	
	function _nav(active,link_all,link_prev,link_next){
			if (active){
			 
				$('precedent').href=link_prev;
				$('suivant').href=link_next;
				$('btn_retour').href=link_all;
			 
			 } else {
					try{$('actionsNavigations').remove();}catch(e){}
			}
	};
	
	function _favorites(profileViewBean){
			
			var link ='';
			if (profileViewBean){
				link = '/managePreferredHotels.svlt?action=addHotel&code_hotel='+FH.rid+'&code_chaine=for';
			} else {
				link = '/'+FH.imgpath+'/fh/pop_favoris.html';
			}
			var oclick = 'window.open(\''+link+'\',\'pop\',\'scrollbars=yes,resizable=yes,width=555,height=415\');';
			if ($('lnk_favorites')) {Event.observe($('lnk_favorites'), 'click', function(){
				eval(oclick);
			});}
			if ($('lnk_favorites2')) {Event.observe($('lnk_favorites2'), 'click', function(){
				eval(oclick);
			});}
		
	};
	
	
	function _resaEngine(ficheHotelViewBean){
		
	  if (ficheHotelViewBean.estReservationAutorisee ) {
		 	try {$('lnk_resa').href="/express/search.action?search.hotelTarsCode="+FH.rid;} catch (ignore){};
		 	try {$('lnk_resa2').href="/express/search.action?search.hotelTarsCode="+FH.rid;} catch (ignore){};
		} else  {
	   	try{$('btn_resa').remove();}catch(ignore){}
	   	try{$('btn_resa2').remove();}catch(ignore){}
	  
		}
	  
	};
	
	function	_checkprice(){
		if (($$(".pricecontainer .price .amount")[0].innerHTML) == "N/A") {
			Element.remove($$(".pricecontainer")[0].parentNode); 
		}
	};
	
	
	return {
	
		init : function(){
			FH.fhdyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);	
		}
	}
}
)();
FH.fhdyn.init(FOR);
	



