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


IBI.fh.display = (function(){
		
	function _gallery(){
						if(jQuery("#flashGallery").length == 0) return;
						var valtvtrip = (jQuery("#extvid").length>0)?1:0;
						var so = new SWFObject("/flash/fh/gallery.swf","gallery", "725", "454", "8", "#FFFFFF");
								so.addParam("wmode", "transparent");
								so.addVariable("tvtrip", valtvtrip );
								so.addVariable("URL_XMLlang",	"/flash/fh/i18n/gallery_"+FH.lang+".xml");
								so.addVariable("URL_XMLhotel", "/fh/xml/");
								so.addVariable("URL_PIC", "http://www.ibishotel.com/photos/");
								so.addVariable("URL_VID", "http://media.ibishotel.com/video/"	);
								so.addVariable("rid", FH.rid);
								so.addVariable("lang", FH.lang);
								so.write("flashGallery");
	};

		
	function _mycarousel_initCallback (carousel) 	{
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		}); 
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		}); 
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	
	function _carousel(){
		if(jQuery("#mycarousel").length == 0) return;
		var i = 0;
		jQuery("#mycarousel li").each(function(){
			i = i+1;									  
		 })
		if(i > 1){
			jQuery("#mycarousel").jcarousel({
					scroll: 1,
					wrap: 'last',
					initCallback: IBI.fh.display._mycarousel_initCallback
			})
		}
	};
	
	function _print(){ 
	  if(jQuery(".print").length == 0) return;
	  jQuery (".print").click(function(){
	  window.print();
	  return false;
	  })
	 };
		
	function _tooltip (){
		if(jQuery('.tooltip').length == 0) return;
		/* CONFIG */
			xOffset = -20;
			yOffset = 8;
		jQuery("li.picto").hover(function(e){  
			jQuery("body").append("<span class='tooltips'>"+jQuery(this).find('.tooltip').html()+"</span>");								 
			jQuery(".tooltips")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");						
		},
		function(){ 	
			jQuery(".tooltips").remove();
		});	
		jQuery(".picto").mousemove(function(e){
			jQuery(".tooltips")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});		
	};
	
	function _promotip (){
		jQuery('span.picto').hover(
			function(){jQuery(this).find('.tip:hidden').show();},
			function(){jQuery(this).find('.tip:visible').hide();}
		);
	};
	
	
	function _scroll () {
		var el = (jQuery.browser.msie || jQuery.browser.mozilla)?"html":"body";
		jQuery(el).scrollTop(jQuery.cookie("scroll"));
		jQuery.cookie("scroll",null);
		jQuery("#navigation a").click(function(){jQuery.cookie("scroll",jQuery(el).scrollTop());}) 
	};
	
	function _histo () {
		//recuperation/stockage
		
		if(!jQuery.cookie("histo"));
		var c = jQuery.cookie("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
		jQuery.cookie("histo",c.join("|"),{ expires: 7, path: '/', domain: 'ibishotel.com', secure: false });
		
		//ecriture		
		var inn ='<ul>';
		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>';
		}
		inn+='</ul>';
		
		jQuery("#bloc-historique h2").after(inn).show();
	};
	
	
  function _mapo(){
  	try{FH.mapo.init_map('#lnk_map',FH.rid,'#leftCol');}catch(ee){};
  	try{FH.mapo.init_map('#lnk_map1',FH.rid,'#leftCol');}catch(ee){};
  	
  };
  
  function _parse(_url) {
			/\-(\d{4})\-/.exec(_url);
			return RegExp.$1;
	};
			
	return {

			init : function(){
				_carousel();
				_tooltip();
				_histo();
				_gallery();
				_mapo();
				_promotip();
				_print();
				_scroll();
			},
			
			toggleTv : function(){
				jQuery("#extvid").toggle();
			}
	
	}
	
})();

function OpenTvtrip() {
	IBI.fh.display.toggleTv();
};

function CloseTvtrip(){
	IBI.fh.display.toggleTv();
};


								
FH.display.init(IBI);

