Cufon.replace('h1, h2, h4, h5, h6, .price'); //, .main_content_bookmark, .main_content_bookmark_selected

var SERVER_NAME;
var DOMAIN_NAME;
var DOMAIN_NAME;
var DOMAIN_ANCHOR;
var LANGUAGE;
var MINWIDTH;
var MINHEIGHT;
var TAB_REG;
var TAB_GET;
var CONFIRM_URL = false;

function extractUrlParams(){	
	var urlInfos = location.href.substring(location.href.indexOf("?")+1, location.href.length).split('&');
	var allParams = {};
	for (var i=0; i<urlInfos.length; i++){
		var element = urlInfos[i].split('=');
		allParams[''+element[0]+''] = element[1];
	}
	return allParams;
}

function init() {
	var reg = new RegExp("^(http|https)://([^/]+)(.*)$","g");
	TAB_REG = reg.exec(window.document.location.href);
	var tab_path = TAB_REG[3].split('#');
	SERVER_NAME = TAB_REG[2];
	DOMAIN_NAME = SERVER_NAME.replace('localhost.', '');
	DOMAIN_NAME = DOMAIN_NAME.replace('beta.', '');
	var anchorOnly = tab_path[1];
	if(tab_path[1] != undefined) {
		tab_anchor = anchorOnly.split('?');
		DOMAIN_ANCHOR = tab_anchor[0] ? tab_anchor[0] : 'no anchor';
	} else {
		DOMAIN_ANCHOR = tab_path[1] ? tab_path[1] : 'no anchor';
	}
	LANGUAGE = $('meta[http-equiv=content-language]').attr('content');
	TAB_GET = extractUrlParams();
	//console.log("script:init:TAB_GET:" + TAB_GET.openauto);
	//console.log("script:init:TAB_GET:" + TAB_GET.nom);
	MINWIDTH = 1010;
	MINHEIGHT = 600;
	
	if(TAB_REG[3].indexOf('confirm') > -1) {
		CONFIRM_URL = true;
	} else {
		CONFIRM_URL = false;
	}
	
	//console.log("script:init:DOMAIN_ANCHOR:"+DOMAIN_ANCHOR);
	//console.log("script:init:CONFIRM_URL:"+CONFIRM_URL);
}

init();

var iphone = false;
var ipad = false;
var ipod = false;
var android = false;
var blackBerry = false;
//var mozilla = false;
//console.log("script:iphone:navigator.userAgent:" + navigator.userAgent);
if( navigator.userAgent.indexOf("iPhone") > -1 ) { 
	iphone = true; 
}
if( navigator.userAgent.indexOf("iPad") > -1 ) {
	ipad = true;
}
if( navigator.userAgent.indexOf("iPod") > -1 ) {
	ipod = true;
}
if( navigator.userAgent.indexOf("Android") > -1 ) {
	android = true;
}
if( navigator.userAgent.indexOf("BlackBerry") > -1 ) {
	blackBerry = true;
}

/*==========================================================================
				* OVERLAY CLOSE WIDGET*
==========================================================================*/
function displayOverlayCloseWidget() {
	$('#overlay_close_widget').css('display', 'block');
};
function hideOverlayCloseWidget() {
	$('#overlay_close_widget').css('display', 'none');
};	

function ThereCanBeOnlyOne() {
	var elements = new Object();
	
	this.addElement = function(elementObj) {
		eval('elements.'+elementObj.prefix+' = elementObj;');
	}
	
	this.openElement = function(elementRef) {
		//console.log("script:openElement:elementRef:"+elementRef);
		$.each(elements, function(key, element) {
			if (element.prefix != elementRef) {
				if (element.isopen) {
					element.fnClose();
					element.isopen = false;
					if (element.prefix == 'mainBox') {
						element.mustbeopen = true;
					}
				}
			}
		});
		eval('elements.'+elementRef+'.fnOpen();');
		eval('elements.'+elementRef+'.isopen = true;');
	}
	
	this.closeElement = function(elementRef) {
		eval('elements.'+elementRef+'.fnClose();');
		eval('elements.'+elementRef+'.isopen = false;');
		//console.log('main box is open: '+elements.mainBox.isopen);
		if (elementRef != 'mainBox') {
			if (elements.mainBox.mustbeopen && !elements.mainBox.isopen) {
				elements.mainBox.fnOpen();
				elements.mainBox.isopen = true;
			}
		}
		else { elements.mainBox.mustbeopen = false; }
		
		hideOverlayCloseWidget();
	}
	
	this.closeElements = function() {
		$.each(elements, function(key, element) {
			if (element.isopen) {
				element.fnClose();
				element.isopen = false;
			}
		});
		hideOverlayCloseWidget();
	}
}

var thereCanBeOnlyOne = new ThereCanBeOnlyOne();
thereCanBeOnlyOne.addElement({
	prefix: 'mainBox', 
	isopen: false, 
	fnOpen: function() {
		//console.log('open mainbox');
		mainBoxOpen();
	}, 
	fnClose: function() {
		//console.log('close mainbox');
		mainBoxClose();
	}
});

var main_box_open = false;
function mainBoxClose()
{
	if ($.browser.msie && $.browser.version.slice(0,1) < 9) {
		$('#main-box-thumb').css('display', 'block');
		$('#main-box').css('display', 'none');
	}
	else {
		$('#main-box').fadeOut('fast');
		$('#main-box-thumb').fadeIn('normal', function() {
			var position = 'top';				
		});
	}
	main_box_open = false;
}
	
function mainBoxOpen()
{
	if ($.browser.msie && $.browser.version.slice(0,1) < 9) {
		$('#main-box-thumb').css('display', 'none');
		$('#main-box').css('display', 'block');
	}
	else {
		$('#main-box-thumb').fadeOut('fast');
		$('#main-box').fadeIn();
	}
	main_box_open = true;
	//overlayShow();
}

$(document).ready(function(){
	/*==========================================================================
				* DETECTION NAVIGATOR *
	==========================================================================*/
	var navMoins = false;
	var ua = $.browser;
	var ua_version = parseInt(ua.version.slice(0,3));
	if ( ua.msie && (ua_version < 9) ) {
		navMoins = true;
	} else {
		navMoins = false;
	}
	var ua_chrome;
	
	if( ua.safari ) {
		ua_chrome = true;
	} else {
		ua_chrome = false;
	}
	
	//console.log("script:navigateur:navMoins:"+navMoins+":ua:"+ua+":ua_version:"+ua_version);
	
	/*==========================================================================
				* LANGUAGE *
	==========================================================================*/
	$('#header_all_language a[id="'+LANGUAGE+'"]').css("color", "#ffffff");
	
	
	/*==========================================================================
				* SLIDESHOW *
	==========================================================================*/
	var playAutoSlideshow = true;
	var slideshowAllLoaded = false
	var slideShow = new SlideShow({
		containerId:'slideshow_container', //Required
		itemIdPrefix:'img_',
		timerBetweenSlide:5000, 
		timerFadeTransition:1000, 
		itemClassName:'slideme',
		playAuto:playAutoSlideshow,
		minWidth:MINWIDTH,
		minHeight:MINHEIGHT,
		onBeforeLoad:function() {
			;
		}, 
		onAfterLoad:function() {
			actionResize(MINWIDTH, MINHEIGHT);
			slideshowAllLoaded = true;
			$('#slideshow_nav_next').css('display', 'block');
			$('#slideshow_nav_prev').css('display', 'block');
			startSlideshow();
		},
		onBeforeSlide:function(position) {
			$('#slideshow_nav_next_cpt').html(position+' / '+slideShow.itemNb);
			if(!slideShow.isPlaying() && playAutoSlideshow) slideShow.play();
		} ,
		onAfterSlide:function(position) {
			;
		} 
	});
	
	$('#slideshow_nav_next_cpt').html('1 / '+slideShow.itemNb);
	
	if($.browser.msie && ( $.browser.version.slice(0,3) == "7.0" || $.browser.version.slice(0,3) == "8.0") ) {
		slideshowAllLoaded = true;
		$('#slideshow_nav_next').css('display', 'block');
		$('#slideshow_nav_prev').css('display', 'block');
	}
	
	actionResize(MINWIDTH, MINHEIGHT);
	
	$(window).resize(function(){  
        slideShow.resize();
    });
	
	function startSlideshow(){
		if(!slideShow.isPlaying() && slideshowAllLoaded){
			//console.log('startSlideshow');
			slideShow.play();
		}
	}
	
	function stopSlideshow(){
		slideShow.stop();
	}
	
	function callNextSlideshow(){
		//console.log('slideShow.isPlaying:'+slideShow.isPlaying());
		if(slideShow.isPlaying()){
			slideShow.next();
		}
	}
	function callPrevSlideshow(){
		//console.log('slideShow.isPlaying:'+slideShow.isPlaying());
		if(slideShow.isPlaying()){
			slideShow.prev();
		}
	}
	
	/*==========================================================================
				* SLIDESHOW NAV *
	==========================================================================*/
	$('#slideshow_nav_prev').click(function() {
		if(mainHoteContentOpen)
		{
			closeMainHoteContent();
			hideOverlayClose();
		}
		callPrevSlideshow();
	});
	$('#slideshow_nav_next').click(function() {
		if(mainHoteContentOpen)
		{
			closeMainHoteContent();
			hideOverlayClose();
		}
		callNextSlideshow();
	});	
	
	/*=========================================================================
				* RESIZING *
	=========================================================================*/
	var windowWidthMin = MINWIDTH;
	var windowHeightMin = MINHEIGHT;
		
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	
	function mainBoxResize() {
		if (!$.browser.msie || ($.browser.msie && $.browser.version.slice(0,1) > 7)) {		
			if (screenHeight > 650) {
				if ($('#main-box').hasClass('main-box')) {
					mainBoxMin();
					$('#main-box-bt-max-container').css('display', 'block');
					$('#main-box-bt-min-container').css('display', 'none');
				}
				if ($('#main-box').hasClass('main-box-768')) {
					$('#main-box-bt-min-container').css('display', 'block');
					$('#main-box-bt-max-container').css('display', 'none');
				}
			}
			else {
				mainBoxMax();
				$('#main-box-bt-max-container').css('display', 'none');
				$('#main-box-bt-min-container').css('display', 'none');
			}
			
			if (screenWidth < 1450) {
				$('#main-box-bt-menu-container').css('display', 'block');
			}
			else { $('#main-box-bt-menu-container').css('display', 'none'); }
		}
	}
	
	function actionResize() {
		windowWidthMin = MINWIDTH;
		windowHeightMin = MINHEIGHT;
		
		windowWidth = $(window).width();
		windowHeight = $(window).height();
		//console.log('script:actionResize:windowWidth:' + windowWidth + ':windowHeight:' + windowHeight);
		
		if(windowWidth <= windowWidthMin) {
			var posX_sub_menu_right = -(windowWidthMin - windowWidth) + 285;
			$('#sub_menu_right').css('right', posX_sub_menu_right);
			
			windowWidth = windowWidthMin;
			$('html').css('overflow-x', 'auto');
		} else {
			$('html').css('overflow-x', 'hidden');
			$('#sub_menu_right').css('right', 285);
		}
		if(windowHeight <= windowHeightMin) {
			windowHeight = windowHeightMin;
			$('html').css('overflow-y', 'auto');
		} else {
			$('html').css('overflow-y', 'hidden');
		}
		$('body').css('width', windowWidth);
		$('html').css('width', windowWidth);
		$('html').css('height', windowHeight);
		
		$('#slideshow_container').css('width', windowWidth);
		$('#slideshow_container').css('height', windowHeight);
		
		$('#header').css('width', windowWidth);
		
		$('#header_logo').css('width', windowWidth);
		
		$('#slideshow_nav_prev').css('top', windowHeight - 194);
		$('#slideshow_nav_next').css('top', windowHeight - 194);
		$('#slideshow_nav_next').css('left', windowWidth - 104);		
		
		$('#minia_content_hote').css('top', windowHeight - 240);
		$('#minia_content_hote').css('width', windowWidth);
		
		$('#minia_content').css('marginLeft', (windowWidth / 2) - 108);
		changeMinia('show');
		
		$('#main_menu').css('width', windowWidth);
		$('#main_menu_left').css('width', windowWidth / 2);
		$('#main_menu_right').css('width', windowWidth / 2);
		
		$('#footer').css('width', windowWidth);
		$('#footer').css('top', windowHeight - 147);
		
		$('#shadow_borders').css('width', windowWidth);
		$('#shadow_borders').css('height', windowHeight);
		$('#shadow_borders_more_right').css('width', windowWidth);
		
		$('#tripadvisor_excelence_on').css('top', windowHeight - 201);
		$('#tripadvisor_excelence_off').css('top', windowHeight - 201);
		
		slideShow.resize(windowWidthMin, windowHeightMin);
		
		//mainBoxResize();
	}
	
	$(window).resize(function(){ 
        actionResize();
    });
	
	//TEMPORAIRE
	//console.log("script:width_main_menu_left:" + $('#main_menu_left').
	
	/*==========================================================================
				* OVERLAY CLOSE *
	==========================================================================*/
	$('#overlay_close').click(function() {
		hideOverlayClose();
		closeMainHoteContent();
		thereCanBeOnlyOne.closeElement('mainBox');
	});
	
	function displayOverlayClose() {
		$('#overlay_close').css('display', 'block');
	};
	function hideOverlayClose() {
		$('#overlay_close').css('display', 'none');
	};
	
	/*==========================================================================
				* OVERLAY CLOSE WIDGET*
	==========================================================================*/
	$('#overlay_close_widget').click(function() {
		hideOverlayCloseWidget();
		thereCanBeOnlyOne.closeElements();
	});
	
	/*=========================================================================
				* LOGO *
	=========================================================================*/	
	function gestionLogo(etat)
	{
		var nivOpacity;
		
		if(navMoins == false) {
			switch(etat) {
				case "on":
					nivOpacity = 1;
				break;
				case "off":
					nivOpacity = 0.3;
				break;
			}
			$('#header_logo').stop(true, true).animate(
				{opacity: nivOpacity},
				{queue: false,
				duration: 90,
				easing: 'easeOutQuart'}
			);
		} else {
			if(etat == "on") {
				$('#header_logo').css('display', 'block');
			} else {
				$('#header_logo').css('display', 'none');
			}
		}		
	}
	
	/*=========================================================================
				* =TARIFS *
	=========================================================================*/
	$('#header_rates_button').click(function(){
		init();
		if(DOMAIN_ANCHOR.indexOf('tarifs-chambres') > -1) {
			changeMinia('hide');
		}
	});
	
	var oSliderTarif = $('#slider-tarifs');
	if(oSliderTarif.length > 0){
		oSliderTarif.tinycarousel({ controls: true, pager: true, animation: false });
	}
	
	$('.pager li a').click(function(){
		var multiple = parseInt($(this).attr('rel'));
		var valeur = -multiple*670;
		var valeurStr = valeur.toString() + 'px';
		$('#slider-tarifs .viewport .overview').animate({
			"left": valeurStr
		}, 300);
	});
	
	
	/*=========================================================================
				* MAIN MENU ET SOUS-MENU *
	=========================================================================*/	
	var thisName;
	var nowName;
	var mainMenuOpen = false;
	
	function changeStateShadowBorders(etat) {
		if(etat == 'show') {
			$('#shadow_borders_more_right').show();
			$('#shadow_borders_more_left').show();
		}else if(etat == 'hide') {
			$('#shadow_borders_more_right').hide();
			$('#shadow_borders_more_left').hide();
		}
	}
	
	function gestionMenu(_this) {
		thisName = $(_this).attr('name');
		nowName = $('.menu_rub[class*="current"]').attr('name');
		if(nowName != undefined && nowName == thisName) {
			//on referme/reset le sous-menu courrant
			$(_this).removeClass('current');
			$('.sub_menu_element[name$="' + thisName + '"]').slideUp();
			//on fait disparaitre les ombres ajoutées
			changeStateShadowBorders('hide');
			//on initialise l'état du logo
			gestionLogo("on");
			//on initialise les indicateurs
			nowName = undefined;
			mainMenuOpen = false;
		} else if (nowName != undefined && nowName != thisName && thisName != undefined) {
			//on ferme/reset le sous-menu ouvert
			$('.sub_menu_element[name$="' + nowName + '"]').slideUp(function(){
				//on ouvre le sous-menu demandé
				$('.menu_rub[name$="'+ thisName +'"]').addClass('current');
				$('.sub_menu_element[name$="' + thisName + '"]').slideDown();
			});
			$('.menu_rub[class*="current"]').removeClass('current');
			//on initialise l'état du logo
			gestionLogo("off");
			//on initialise les indicateurs
			mainMenuOpen = true;
		} else if(thisName == undefined) {
			//cas de fermeture automatique
			//on referme/reset le sous-menu courrant
			$('.menu_rub[name$="'+ nowName +'"]').removeClass('current');
			$('.sub_menu_element[name$="' + nowName + '"]').slideUp();
			//on fait disparaitre les ombres ajoutées
			changeStateShadowBorders('hide');
			//on initialise l'état du logo
			gestionLogo("on");
			//on initialise les indicateurs
			nowName = undefined;
			mainMenuOpen = false;
		} else {
			//on ouvre le sous-menu demandé
			$(_this).addClass('current');
			$('.sub_menu_element[name$="' + thisName + '"]').slideDown();
			//on fait apparaitre les ombres ajoutées
			changeStateShadowBorders('show');
			//on initialise l'état du logo
			gestionLogo("off");
			//on initialise les indicateurs
			mainMenuOpen = true;
		}
	};
	
	$(".menu_rub").click(function() {
		gestionMenu(this);
	});
	
	$(".menu_ssrub").mouseover(function() {
		if(navMoins == false && !$(this).hasClass('current')){
			if($(this).hasClass('right_side')) {
				$(this).stop(true, true).animate(
					{marginRight:"10px"},
					{queue: false,
					duration: 200,
					easing: 'easeOutQuart',
					complete: function(){
					}}
				);	
			}else {
				$(this).stop(true, true).animate(
					{marginLeft:"10px"},
					{queue: false,
					duration: 200,
					easing: 'easeOutQuart',
					complete: function(){
					}}
				);	
			}
		}
	});
	
	$(".menu_ssrub").mouseout(function() {
		if(navMoins == false && !$(this).hasClass('current')){
			if($(this).hasClass('right_side')) {
				$(this).stop(true, true).animate(
					{marginRight:"0px"},
					{queue: false,
					duration: 200,
					easing: 'easeOutQuart',
					complete: function(){
					}}
				);
			}else {
				$(this).stop(true, true).animate(
					{marginLeft:"0px"},
					{queue: false,
					duration: 200,
					easing: 'easeOutQuart',
					complete: function(){
					}}
				);	
			}
		}
	});
	
	/*---------INITIALISATION SOUS-MENU-----------*/
	$('.sub_fleche[name$="hebergement"]').css('background-position' , '0 76px');
	$('.sub_list[name$="hebergement"]').css('margin-top', '74px');
	$('.sub_fleche[name$="gastronomie"]').css('background-position' , '0 146px');
	$('.sub_list[name$="gastronomie"]').css('margin-top', '71px');
	$('.sub_menu_element[class*="right_side"]').css('float', 'right');
	var cssFleche = {
		'float' : 'right',
		'margin' : '0 0 0 15px',
		'background' : 'url(/image/fleche_menu_right.png) no-repeat'
    }
	$('.sub_fleche[class*="right_side"]').css(cssFleche);
	
	$('.sub_border[class*="right_side"]').css('float', 'right');
	
	var cssList = {
		'float' : 'right',
		'margin' : '0 15px 0 0',
		'text-align' : 'right'
    }
	$('.sub_list[class*="right_side"]').css(cssList);
	$('.sub_fleche[name$="loisirs-et-decouvertes"]').css('background-position' , '0 76px');
	$('.sub_list[name$="loisirs-et-decouvertes"]').css('margin-top', '30px');
	$('.sub_fleche[name$="informations"]').css('background-position' , '0 146px');
	$('.sub_list[name$="informations"]').css('margin-top', '95px');
	
	var tab_url = TAB_REG[3].split('/');
	var SECTION = tab_url[2];
	//console.log("script:SECTION:" + SECTION);
	$('.sub_list[name='+SECTION+'] > ul > li > .menu_ssrub_link').each( function(key, element) {
		if(this.rel != "pdf") {
			var currentElementHref = element.href;
			var currentAnchorTab = currentElementHref.split('#');
			this.href = '#'+currentAnchorTab[1]+'?openauto=true';
		}
	});
	
	$('.menu_ssrub_link').click(function() {
		if(this.rel != "pdf") {
			var tab_localAnchor = this.href.split("#");
			localAnchor = tab_localAnchor[1];
			tab_localAnchor = localAnchor.split("?");
			autoOpen(tab_localAnchor[0]);
		}
	});
	
	function autoOpen(infos) {
		if(infos == DOMAIN_ANCHOR) {
			changeMinia('hide');
		}
	}
	
	/*==========================================================================
				* MAIN BOOKMARK *
	==========================================================================*/
	$('.main_bookmark').click(function() {
		//console.log("script:main_bookmark");
		openMainHoteContent();
	});
	
	var main_content_panel_current_index;
	if($('.main_content_bookmark')[0] != undefined) {
		main_content_panel_current_index = $('.main_content_bookmark')[0].id;
	}else {
		main_content_panel_current_index = "-1";
	}
	
	/*==========================================================================
				* MAIN HOTE CONTENT BOX *
	==========================================================================*/
	var mainHoteContentOpen = false;
	var newsDisplay = false;
	
	$('#bt_actualites').click(function() {
		newsDisplay = true;
		openMainHoteContent();
		return(false);
	});
	$('#main_hote_content_stream_close').click(function() {
		closeMainHoteContent();
	});
	
	function openMainHoteContent() {
		//console.log("openMainHoteContent");
		stopSlideshow();
		if(mainMenuOpen == true) {
			gestionMenu(nowName);
		}
		if(newsDisplay == true) {
			$('#main_actualites').css('display', 'block');
			$('#main_content').css('display', 'none');
		} else {
			$('#main_actualites').css('display', 'none');
			$('#main_content').css('display', 'block');
			
			$('#main_hote_content').addClass('main_hote_content_format');
			
			updateMainContent();
		}
		
		$('#main_hote_content').css('display', 'block');
		$('#main_hote_content').animate(
			{top: "0px"},
			{queue:false,
			duration: 400,
			easing: 'easeOutQuart',
			complete: function() {
				endAppaMainHoteContent();
			}
		});
		mainHoteContentOpen = true;
		displayOverlayClose();
	};
	
	function endAppaMainHoteContent(){
		if(newsDisplay == false){
			updateScrollbar(DOMAIN_ANCHOR, 'content');
		}
		startSlideshow();
	}
	
	function closeMainHoteContent() {
		stopSlideshow();
		$('#main_hote_content').animate(
			{top: "-700px"},
			{queue:false,
			duration: 300,
			easing: 'easeOutQuart',
			complete: function() {
				endCloseMainHoteContent();
				$('#main_hote_content').css('display', 'none');
			}
		});
		mainHoteContentOpen = false;
		hideOverlayClose();
	};
	
	function endCloseMainHoteContent() {
		startSlideshow();
		if(newsDisplay) {
			newsDisplay = false;
			resetValue();
		} else {
			$('#main_hote_content').removeClass('main_hote_content_format');
			changeMinia('show');
		}
	}
	
	var idMainContent;
	
	function updateMainContent() {
		//console.log("script:updateMainContent:main_content_panel_current_index:" + main_content_panel_current_index);
		init();
		DOMAIN_ANCHOR = DOMAIN_ANCHOR == 'no anchor' ? main_content_panel_current_index : DOMAIN_ANCHOR;
		
		var heightDefault = '264px';
		
		if(DOMAIN_ANCHOR == 'tarifs-chambres') {
			$('#main_content_footer').css('display', 'none');
			
			$('.text_content').addClass('content_max_height_tempo');
			$('.text_content').addClass('content_height_tempo');
			$('.text_content > .viewport').addClass('content_height_tempo');
		} else {
			$('#main_content_footer').css('display', 'block');
			
			$('.text_content').removeClass('content_max_height_tempo');
			$('.text_content').removeClass('content_height_tempo');
			$('.text_content > .viewport').removeClass('content_height_tempo');
			
			$('.main_content_bookmark').removeClass('main_content_bookmark_selected');
			$("#"+DOMAIN_ANCHOR).addClass('main_content_bookmark_selected');
		}
		idMainContent = DOMAIN_ANCHOR;
		
		$('.main_content_panel').css('display', 'none');
		$('#main_content_section_panel_'+DOMAIN_ANCHOR).css('display', 'block');	
	}
	
	/*=========================================================================
				* ACTUALITES *
	=========================================================================*/
	var arr_widgetNewsItems = new Array();
	$('.news_widget_item').each(function(key, item){
		arr_widgetNewsItems.push(item.id);
	});
	var widgetNewsCurrentIndex = 0;
	var delayFade = 500;
	var transitionInP = false;
	var askUpdateFast = false;
	
	var idTemp = arr_widgetNewsItems[0]
	var idNews = idTemp.substr(idTemp.indexOf("news_")+5);
	//console.log("idNews start:" + idNews);
	
	function updateNews(id) {
		////console.log(id);
		if(!transitionInP){
			transitionInP = true;
			askUpdateFast = false;
			stopSlideshow();
			$(".news_widget_item").css('display', 'none');
			$('#news_'+id).fadeIn(delayFade, endAppaNews);
			idNews = id;
			
			updateScrollbar(idNews, 'actu');
			
			
		} else {
			askUpdateFast = true;
		}
	}
	
	function endAppaNews() {
		transitionInP = false;
		if(!askUpdateFast) {
			startSlideshow();
		}else {
			updateNews(getIdValue());
		}
		$('#main_actualite_content_texte_'+idNews).tinyscrollbar_update();
	}
	
	/*==========================================================================
				* SCROLLBAR *
	==========================================================================*/
	function updateScrollbar(id, type){
		if(type == 'actu') {
			$('#main_actualite_content_texte_'+id).tinyscrollbar();
		}else if(type == 'content') {
			$('#text_content_'+id).tinyscrollbar();
		}
	}
	
	$('#main_content_bookmark_hote ul li a').delegate('', 'click', function() {
		var idElement = $(this).attr('id');
		if(idElement == "revue-presse") {
			openMainHoteContent(); /*pour fiorcer le refraichissement de la scrollbar*/
		}
	});
	
	/*==========================================================================
				* MINIA CONTENT *
	==========================================================================*/
	function changeMinia(etat) {
		//console.log("script:changeMinia:etat:" + etat);
		if(etat == 'show') {
			$('#minia_content').fadeIn();
		} else if(etat == 'hide') {
			$('#minia_content').fadeOut('', function() {
				openMainHoteContent();
			});
		}
	}
	
	$('#minia_content').click(function() {
		changeMinia('hide');
	});
	
	/*==========================================================================
				* TRIPADVISOR WIDGET *
	==========================================================================*/
	function active_off(){
		startSlideshow();
		
		$('#tripadvisor_excelence_logo_off').bind("mouseover", function() {
			
			if(!mainHoteContentOpen) {
				
				stopSlideshow();
				
				$('#tripadvisor_excelence_logo_on').unbind("mouseout");
				$('#tripadvisor_excelence_logo_off').unbind("mouseover");
				
				$('#tripadvisor_excelence_off').css('display', 'none');
				$('#tripadvisor_excelence_logo_on').css('width', '70px');
				$('#tripadvisor_excelence_logo_on').css('height', '54px');
				$('#tripadvisor_excelence_on').css('display', 'block');
				$('#tripadvisor_excelence_logo_on').animate(
					{width: "152px",
					height: "117px"},
					{queue:false,
					duration: 200,
					easing: 'easeOutQuart',
					complete: function() {
						active_on();
					}
					}
				);
			}
		});
	}
	
	function active_on(){
		startSlideshow();
		
		$('#tripadvisor_excelence_logo_on').bind("mouseout", function() {
			
			stopSlideshow();
			
			$('#tripadvisor_excelence_logo_on').unbind("mouseout");
			$('#tripadvisor_excelence_logo_off').unbind("mouseover");
			
			$('#tripadvisor_excelence_logo_off').animate(
				{width: "70px",
				height: "54px"},
				{queue: false,
				duration: 200,
				easing: 'easeOutQuart',
				complete: function(){	
					$('#tripadvisor_excelence_on').css('display', 'none');
					$('#tripadvisor_excelence_off').css('display', 'block');		
					active_off();
				}
				}
			);
		});
	}
	
	active_off();
	
	$('#tripadvisor_excelence_logo_on').click(function() { open($('#tripadvisor_excelence_logo_on').attr('name'), "_blank"); } );
	
	/*==============================================================================
				* =WIDGET *
	==============================================================================*/
	$('.newsletterbox-trigger').click(function() {
		thereCanBeOnlyOne.openElement('newsletterBox');
		displayOverlayCloseWidget();
		return(false);
	});
	
	$('.sharebox-trigger').click(function() {
		thereCanBeOnlyOne.openElement('shareBox');
		displayOverlayCloseWidget();
		return(false);
	});
	
	$('.freecallbox-trigger').click(function() {
		thereCanBeOnlyOne.openElement('freecallBox');
		displayOverlayCloseWidget();
		return(false);
	});
	
	/*==============================================================================
				* =BOOKING *
	==============================================================================*/
	$('#booking_valid').click(function() {
		var bookingLink = 'http://hotel.Reservit.com/reservit/reserhotel.php?';
		bookingLink += 'hotelid=54702';
		bookingLink += '&lang='+LANGUAGE;
		if (cf_date.qs_arrival) {
			var arr_arrivalDate = cf_date.qs_arrival.split('-');
			var arrivalDay = arr_arrivalDate[2];
			var arrivalMonth = arr_arrivalDate[1];
			var arrivalYear = arr_arrivalDate[0];
			bookingLink+= '&fday='+arrivalDay;
			bookingLink+= '&fmonth='+arrivalMonth;
			bookingLink+= '&fyear='+arrivalYear;
		
			var nbNights = $('#qs_nights').val();
			nbNights = nbNights.substring(nbNights.indexOf(': ')+2);
			nbNights = nbNights.length > 1 ? nbNights : '0'+nbNights;
			
			var nbAdults = $('#qs_adults_container_input').val().substr(0, 2).replace(' ', '');
			var nbChildren = $('#qs_children_container_input').val().substr(0, 2).replace(' ', '');			

			if (parseInt(nbNights)) {
				bookingLink+= '&nbnights='+nbNights;
			}
				
			if(parseInt(nbAdults)) {
				nbAdults = nbAdults.length > 1 ? nbAdults : '0'+nbAdults;
				bookingLink+= '&numadult='+nbAdults;
				if (parseInt(nbChildren)) {
					bookingLink+= '&numchild='+nbChildren;
					for (var i=1; i<=nbChildren; i++) {
						bookingLink+= '&ages'+i+'=12';
					}
				}
			}
			$(this).attr('href', bookingLink);
		}
		else { 
			$(this).attr('href', bookingLink);
		}
	});
	
	$('.cfe-select-options li').hover(function(){
		$(this).addClass('cfe-select-options-hover');
	}, function(){
		$(this).removeClass('cfe-select-options-hover');
	});
	
	if(ua_chrome == true) {
		$('#qs_arrival_container').css("margin-top", "0px !important");
		$('#qs_nights_container').css("margin-top", "0px !important");
		$('#qs_adults_container').css("margin-top", "0px !important");
		$('#qs_children_container').css("margin-top", "0px !important");
	}
	
	/*=========================================================================
				* =SWFAddress *
	=========================================================================*/
	//TEMPO
	var saveValue = "";
	var saveTitle = document.title;
	
	function resetValue() {
		SWFAddress.setValue(saveValue);
		SWFAddress.setTitle(saveTitle);
	}
	
	function getIdValue() {
		var allValue = SWFAddress.getValue();
		var arr_url = allValue.split('/');
		var idToReturn;
		
		switch(arr_url[1])
		{
			case "news":
				idToReturn = arr_url[2];
			break;
		}
		return idToReturn;
	}
	
	function toTitleCase(str) {
    	return str.substr(0,1).toUpperCase() + str.substr(1).toLowerCase();
	}  
	function formatTitle(title) {
		return document.title;
	}
	
	function handleChange(event) {
	    var index, rel, links = document.getElementsByTagName('a'), path = event.path;
		
    	if (path.substr(path.length - 1) != '/') {
        	path += '/';
    	}
    	for (var i = 0, l, link; link = links[i]; i++) {
        	index = link.rel.indexOf('?');
       		rel = (index > -1) ? link.rel.substr(0, index) : link.rel;
       		link.className = (rel == path) ? 'selected' : '';
    	}
    	var parameters = '';
    	for (var p in event.parameters) {
        	parameters += '&' + p + '=' + event.parameters[p];
    	}
		
		//TEMPO
		SWFAddress.setTitle(saveTitle);
    	SWFAddress.setTitle(formatTitle(event.path));
		
		//TEMPO
		var id = SWFAddress.getValue();
		
		var arr_url = id.split('/');
		
		switch(arr_url[1])
		{
			case "news":
				id = arr_url[2];
				updateNews(id);
				if(!mainHoteContentOpen) {
					newsDisplay = true;
					openMainHoteContent();
				}
			break;
			case "":
				if(arr_url[2] == 'news') {
					id = arr_url[3];
					updateNews(id);
					if(!mainHoteContentOpen) {
						newsDisplay = true;
						openMainHoteContent();
					}
				}
				if(CONFIRM_URL == true) {
					thereCanBeOnlyOne.openElement('newsletterBox');
				}
			break;
			default:
				if(TAB_GET.openauto == "true") {
					changeMinia('hide');
				} else if(CONFIRM_URL == true) {
					thereCanBeOnlyOne.openElement('newsletterBox');
				} else {
					updateMainContent();
				}
			break;
		}
	}
	
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
	
	/*=========================================================================
				* KEYBOARD *
	=========================================================================*/
	function getChar (event){
		var keyCode = ('which' in event) ? event.which : event.keyCode;
        //console.log("The Unicode key code of the released key: " + keyCode);
		
		switch(keyCode){
			/*ECHAP*/
			case 27:
				//console.log("script:getChar:Echap:mainMenuOpen:" + mainMenuOpen);
				if(mainHoteContentOpen){
					closeMainHoteContent();
				} else if(mainMenuOpen == true) {
					gestionMenu(nowName);
				}
				thereCanBeOnlyOne.closeElements();
			break;
			/*RIGHT*/
			case 39:
				if(newsDisplay){
					var urlToGo = $('#main_actualite_nav_next_'+idNews).attr("href");
					//console.log("urlToGo: " + urlToGo);
					window.location = urlToGo;
				}else if(mainHoteContentOpen){
					
				}else{
					callNextSlideshow();
				}
			break;
			/*LEFT*/
			case 37:
				if(newsDisplay){
					var urlToGo = $('#main_actualite_nav_prev_'+idNews).attr("href");
					//console.log("urlToGo: " + urlToGo);
					window.location = urlToGo;
				}else if(mainHoteContentOpen){
					
				}else{
					callPrevSlideshow();
				}
			break;
		}
    }
	$(document).bind("keyup", function(event) {
		getChar(event);
	});
});
