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


MER.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);_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_list').attr('href',link_all);
			  jQuery('#pagination').show();
		  } else {
		  	try{jQuery('#pagination li').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();*/
				
			} else {
				link = '/'+FH.imgpath+'/fh/favorites.html';
			}
			
			jQuery('#lnk_favorites').attr('href',link);
			
		} ;

	return {
			
			init:function(){
				
				var r = FH.dyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);
			
			}
	}
	
	
})();

FH.dyn.init(MER);

