if(!ACH) {var ACH = {};}
if(!ACH.fh) {ACH.fh = {};};


ACH.fh.dyn = (	function(){
	
	function _success(json){
			if (!json.viewBeans){
				_failure(json);
				return;
			}
			FH.log("succes");
			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);
			
			// test conversion
			//_convert(json.viewBeans.CurrenciesViewBean);
	};
		
	function _failure(json){
		FH.log("failure");FH.log("pb while getting json.ViewBeans");FH.log(json);
		_nav(false);_favorites (null);
		
	};
	
	function _nav(active,link_all,link_prev,link_next){
		  if (active){
		  	jQuery('#lnk_prev').attr('href',link_prev);jQuery('#lnk_next').attr('href',link_next);
		  	jQuery('#lnk_list1').attr('href',link_all);jQuery('#lnk_list2').attr('href',link_all);
			  jQuery('#precedente').show();jQuery('#suivante').show();jQuery('#bloc_list1').show();jQuery('#bloc_list2').show();
		  } else {
		  	try{jQuery('#precedente').remove();jQuery('#suivante').remove();jQuery('#bloc_list1').remove();jQuery('#bloc_list2').remove();}catch(e){/*rien*/}
		  }
	};

	function _convert(currenciesViewBean){
			FH.currencies.convert(currenciesViewBean.currencies,currenciesViewBean.profileCurrency);
	};
	
	function _favorites (profileViewBean){
			var link ='';
			if (profileViewBean){
				link = '/managePreferredHotels.svlt?action=addHotel&code_hotel='+FH.rid+'&code_chaine='+FH.brand;
				//jQuery("#login-account-lnk").attr('href','https://secure.accorhotels.com/'+FH.imgpath+'/profil/modify.shtml').html(I18N._('fh','Change your user ID'));
				//jQuery("#create-account-lnk").attr('href','https://secure.accorhotels.com/authentication/logout.jshtml').html(I18N._('fh','Disconnect'));
				
				/*test ecriture des favoris : var inn ='<div id="bloc-fav"><div class="bloc"><h2>Favorites</h2><ul>';for(hotel in profileViewBean.hotels){inn+= '<li><a href="/frm_fiche_hotel.svlt?code_langue='+FH.imgpath+'&code_hotel='+profileViewBean.hotels[hotel]['code']+'">'+profileViewBean.hotels[hotel]['name']+'</a></li>';}inn+='</ul></div></div>';jQuery("#bloc-historique").after(inn).show();*/
				
				jQuery("#myaccorhotels").show();
			} else {
				link = '/'+FH.imgpath+'/fh/favorites.html';
				jQuery("#myaccorhotels").remove();
			}
			jQuery(".login-form *").show();
			
			jQuery('#lnk_favorites1').attr('href',link);
			jQuery('#lnk_favorites2').attr('href',link);
		} ;
	
	function _groupeLoisir(flag){
		if (flag){
			jQuery("#prix-dispo").remove();
		}
	}
	
	return {
			
			init:function(){
				
				var r = FH.dyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);
			
			}
	}
	
	
})();

FH.dyn.init(ACH);
