if(!PUL) {var PUL = {};}


PUL.slideshow = function(rid,brand,mark,lang,cat) {
			var so = new SWFObject("/flash/fh/slide_show.swf", "flash", "672", "241", "7", "#ffffff");
			so.addParam("wmode", "transparent");
			so.addVariable("code",rid);
			so.addVariable("brand",brand);
			so.addVariable("mark",mark);
			so.addVariable("lang",lang);
			so.addVariable("cat",cat);
			so.write("flash");
};



PUL.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);	
		_histo();
		_popup();		
	};
	
	
	function _failure(json){
		_histo();
		_popup();		

		FH.log(json);
	};
	
	function _nav(active,link_all,link_prev,link_next){
			if (active){
			 
			var nav = $('nav_fh');
			
			nav.innerHTML='<li class="list-hotels"><a href="'+link_all+'">'+I18N._('fh','List of hotels')+'</a></li>'+
            '<li class="list-prev">< <a href="'+link_prev+'">'+I18N._('fh','Previous hotel')+'</a></li>'+
            '<li class="list-next"><a href="'+link_next+'">'+I18N._('fh','Next hotel')+'</a> ></li>';
			 
			 } else {
			 }
	};
	
	function _favorites(profileViewBean){
		var fav = FH.$('lnk_favorites');
			
		if (profileViewBean){
  		link = '/managePreferredHotels.svlt?action=addHotel&code_hotel='+FH.rid+'&code_chaine=PUL';
		} else {
  		link = '/'+FH.imgpath+'/fh/pop_favoris.html';
		}
  	Event.observe(fav, 'click', function(e) {if (e.preventDefault) {e.preventDefault()} else {e.returnValue = false};window.open(link,'pop','scrollbars=yes,resizable=yes,width=400,height=400');});

		
	};
	
	function _histo(){
		//recuperation/stockage
		
		var c = new Cookies().get("histo");
		c= (!c)?[]:c=c.split("|");
		var h = FH.rid+":"+FH.name;
		for (var i=0;i<c.length;i++){
			if (c[i].split(":")[0]==FH.rid){h='';}
		}
		if (h!=''){c.unshift(h);}	
		c = c.slice(0,5);//ongarde les 5 derniers
		var cc = new Cookies('/', 'pullmanhotels.com');
		cc.set("histo",c.join("|"), 7);
		
		//ecriture		
		var inn ='';
		for (var i=0;i<c.length;i++){
			var cs = c[i].split(":");
			inn+= '<li> > <a href="/frm_fiche_hotel.svlt?code_langue='+FH.imgpath+'&code_hotel='+cs[0]+'">'+cs[1]+'</a></li>';
		}
		$$("#bloc-historique ul")[0].innerHTML =inn; 
	};
	
	
	function _resaEngine(ficheHotelViewBean){
		
	  if (ficheHotelViewBean.estReservationAutorisee) {
	  	
			resasrc= '/'+FH.imgpath+'/fh/bloc_moteur_fh-v66.htm#rid='+FH.rid;
		} else  {
	   	resasrc= '/'+FH.imgpath+'/fh/bloc_moteur_empty_fh-v66.htm#rid='+FH.rid;
		}
	  
	  var ifres = $('iframe_rech');
		ifres.replace('<iframe frameborder="0" scrolling="no" id="iframe_rech" src="'+resasrc+'"></iframe>');
		 
		
    
	};
	
	function _popup() {
			var p1,p2,p3;
			p1 = $('visite_virtuelle');
			if (p1){ 
				var a1 = p1.getElementsBySelector('a')[0];
				Event.observe(a1, 'click', function(e) {if (e.preventDefault) {e.preventDefault()} else {e.returnValue = false};window.open(a1.href,'pop','scrollbars=no,resizable=yes,width=572,height=525');});
			}
			
			p2 = $('galerie_photo');
			if (p2){ 
				var a2 = p2.getElementsBySelector('a')[0];
				Event.observe(a2, 'click', function(e) {if (e.preventDefault) {e.preventDefault()} else {e.returnValue = false};window.open(a2.href,'pop','scrollbars=no,resizable=yes,width=611,height=570');});
			}
			
			p3 = $('galerie_video');
			if (p3){ 
				var a3 = p3.getElementsBySelector('a')[0];
				Event.observe(a3, 'click', function(e) {if (e.preventDefault) {e.preventDefault()} else {e.returnValue = false};window.open(a3.href,'pop','scrollbars=no,resizable=yes,width=611,height=570');});
			}
	}
	
	
	return {
	
		init : function(){
			FH.fhdyn.callJson('OriginViewBean|ProfileViewBean|FicheHotelViewBean|HotelsViewBean|CurrenciesViewBean',_success,_failure);	
		}
	}
}
)();
FH.fhdyn.init(PUL);
	


