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));
				}
			}
			
			_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);
	};
	
	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("#myaccorhotels").fadeIn(1500);
			} else {
				link = '/'+FH.imgpath+'/fh/favorites.html';
				jQuery("#myaccorhotels").remove();
			}
			jQuery('#lnk_favorites1').attr('href',link);
			jQuery('#lnk_favorites2').attr('href',link);
		} ;
	
	
	return {
			init:function(){
				var r = FH.dyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);
			}
	}
	
	
})();

FH.dyn.init(ACH);
