/*------------------------------------------------------------------------------
JS Document (https://developer.mozilla.org/en/JavaScript)

project:    Lucien Barrière
created:    2011-04-03
author:     djohad

summary:    
MAJX_CORE
CONSTANTES
UTILITIES
WINDOW.ONLOAD
CAROUSEL
SLIDESHOW
DATEPICKER
MAP
SELECTS
POPIN
TABS
SUBTABS
TOOLTIP
MENU
GALLERY
--BEGIN functions not included
                ADDTHISCONFIG
                PRINTIT
                SHOWITEMS
                CHECK
                SHOPPINGCART
                EQUALHEIGHTS
                TABS
--END functions not included
SLIDES
DIAPORAMA HUB

----------------------------------------------------------------------------- */

/* =MAJX_CORE (http://code.google.com/p/majx-js/)
----------------------------------------------------------------------------- */
(function () { if (typeof majx == "undefined") { majx = {}; majx.init = function () { if (!majx.config) { majx.config = {}; } } (); } } ()); majx.set = function () { var e = arguments[0] || {}; var b = null; var d = arguments.length; var c = 1; if (d == c) { e = majx.config; --c; } for (; c < d; c++) { if ((b = arguments[c]) != null) { for (var a in b) { var f = e[a]; var g = b[a]; if (e === g) { continue; } else { if (g !== undefined) { e[a] = g; } } } } } majx.config = e; };


/*  =CONSTANTES
----------------------------------------------------------------------------- */
jQuery.noConflict();
var d = document;
var w = window;
pm = {};
majx.set({
    popin1: {
        target: '.popin',              // target links with this class (CSS 3 Selectors)
        name: {
            popin: 'popin',          // the popin id
            cache: 'cache',          // the popin cache id
            close: 'close',          // the close button id
            content: 'pop-content'     // the id where to extract the code in the target page.
        },
        behaviours: {
            closeClick: true,          // if true permits to click outside the popin to close it
            close: 'Fermer',           // close button, you can also include HTML code
            anim: true,              // true by default, false avoids fadeIn
            resize: false              // experimental to refit the popin when the window is resized
        },
        style: {
            marginMax: 50,             // minimum margin between the popin and the window
            opacity: 0.50,           // cache final opacity
            maxWidth: 250,            // minimal screen width to open popins
            maxHeight: 250             // minimal screen height to open popins
        }/*,
        callback : {                    // events
            onload   : 
        }*/
    },
    tabs: {
        tabs1: {
            id: '.block-tabs-01',
            zones: '.tab',
            menu: '.menu-tabs',
            active: 'on',
            container: '#tabs',
            linkParent: 'li',
            scrollToTop: true
        },
        tabs2: {
            id: '#example2',
            zones: '.tab',
            menu: '#menu2',
            active: 'actif',
            container: '#tabs2',
            linkParent: 'span',
            scrollToTop: true
        }
    }
});



/*  =UTILITIES
----------------------------------------------------------------------------- */
var log = function (x) {
    if (typeof console != 'undefined') {
        console.log(x);
    }
};




/*  =WINDOW.ONLOAD
----------------------------------------------------------------------------- */
jQuery(document).ready(function () {

    // Call Functions
    fnCarousel();
    try { datepicker(); } catch (ex) { }
    selectsBehaviors();
    try { map(); } catch (ex) { }
    ChangeMapDisplay();
    popin1 = new popin(majx.config.popin1);
    fnTabs();
    fnTooltip();
    fnMenu();
    fnSlider();
    flags();
    //fnCompare();
    showHotels();
    goDestination();
    showHide();
    fnSlides();
    newTabs();
    try { frameIt(); } catch (ex) { }
    try { printIt(); } catch (ex) { }

    diapoHubIn();
    diapoInteract();
    diapoStop();
    diapoHubIn();
    diapoHotelStop();

    if (jQuery.browser.msie && jQuery.browser.version == 6) {
        // IE 6 FUNCTIONS ONLY

    }

});


/*  =CAROUSEL
----------------------------------------------------------------------------- */

fnCarousel = function () {
    var elm = jQuery('#carousel-header ul');
    if (elm.length) {
        elm.cycle({
            fx: 'fade',
            speed: 'slow',
            timeout: 5000,
            next: '.next',
            prev: '.previous'
        });
    };

    elm = jQuery('#block-offer .block-carousel:not([class*="disabled"])');
    if (elm.length) {
        elm.jcarousel({
            wrap: 'circular'
        });
    };

    elm = jQuery('.block-slideshow .block-carousel');
    if (elm.length) {
        elm.jcarousel({
            wrap: 'circular',
            scroll: 2
        });
    };
    
    elm = jQuery('.block-carousel:not([class*="disabled"]) .thumbnail');
    if (elm.length) {
        //elm = jQuery('.block-carousel:not([class*="disabled"])  ');
        elm.jcarousel({
            wrap: 'circular',
            scroll: 4
        });
    };

    elm = jQuery('.block-slideshow-02 .block-carousel:not([class*="disabled"])');
    if (elm.length) {
        elm.jcarousel({
            wrap: 'circular',
            scroll: 4
        });
    };
};

fnSlider = function () {
    if (jQuery('#coda-slider-1').length != 0) {
        jQuery('#coda-slider-1').codaSlider({
            dynamicTabs: false,
            autoSlide: true,
            autoSlideStopWhenClicked: true,
            autoSlideInterval: 3000
        });
    }
};

addGallery = function (parentElementId) {
    jQuery(parentElementId+' .block-carousel ul').galleryView({
        panel_width: 816,
        panel_height: 413,
        pointer_size: 0,
        show_panel_nav: false,
        frame_opacity: 1,
        frame_height: 84,
        frame_width: 170,
        frame_gap: 0,
        strip_width: 786,
        show_filmstrip_nav: false,
        start_frame: 2
    });
};

/*  =SLIDESHOW
----------------------------------------------------------------------------- */

function popupSlideshow(value) {
    var message, close = "";
    if (typeof (value) == "string") message = value;
    else { message = value.html; close = value.close || "" }

    jQuery('<div id="cache2"></div> <div id="popin-slideshow"><div id="close"><a href="#">'+close+'</a></div>' + message + '</div>').appendTo('body');
    jQuery("#cache2").animate({ opacity: 0.4 });
    jQuery('#cache2').fadeIn();
    simplePopin();
    addGallery("#slideshow");
    return false;
};

function popupPicture(value) {
    var message, close = "";
    if (typeof (value) == "string") message = value;
    else { message = value.html; close = value.close || "" }

    jQuery('<div id="cache2"></div> <div id="popin-slideshow"><div id="close"><a href="#">'+close+'</a></div>' + message + '</div>').appendTo('body');
    jQuery("#cache2").animate({ opacity: 0.4 });
    jQuery('#cache2').fadeIn();
    simplePopin();
    return false;
};

function popupPicture2(value) {
    var message,close = "";
    if (typeof (value) == "string") message = value;
    else { message = value.html; close = value.close || "" }
    jQuery('<div id="cache2"></div> <div id="popin" style="display: block;opacity:0.01;filter:alpha(opacity = 1);" tabindex="-1"><div class="popin-img" id="pop-content"><div class="inside">' + message + '</div><ul id="close"><li><a href="#">' + close + '</a></li></ul></div></div>').appendTo('body');
    jQuery("#cache2").animate({ opacity: 0.4 });
    jQuery('#cache2').fadeIn();
    jQuery("#popin").animate({ opacity: 1 });
    simplePopin();
    return false;
};

simplePopin = function () {

    jQuery('#cache2, #close').click(function () {
        closeAll();
        return false;
    })

    function closeAll() {
        jQuery('#cache2,#cache,#popin-slideshow,#popin').fadeOut();
        setTimeout(function () { jQuery('#cache2, #popin-slideshow,#popin').remove() }, 2000)

    }

}


/*  =DATEPICKER
----------------------------------------------------------------------------- */

datepicker = function () {
    datepickerCalculateNights.init();

    jQuery('.datepicker').datepicker({
        onSelect: function (dateText, inst) {
            datepickerCalculateNights.calculate();
        },
        beforeShow: function (input, inst) {
            //inst('setDate', input.value);
            var minDate;
            if (input.id == 'qb-arrival')
                minDate = new Date();
            else
                minDate = jQuery('#qb-arrival').datepicker('getDate');
            return {
                minDate: minDate,
                defaultDate : input.value
            }
        },
        showOn: "button",
        buttonImage: "/css/img/skin/picto-calendar.png",
        buttonText: "",
        buttonImageOnly: true,
        gotoCurrent:true
    });
    var d = new Date();
    var natDays = [[4, 8, 2011], [4, 9, 2011]];
    function nationalDays(date) {
        var m = date.getMonth();
        var d = date.getDate();
        var y = date.getFullYear();
        for (i = 0; i < natDays.length; i++) {
            if ((m == natDays[i][0] - 1) && (d == natDays[i][1]) && (y == natDays[i][2])) {
                return [false, "specialDate"];
            }
        }
        return [true];
    }
}

var datepickerCalculateNights = {
    data: {
        date: null,
        date2: null
    },
    init: function () {
        if (jQuery('#qb-arrival').length && jQuery('#qb-departure').length) {
            this.data.date = jQuery('#qb-arrival').val();
            this.data.date2 = jQuery('#qb-departure').val();
        }

        jQuery('#qb-arrival, #qb-departure').bind('blur', function () {
            datepickerCalculateNights.calculate();
        });
    },
    calculate: function () {
        if (jQuery('#qb-arrival').length && jQuery('#qb-departure').length) {
            var startVal = jQuery('#qb-arrival').val();
            var start = startVal.split('/');
            var endVal = jQuery('#qb-departure').val();
            var end = endVal.split('/');
            var timestampOneDay = 86400000;
            var action, formatDate, dateStart, dateEnd = null;

            if (parseInt(startVal) > -1) {
                // Silence
            } else {
                return false;
            }

            if (startVal != this.data.date) {
                action = 'start';
            }

            if (endVal != this.data.date2) {
                action = 'end';
            }

            switch (action) {
                case 'start':
                default:
                    dateStart = jQuery.datepicker.parseDate(jQuery.datepicker._defaults.dateFormat, document.getElementById("qb-arrival").value);
                    var finalDateStart = new Date((dateStart.getTime() + timestampOneDay));
                    formatDate = this.formatDate(finalDateStart.getDate()) + '/' + this.formatDate((finalDateStart.getMonth() + 1)) + '/' + finalDateStart.getFullYear();
                    jQuery('#qb-departure').val(formatDate);
                    break;
                case 'end':
                    /*dateEnd = new Date(end[2], (end[1])-1, end[0]).getTime();
                    dateStart = new Date(start[2], (start[1])-1, start[0]).getTime();*/
                    break;
            }

            this.data.date = jQuery('#qb-arrival').val();
            this.data.date2 = jQuery('#qb-departure').val();
        }
    },
    formatDate: function (num) {
        if (num < 10) {
            num = '0' + num;
        }

        return num;
    }
};

/*  =MAP
----------------------------------------------------------------------------- */

map = function () {
    jQuery('.list-map a').hover(function () { var aClass = jQuery(this).attr('class'); jQuery('#block-map-01 #' + aClass).show(); }, function () { var aClass = jQuery(this).attr('class'); jQuery('#block-map-01 #' + aClass).hide(); });
    jQuery('#block-map-01 .dot').hover(function () { var spanId = jQuery(this).attr('id'); var theID = spanId.replace('dot-', ''); jQuery('#block-map-01 #' + theID).show(); });
    jQuery('#block-map-01 .cities a').mouseout(function () { jQuery(this).hide(); });
}


/*  =SELECTS
----------------------------------------------------------------------------- */

selectsBehaviors = function () {
    jQuery("input.text").click(function () { if (jQuery(this).val() == jQuery(this).attr('defaultValue').replace("\n", "")) jQuery(this).val(""); })
	.blur(function () {if (jQuery(this).val() == "") jQuery(this).val(jQuery(this).attr('defaultValue'));});
    jQuery('select#activites, select#lang, select#reservationsList').selectmenu({ style: 'dropdown' });
}

showHotels = function () {jQuery('.block-results').hide();}
//modif CiiS
function ShowConcierge(value) {
    if (value != '0') {jQuery('.block-results').hide();jQuery('#' + value).show();}else {jQuery('.block-results').hide();}}
    goDestination = function () {
        jQuery('.other-countries').change(function () {

            var theVal = jQuery(this).val();
            if (theVal != 0) {
                var thePosition = jQuery('#' + theVal).offset();
                window.scrollTo(thePosition.left, thePosition.top);
                jQuery(this).val(0);
            }
        })
    }

ChangeMapDisplay = function () {
    jQuery('.map').click(function () {
        if (document.getElementById('destination-map'))
            document.getElementById('destination-map').style.display = 'block';
        if (document.getElementById('destination-liste'))
            document.getElementById('destination-liste').style.display = 'none';
        jQuery('#li-map').addClass("on");
        jQuery('#li-list').removeClass("on");
    });
    jQuery('.list').click(function () {
        if (document.getElementById('destination-map'))
            document.getElementById('destination-map').style.display = 'none';
        if (document.getElementById('destination-liste'))
            document.getElementById('destination-liste').style.display = 'block';
        jQuery('#li-map').removeClass("on");
        jQuery('#li-list').addClass("on");
    });
}

/* =POPIN
------------------------------------------------------------------------------*/
var popinMemorize = {
    activeLink: null
};
function popin(config) {
    var targetLink = config.target;
    var id_popin = config.name.popin;
    var id_cache = config.name.cache;
    var id_close = config.name.close;
    var id_content = config.name.content;
    var marginMax = config.style.marginMax || 50;          // popin margin
    var marginIE6 = config.style.marginIE6 || 50;          // IE 6 fix
    var opacity = config.style.opacity;
    var maxWidth = config.style.maxWidth;
    var maxHeight = config.style.maxHeight;
    var pop_hash = config.behaviours.hash || 'pop';
    var closeStr = config.behaviours.close;
    var innerLoad = config.behaviours.innerLoad || true;
    var anim = config.behaviours.anim || true;
    var resize = config.behaviours.resize || false;     // EXPERIMENTAL / 
    var anchor = config.behaviours.anchor || false;     // EXPERIMENTAL / handling location hash
    var closeClick = config.behaviours.closeClick || false;
    // var loadImage  = new Image();
    // if (config.behaviours.loadingImage) {
    //     loadImage.src = config.behaviours.loadingImage.src || null;
    //     loadImage.alt = config.behaviours.loadingImage.alt || null;
    //     loadImage.id  = config.name.loadimg || null;
    // }
    if (config.callback) {
        var callOnunload = config.callback.onunload || null;
        var callOnload = config.callback.onload || null;
        var callReload = config.callback.onreload || null;
        var callOnBeforeLoad = config.callback.onbeforeload || null;
    }

    var popin = null;
    var popinCache = null;
    var body = jQuery('body');

    var url, parametres, paramets, params, iparam = null; // ugly!!!

    var globs = {
        callerElm: null,
        popinLoaded: 0
    };

    var utils = {
        getWindowDimensions: function (dimension) {
            var dimension = dimension.substr(0, 1).toUpperCase() + dimension.substr(1);
            var result = 0;
            if (typeof (w['inner' + dimension]) == "number") {
                // Standard Browsers
                var result = w['inner' + dimension];
            }
            else if (d.documentElement && d.documentElement['client' + dimension]) {
                // IE 6+ in standard mode
                var result = d.documentElement['client' + dimension];
            }
            return result;
        },
        fixDimensions: function (dimension, direction) {
            if (utils.getWindowDimensions(dimension) < popin[dimension]()) {
                popin.css(dimension, (utils.getWindowDimensions(dimension) - marginMax) + "px");
                popin.css("margin-" + direction, "-" + Math.round((utils.getWindowDimensions(dimension) - marginMax) / 2) + "px");
            }
        },
        getScrollPositions: function (axis) {
            var axis = axis.toUpperCase();
            var axis2 = (axis == 'Y') ? 'Top' : 'Left';
            var result = 0;
            if (typeof w['page' + axis + 'Offset'] == "number") {
                result = w['page' + axis + 'Offset'];
            }
            else if (d.body && d.body['scroll' + axis2]) {
                result = d.body['scroll' + axis2];
            }
            else if (d.documentElement && d.documentElement['scroll' + axis2]) {
                result = d.documentElement['scroll' + axis2];
            }
            return result;
        },
        setLinks: function (elm, inner) {
            // update this to a resolution check, rather than to a window size check ?
            if (!((utils.getWindowDimensions('width') < maxWidth)
            || (utils.getWindowDimensions('height') < maxHeight))) {
                if (!popin && typeof callOnBeforeLoad == 'function') {
                    callOnBeforeLoad();
                }
                var options = {
                    inner: inner
                };
                openPopin(jQuery(elm), options);
            }
        }
    };

    function openPopin(elm, options) {
        var focusElm = null;  // a DOM element where the focus is applied on close
        var inner = false; // if true permits inner reloads
        if (options) {
            if (options.focusElm) {
                focusElm = options.focusElm;
            }
            if (options.inner) {
                inner = true;
            }
        }

        url = null;

        var setUrl = function () {
            if (typeof elm == 'string') {
                popinMemorize.activeLink = jQuery(focusElm) || body;
                url = elm;
            }
            else if (typeof elm == 'object') {
                if (elm[0] && elm[0].action) { // if elm is in DOM and has action
                    if (!document.getElementById(id_popin)) {
                        popinMemorize.activeLink = elm;
                    }
                    url = elm.attr('action');
                    globs.callerElm = elm;
                }
                else if (elm[0] && elm[0].href) { // if elm is in DOM and has href
                    if (!document.getElementById(id_popin)) {
                        popinMemorize.activeLink = elm;
                    }
                    url = elm.attr('href');
                    globs.callerElm = elm;
                }
                else {
                    throw ('Popin : openPopin() Argument Type Error');
                    return;
                }
            }
            else {
                throw ('Popin : openPopin() Argument Type Error');
                return;
            }
        } ();

        // ugly!!!
        parametres = (url.slice(url.indexOf("?") + 1)).split("&");
        paramets = [];
        params = [];
        iparam = 0;

        var handleWindowLocation = function () {
            // ugly!!!
            for (var i = 0, n = parametres.length; i < n; i++) {
                paramets[iparam] = parametres[i].split("=")[0];
                iparam++;
                paramets[iparam] = parametres[i].split("=")[1];
                iparam++;
            }
            for (var i = 0, n = paramets.length; i < n; i++) {
                var chaine = paramets[i];
                i++;
                params[chaine] = paramets[i];
            }
        } ();

        var setBehaviours = function () {
            if (typeof inner != 'undefined' && inner == true) {
                var oContent = jQuery('#' + id_content);
                oContent.empty();
                // oContent.append(loadImage); // breaks focus on Jaws
                // oContent.show(); // breaks focus on Jaws
                return;
            }
            if (popin && popinCache) {
                closePopin(true);
            }
        } ();

        var buildHTML = function () {
            if (typeof inner != 'undefined' && inner == true) {
                return;
            }
            body.append('<div id="' + id_cache + '"></div><div id="' + id_popin + '"></div>');
            popinCache = jQuery('#' + id_cache);
            popin = jQuery("#" + id_popin);
            if (typeof callOnunload == 'function') {
                popin[0].setUnload = callOnunload;
            }
        } ();

        var setPreStyles = function () {
            if (typeof inner != 'undefined' && inner == true) {
                return;
            }
            popinCache.css("opacity", opacity);

            if (anim) {
                popinCache.fadeIn();
            }
            else {
                popinCache.show();
            }

            // IE 6 hacks
            if ((jQuery.browser.msie) && (jQuery.browser.version < 7)) {
                // hide selects
                jQuery('select').css('visibility', 'hidden');
                popin.find('select').css('visibility', 'visible');

                // position:fixed
                popinCache.css('height', (body.height() + marginIE6) + 'px');
                if (body.height() < utils.getWindowDimensions('height')) {
                    popinCache.css('height', utils.getWindowDimensions('height') + 'px');
                }
            }

        } ();

        var loadContent = function () {
            var eUrl = encodeURI(url);

            if (globs.callerElm && globs.callerElm.attr('action')) {
                var sentData = '';
                var getFormData = function () {
                    jQuery(elm).find('input, select, textarea').each(function () {
                        var current = jQuery(this);
                        var val = encodeURIComponent(current.val());
                        var name = current.attr('name');
                        sentData += name + "=" + val + "&";
                    });
                } ();
                jQuery.ajax({
                    type: 'POST',
                    url: eUrl,
                    data: sentData,
                    success: setPopin
                });
            }
            else {
                var param = (url.indexOf("?") != -1) ? '&' : '?';
                popin.load(eUrl + param + " #" + id_content, setPopin);
            }
        } ();

    } // end openPopin

    function setPopin() {
        var responseText = arguments[0];
        var textStatus = arguments[1];
        var XHR = arguments[2];
        var closeHTML = '<ul id="' + id_close + '"><li><a href="#">' + closeStr + '</a></li></ul>';
        var setDimensions = function () {
            if (globs.popinLoaded == 1) {
                popin.animate({
                    width: params["width"] + "px",
                    marginLeft: "-" + Math.round(((params["width"]) / 2)) + "px",
                    height: params["height"] + "px",
                    marginTop: "-" + Math.round(((params["height"]) / 2)) + "px"
                });
            }
            else {
                if (typeof params["width"] != 'undefined') {
                    popin.css("width", params["width"] + "px");
                    popin.css("margin-left", "-" + Math.round(((params["width"]) / 2)) + "px");
                }
                if (typeof params["height"] != 'undefined') {
                    popin.css("height", params["height"] + "px");
                    popin.css("margin-top", "-" + Math.round(((params["height"]) / 2)) + "px");
                }
            }
            utils.fixDimensions('width', 'left');
            utils.fixDimensions('height', 'top');
        } ();

        var verifyBehaviours = function () {
            if (resize) {
                jQuery(window).resize(function () {
                    utils.fixDimensions('width', 'left');
                    utils.fixDimensions('height', 'top');
                });
            }
            if (anchor) {
                var position_x = utils.getScrollPositions("x");
                var position_y = utils.getScrollPositions("y");
                w.location.hash = pop_hash + "=" + url;
                window.scrollTo(position_x, position_y);
            }

            if ((jQuery.browser.msie) && (jQuery.browser.version < 7)) {
                if (utils.getScrollPositions("y") != 0) {
                    popin.css("top", utils.getScrollPositions("y") + (utils.getWindowDimensions("height") / 2));
                }
            }
        } ();

        var handleVisitedLinks = function () {
            if (typeof inner != 'undefined' && inner == true) {
                return;
            }
            // only works on Firefox/Gecko
            popin.append('<iframe src="' + url + '" id="popin-iframe"></iframe>');
            popin.children("#popin-iframe").css("display", "none");
        } ();


        var handleEvents = function () {
            if (globs.callerElm && globs.callerElm.attr('action')) {
                var content = jQuery(responseText).find('#' + id_content);
                content.clone(true).appendTo(popin);
                popin.children('#' + id_content).append(closeHTML);
            }
            else {
                jQuery('#' + id_content).append(closeHTML);
            }

            jQuery('#' + id_close + ' a').bind('click', function () {
                closePopin();
                return false;
            });

            jQuery('#pop-content .btn-cancel').bind('click', function () {
                closePopin();
                return false;
            });

            body.bind('keyup', function (e) {
                if (e.keyCode == 27 && popin) {
                    closePopin();
                    jQuery(this).unbind('keyup');
                }
            });

            if (closeClick) {
                popinCache.bind('click', function () {
                    closePopin();
                    return false;
                });
            }

            if (innerLoad) {
                jQuery(popin).find(targetLink).not('form').click(function () {
                    utils.setLinks(this, true);
                    return false;
                });
                jQuery(popin).find('form' + targetLink).submit(function () {
                    utils.setLinks(this, true);
                    return false;
                });
            }

            if (globs.popinLoaded > 0 && typeof callReload == "function") {
                callReload();
            }
            else if (typeof callOnload == "function") {
                callOnload();
            }

        } ();

        var handleStatus = function () {
            if (typeof inner != 'undefined' && inner == true) {
                return;
            }
            if (textStatus != 'success') {
                popin.append('<div id="' + id_content + '">' +
                                '<p>Message : ' + textStatus + '</p>' +
                                '<p>ReadyState : ' + XHR.readyState + '</p>' +
                                '<p>Status : ' + XHR.status + '</p>' +
                             '</div>' + closeHTML);
                jQuery('#' + id_close + ' a').bind('click', function () {
                    closePopin();
                    return false;
                });
            }
            popin.show();
            popin.attr("tabindex", "-1");
            popin.focus();

            globs.popinLoaded = 1;
        } ();
    } // end setPopin

    function closePopin(onload, options) {
        // we need this if we use the external interface
        popinCache = popinCache || jQuery('#' + id_cache);
        popin = popin || jQuery('#' + id_popin);
        var tmpPopin = document.getElementById(id_popin);

        globs.popinLoaded = 0;

        var handleEvents = function () {
            if (!onload && typeof tmpPopin.setUnload == 'function') {
                tmpPopin.setUnload();
                tmpPopin.setUnload = null;
                delete tmpPopin;
            }
            if (anchor) {
                var position_x = utils.getScrollPositions('x');
                var position_y = utils.getScrollPositions('y');
                w.location.hash = '#';
                w.scrollTo(position_x, position_y);
            }
        } ();

        var setFocusBack = function () {
            if (options) {
                if (options.focusElm) {
                    popinMemorize.activeLink = jQuery(options.focusElm);
                }
            }

            if (!onload && popinMemorize.activeLink) {
                popinMemorize.activeLink.attr('tabindex', '-1');
                popinMemorize.activeLink.focus();
                popinMemorize.activeLink.removeAttr('tabindex');
                popinMemorize.activeLink = null;
            }
        } ();

        var removePopin = function () {
            if (anim) {
                var tmpCache = popinCache;
                popinCache.fadeOut(function () {
                    tmpCache.remove();
                    delete tmpCache;
                });
            }
            else {
                popinCache.remove();
            }
            popin.remove();
        } ();

        var resetVars = function () {
            popin = null;
            popinCache = null;

            url, parametres, paramets, params, iparam = null; // ugly!!!

            globs.callerElm = null;
        } ();

        if (jQuery.browser.msie && jQuery.browser.version < 7) {
            jQuery('select').css('visibility', 'visible');
        }
    } // end closePopin

    var init = function () {
        if (anchor && w.location.hash
        && (w.location.hash.indexOf(pop_hash + "=") != -1)) {
            var wHash = w.location.hash;
            var options = {};
            openPopin(wHash.slice(wHash.indexOf(pop_hash + "=") + pop_hash.length + 1), options);
        }

        if (targetLink) { // if null just works on external calls
            jQuery(targetLink).not('form').click(function () {
                utils.setLinks(this, false);
                return false;
            });
            jQuery('form' + targetLink).submit(function () {
                utils.setLinks(this, false);
                return false;
            });
        }
    } ();

    return {
        openPopin: function (url, focusElm) {
            var options = {
                focusElm: focusElm
            };
            openPopin(url, options);
            return false;
        },
        closePopin: function (focusElm) {
            var options = {
                focusElm: focusElm
            };
            closePopin(null, options);
            return false;
        }
    };

}


/* =TABS
------------------------------------------------------------------------------*/

fnTabs = function () {
    jQuery('.sub-tabs').tabs().tabs('rotate', 8000);
    jQuery('#block-stay').tabs().tabs();
}

newTabs = function () {
    jQuery('.view .item').hide();
    jQuery('.view div:first-child').show();
    jQuery('.thumbnail li a').click(function () {
        jQuery('.view .item').hide();
        var theItem = jQuery(this).attr('href');
        jQuery(theItem).show();
        return false;
    })
}


function carouselThumbnailClick(id) {
    jQuery('.view .item').hide();
    jQuery(id).show();
    return false;
}


/*  =TOOLTIP
----------------------------------------------------------------------------- */

fnTooltip = function () {
    jQuery('.services span').simpletooltip();
}

jQuery.fn.simpletooltip = function () {
    return this.each(function () {
        var theClass = jQuery(this).attr("class");
        if (theClass == "service") return;
        var text = jQuery(this).html();
        //jQuery(this).attr("title", "");
        if (text != undefined) {
            jQuery(this).hover(function (e) {
                var tipX = e.pageX + 12;
                var tipY = e.pageY + 12;
                jQuery(this).attr("title", "");
                jQuery("body").append("<div class='tooltip " + theClass + "' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
                var toolTip = jQuery(".tooltip");
                if (jQuery.browser.msie) var tipWidth = toolTip.outerWidth(true);
                else var tipWidth = toolTip.width();
                toolTip.width(tipWidth);
                toolTip.css({ "left": tipX, "top": tipY }).fadeIn("medium");
            }, function () {
                jQuery(".tooltip").remove();
                jQuery(this).attr("title", text);
            });
            jQuery(this).mousemove(function (e) {
                var tipX = e.pageX + 12;
                var tipY = e.pageY + 12;
                var toolTip = jQuery(".tooltip");
                var tipWidth = toolTip.outerWidth(true);
                var tipHeight = toolTip.outerHeight(true);
                if (tipX + tipWidth > jQuery(window).scrollLeft() + jQuery(window).width()) tipX = e.pageX - tipWidth;
                if (jQuery(window).height() + jQuery(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
                toolTip.css({ "left": tipX, "top": tipY }).fadeIn("medium");
            });
        }
    });
}



/*  =MENU
----------------------------------------------------------------------------- */

fnMenu = function () {
    jQuery("#menu li,#hotelMenu .li").hover(function () {
        if (jQuery('#hotelMenu .li.current').length = 1) {
            jQuery('#hotelMenu .li.current').removeClass("hover");
            jQuery('#hotelMenu .li.current .dropdown').css('visibility', 'hidden');
        }

        jQuery(this).addClass("hover");
        if (typeof (addthis_close) != "undefined") try { addthis_close(); } catch (ex) { }
        if (typeof (_atw) != "undefined" && typeof (_atw.clb) != "undefined") try { _atw.clb(); } catch (ex) { }
        jQuery('div:first', this).css('visibility', 'visible');
    },
    function () {

        jQuery(this).removeClass("hover");
        jQuery('div:first', this).css('visibility', 'hidden');

        if (jQuery('#hotelMenu .li.current').length = 1) {
            jQuery('#hotelMenu .li.current').addClass("hover");
            jQuery('#hotelMenu .li.current .dropdown').css('visibility', 'visible');
        }
    });

    if (jQuery('#hotelMenu .li.current').length = 1) {
        jQuery('#hotelMenu .li.current').addClass("hover");
        jQuery('#hotelMenu .li.current .dropdown').css('visibility', 'visible');
    }
}

flags = function () {
    jQuery('.block-map-02 .flag .middle').click(function () {
        jQuery('.preview').hide();
        jQuery('.flag').removeClass('active');
        jQuery(this).parent().find('.preview').show();
        jQuery(this).parent().addClass('active');
        return false;
    })

    jQuery('.block-map-02 .flag .preview .btn-close').click(function () {
        jQuery(this).parent().parent().hide();
        jQuery(this).parent().parent().parent().removeClass('active');
        return false;
    })
}


/*  =COMPARE
----------------------------------------------------------------------------- */

/* MODIF CiiS
-------------Original version-------------
fnCompare = function(){
jQuery('#block-compare-01').hide();
jQuery('.compare a').click(function(){
jQuery('#block-compare-01').show();
})
} 
*/

function HotelComparatorDisplay(divId) {
    if (jQuery('#' + divId).length != 0) {
        if (jQuery('#' + divId).is(":visible")) {
            jQuery('#' + divId).hide();
        }
        else {
            jQuery('#' + divId).show();
        }
    }
}
showHide = function () {
    if (jQuery(".block-show").length) {
        jQuery(".title-fieldset").click(function () {
            if (jQuery(this).next("div").hasClass("block-show") == true) {
                jQuery(this).removeClass("title-show");
                jQuery(this).addClass("title-hide");
                jQuery(this).next("div").removeClass("block-show");
                jQuery(this).next("div").addClass("block-hide");
            } else {
                jQuery(this).removeClass("title-hide");
                jQuery(this).addClass("title-show");
                jQuery(this).next("div").removeClass("block-hide");
                jQuery(this).next("div").addClass("block-show");
            }
        });
    }
}



/*  =SLIDES
----------------------------------------------------------------------------- */

fnSlides = function () {
    jQuery('#block-slide ul').cycle({pager: '#block-slide .pager'});
}



/*  =DIAPORAMA HUB
----------------------------------------------------------------------------- */
var id_li = 0;
interrupteur = false;
vDiapoHotelStop = false;

diapoHubIn = function () {
    blockPicture = jQuery(".hub-block-01 li.picture");
    blockMenu = jQuery(".hub-block-01-inner .menu li");

    if (jQuery(".hub-block-01").length) {
        blockMenu.removeClass('on');
        blockMenu.eq(id_li).addClass('on');
        blockPicture.eq(id_li).fadeIn(1000, function () {
            interrupteur = true;
            if (vDiapoHotelStop == false) {
                timer01 = setTimeout("diapoHubOut()", 3000);
            } else {
                window.clearTimeout(timer01);
            }
        });
    }
}
diapoHubOut = function () {
    window.clearTimeout(timer01);
    blockPicture.eq(id_li).fadeOut(1000, function () {
        if (id_li < 5) {
            id_li++;
        } else {
            id_li = 0;
        }
        diapoHubIn();
    });
}
diapoInteract = function () {
    if (jQuery(".hub-block-01-inner .menu li").length) {
        jQuery('#block-reservation').click(function () {
            vDiapoHotelStop = true;
            diapoHubIn();
        });
        jQuery(".hub-block-01-inner .menu li a").click(function () {
            vDiapoHotelStop = false;
            window.clearTimeout(timer01);
            blockPicture.eq(id_li).stop();
            blockPicture.eq(id_li).hide();
            num = jQuery(this).attr('class');
            if (num == "elt-00") { id_li = 0; vDiapoHotelStop = true; }
            if (num == "elt-01") { id_li = 1; }
            if (num == "elt-02") { id_li = 2; }
            if (num == "elt-03") { id_li = 3; }
            if (num == "elt-04") { id_li = 4; }
            if (num == "elt-05") { id_li = 5; }
            diapoHubIn();
            return false;
        });
    }
}
diapoStop = function () {
    if (jQuery(".hub-block-01-inner .menu li").length) {
        jQuery('.zone-picture, .ui-datepicker').hover(
			function () {
			    window.clearTimeout(timer01);
			    blockPicture.eq(id_li).stop();
			    blockPicture.eq(id_li).css('opacity', 1);
			    blockMenu.removeClass('on');
			    blockMenu.eq(id_li).addClass('on');
			},
			function () {
			    if (vDiapoHotelStop == true) {
			    } else {
			        diapoHubIn()
			    }
			}
		);
        jQuery('.zone-picture, .ui-datepicker').mousemove(function () {
            blockPicture.eq(id_li).stop();
            blockPicture.eq(id_li).css('opacity', 1);
            blockMenu.removeClass('on');
            blockMenu.eq(id_li).addClass('on');
        });
    }
}
diapoHotelStop = function () {
    jQuery('#form-02 input.submit').click(function () {
        vDiapoHotelStop = true;
        window.clearTimeout(timer01);
        blockPicture.eq(0).stop();
    });
}


/* NEW CiiS
-----------------------------------------------------------------------------*/
//Stockage du nombre d'offres déjà afficher 
var countOfferToShow = 0;

//fonction appeler lors d'un changement de filtre. 
//tag représente la classe à afficher
//i le nombre d'offre à afficher en plus de celles qui le sont déjà
function OfferTagFilter(tag, i) {
    //on change de tag => réinitialisation du countOfferToShow
    countOfferToShow = 0;
    if (tag != null) {
        if (jQuery('.tag-filter').length != 0) {
            //on masque automatiquement toutes les offres
            jQuery('.tag-filter').hide();
        }
        if (jQuery('.tag-SeeMore').length != 0) {
            //ainsi que tous les "see more"
            jQuery('.tag-SeeMore').hide();
        }
        if (tag != 'all') {
            //un tag précis à été sélectionné
            if (jQuery('#tag-SeeMore-' + tag).length != 0) {
                //affichage du see more corespondant
                jQuery('#tag-SeeMore-' + tag).show();
            }
            if (jQuery('.tag-' + tag).length != 0) {
                //appel de la fonction pour afficher les offres avec le tag sélectionné
                ShowNextOffer(tag, i, false);
            }
        }
        else {
            if (jQuery('#tag-SeeMore').length != 0) {
                //affichage du "see more" corespondant
                jQuery('#tag-SeeMore').show();
            }
            //affichage de toutes les offres
            if (jQuery('.tag-filter').length != 0) {
                //appel de la fonction pour toutes les offres
                ShowNextOffer('filter', i, false);
            }
        }

        if (jQuery('.on').length != 0) {
            //Supression de la classe qui surligne le tag sélectionné
            jQuery('.on').removeClass("on");
        }
        if (jQuery('#tag-' + tag).length != 0) {
            // Ajout de la classe pour le tag sélectionné
            jQuery('#tag-' + tag).addClass("on");

        }
    }
    //la variable countOfferToShow récupère le nombre d'offres déjà selectionné
    countOfferToShow = i;
};



//affichage du bon nombre d'offre lors d'un changement de tag ou d'un click sur un "see more"
//tag => class a afficher
//i => nombre d'élément à afficher en plus de ceux qui le sont déjà (countOfferToShow)
function ShowNextOffer(tag, i, seeMore) {

    var divOfferTag = ".tag-" + tag;
    var divSeeMoreTag = ".tag-SeeMore";    
    
    countOfferToShow = countOfferToShow + i;
    if (seeMore) {
        testShow(divOfferTag, 0, countOfferToShow);
    }
    else {
        for (var cpt = 0; cpt < countOfferToShow; cpt++) {
            jQuery(divOfferTag).eq(cpt).show();
        }
    }
    if (jQuery(divOfferTag).eq(countOfferToShow).length == 0) {
        //étant en fin de page (il n'y a plus d'offre à afficher) on peut masquer le bouton correspondant
        jQuery(divSeeMoreTag).hide();
    }
};

function testShow(tag, cpt, countOfferToShow) {
    if (cpt < countOfferToShow) {
        jQuery(tag).eq(cpt).slideDown("normal", function () { testShow(tag, cpt + 1, countOfferToShow) });
    }
};



/*  =ADDTHISCONFIG
----------------------------------------------------------------------------- */

var addthis_config = {
    ui_offset_left: -195
};

/*  =BIGIFRAME
----------------------------------------------------------------------------- */

frameIt = function () {
    jQuery('#menu .dropdown, .popin-type-02, .popin-type-01').bgiframe();
};


/*  =PRINTIT
----------------------------------------------------------------------------- */

printIt = function () {
    jQuery('.print').click(function () {
        window.print();
        return false;
    })
}


/*minisites*/
/* =TABS2
------------------------------------------------------------------------------*/

majx.tabs = function (config) {
    var elements = null;
    var active = config.active;
    var linkParent = config.linkParent;
    var scroll = config.scrollToTop;
    var id = jQuery(config.id);
    var zones = id.find(config.zones);
    var menu = id.find(config.menu);
    var container = id.find(config.container);
    function launch() {
        var setStyles = function () {
            var containerHeight = container.css("height");
            var focus = jQuery("." + config.focus).length;
            zones.css('height', containerHeight);
            zones.css('overflow', 'auto');
            container.css('overflow', 'hidden');
            zones.hide();
            if (!focus) {
                id.addClass(config.focus);
            }
        } ();
        var handleBehaviours = function () {
            var idExists = id.find(window.location.hash);
            var isActive = menu.find('.' + active);
            var zoneActive = jQuery(isActive.find('a').attr('href'));
            if (window.location.hash && idExists.length) {
                menu.find(linkParent).removeClass(active);
                idExists.show();
                idExists.attr("tabindex", "-1");
                idExists.focus();
                idExists.removeAttr("tabindex");
                jQuery('a[href=' + window.location.hash + ']').parents(linkParent).addClass(active);
                if (scroll) {
                    window.scrollTo(0, 0);
                }
            }
            else if (isActive.length) {
                zoneActive.show();
            }
            else {
                zones.eq(0).show();
                menu.find(linkParent).eq(0).addClass(active);
            }
        } ();
        var handleEvents = function () {
            var tabs = menu.find(linkParent).find('a');
            tabs.click(function () {
                jQuery("." + config.focus).removeClass(config.focus);
                id.addClass(config.focus);
                var zoneActive = jQuery(jQuery(this).attr("href"));
                menu.find(linkParent).removeClass(active);
                jQuery(this).parents(linkParent).addClass(active);
                zones.hide();
                zoneActive.show();
                zoneActive.attr("tabindex", "-1");
                //zoneActive.focus();
                zoneActive.removeAttr("tabindex");
                return false;
            });
            tabs.focus(function (e) {
                jQuery("." + config.focus).removeClass(config.focus);
                id.addClass(config.focus);
            });
        } ();

        var handleKeyboard = function () {
            jQuery(document).keyup(function (e) {
                var isActive = jQuery(config.id + '.' + config.focus).find(config.menu).find('.' + active);
                if (isActive.length) {
                    var zoneActive = jQuery(isActive.find('a').attr('href'));
                    if (e.keyCode == 39 || e.keyCode == 37) {
                        var position = null;
                        var afterZone = null;
                        var action = function (position, move) {
                            if (isActive[move]().length) {
                                afterZone = jQuery(isActive[move]().children("a").attr("href"));
                                isActive[move]().addClass(active);
                            }
                            else {
                                afterZone = zones.eq(position);
                                menu.children(linkParent).eq(position).addClass(active);
                            }
                        };
                        zones.hide();
                        switch (e.keyCode) {
                            case 39: // right arrow
                                var position = 0;
                                action(position, "next")
                                break;
                            case 37: //  left arrow 
                                var position = zones.length - 1;
                                action(position, "prev")
                                break;
                        }
                        isActive.removeClass(active);
                        afterZone.show();
                        afterZone.attr("tabindex", "-1");
                        afterZone.focus();
                        afterZone.removeAttr("tabindex");
                    }
                }
            });
        } ();
    }


    var init = function () {
        function verifyHTMLStruct() {
            var error = false;
            var message = '\n## Error(s) on `' + config.id + '`\n\n';
            if (zones.length != menu.find('a').length) {
                if (error == false && config.debug == true) {
                    log(message);
                }
                error = true;
                if (config.debug == true) {
                    log(' - `' + config.id + '` ne comporte pas autant d\'onglets que de zones ; ');
                }
            }
            if (menu.find('.' + active).length > 1) {
                if (error == false && config.debug == true) {
                    log(message);
                }
                error = true;
                if (config.debug == true) {
                    log(' - `' + config.id + '` has more than one active tab ; ');
                }
            }
            for (var i = 0; i < zones.length; i++) {
                if (jQuery((menu.find('a').eq(i).attr("href"))).length != 1) {
                    if (error == false && config.debug == true) {
                        log(message);
                    }
                    error = true;
                    if (config.debug == true) {
                        log(' - `' + config.id + '` n\'associe pas correctement les onglets et les zones ; ');
                    }
                }
            }
            if (error) {
                menu.find(linkParent).removeClass(active);
                if (config.debug == true) {
                    log('\nPlease fix HTML and/or JS on `' + config.id + '`.');
                }
                return (false);
            }
            else {
                return (true);
            }
        }
        if (verifyHTMLStruct()) {
            launch();
        }
    } ();
};

function ChangeBarRestaurantDisplay(tabId) {
    if (document.getElementById('tab-bar'))
        document.getElementById('tab-bar').style.display = 'none';
    if (document.getElementById('tab-restaurant'))
        document.getElementById('tab-restaurant').style.display = 'none';
    jQuery('#li-bar').removeClass("on");
    jQuery('#li-restaurant').removeClass("on");
    if (document.getElementById('tab-' + tabId))
        document.getElementById('tab-' + tabId).style.display = 'block';
    jQuery('#li-'+tabId).addClass("on");
};

