(function($) {
    $.fn.hoverIntent = function(f, g) {
        var cfg = {
            sensitivity: 7,
            interval: 100,
            timeout: 0
        };
        cfg = $.extend(cfg, g ? {
            over: f,
            out: g
        }: f);
        var cX,
        cY,
        pX,
        pY;
        var track = function(ev) {
            cX = ev.pageX;
            cY = ev.pageY;
        };
        var compare = function(ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) {
                $(ob).unbind("mousemove", track);
                ob.hoverIntent_s = 1;
                return cfg.over.apply(ob, [ev]);
            } else {
                pX = cX;
                pY = cY;
                ob.hoverIntent_t = setTimeout(function() {
                    compare(ev, ob);
                },
                cfg.interval);
            }
        };
        var delay = function(ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            ob.hoverIntent_s = 0;
            return cfg.out.apply(ob, [ev]);
        };
        var handleHover = function(e) {
            var p = (e.type == "mouseover" ? e.fromElement: e.toElement) || e.relatedTarget;
            while (p && p != this) {
                try {
                    p = p.parentNode;
                } catch(e) {
                    p = this;
                }
            }
            if (p == this) {
                return false;
            }
            var ev = jQuery.extend({},
            e);
            var ob = this;
            if (ob.hoverIntent_t) {
                ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            }
            if (e.type == "mouseover") {
                pX = ev.pageX;
                pY = ev.pageY;
                $(ob).bind("mousemove", track);
                if (ob.hoverIntent_s != 1) {
                    ob.hoverIntent_t = setTimeout(function() {
                        compare(ev, ob);
                    },
                    cfg.interval);
                }
            } else {
                $(ob).unbind("mousemove", track);
                if (ob.hoverIntent_s == 1) {
                    ob.hoverIntent_t = setTimeout(function() {
                        delay(ev, ob);
                    },
                    cfg.timeout);
                }
            }
        };
        return this.mouseover(handleHover).mouseout(handleHover);
    };
})(jQuery);
$.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        $("<img>").attr("src", arguments[i])
    }
};
function addBoxDressing() {
    if ($.browser.msie && $.browser.version == "6.0") {} else {
        $("div.signaturebox").prepend('<div class="box-bottomline"></div><div class="box-topleft"></div><div class="box-topline"></div><div class="box-leftline"></div><div class="box-rightline"></div><div class="box-topright"></div><div class="box-bottomleft"></div><div class="box-bottomright"></div>')
    }
}
function enableMenuSliders() {
    $("ul.nav>li").hoverIntent(function() {
        $(this).find("ul").stop(false, true).slideDown('fast').show()
    },
    function() {
        $(this).find("ul").stop(false, true).slideUp('slow')
    })
}
function hoverImgAnimation() {
    $("div.hover img").css("opacity", "0.75");
    $("div.hover").hover(function() {
        $(this).find("img").animate({
            opacity: "1.0"
        },
        500)
    },
    function() {
        $(this).find("img").animate({
            opacity: "0.75"
        },
        200)
    })
}
$(document).ready(function($) {
    addBoxDressing();
    enableMenuSliders();
    hoverImgAnimation()
});
function enableShopSlideShow() {
    $("#shop-slideshow").before('<div id="prevArrow"></div><div id="nextArrow"></div>').cycle({
        next: "#nextArrow",
        prev: "#prevArrow",
        pause: 0,
        timeout: 2400,
        speed: 800,
        delay: 0,
        autostop: 1
    }).css('cursor', 'pointer').click(function() {
        enableShopSlideShow()
    })
}
function enableRoomsSuitesBrowser() {
    $("div.guest-room-menu ul li").click(function() {
        $("div.guest-room-menu ul li").removeClass("active");
        $(this).addClass("active");
        var a = $(this).attr('name');
        pageTracker._trackPageview("/hotel/rooms-suites/" + a);
        var b = roomsuiteContent[a].title;
        var c = roomsuiteContent[a].description;
        var d = roomsuiteContent[a].bedtype;
        var e = roomsuiteContent[a].size;
        var f = roomsuiteContent[a].view;
        var g = roomsuiteContent[a].floorplan;
        var h = "/images/hotel/roomssuites/" + roomsuiteContent[a].action;
        $("#room_title").html(b);
        $("#room_description").html(c);
        $("#room-floorplan-link").attr("href", g);
        $("span#bedtype").html(d);
        $("span#square_foot").html(e);
        $("span#view").html(f);
        $("img.room_action").attr("src", h);
        if (a == "signatureroom") {
            $("#room-floorplan-link").hide()
        } else {
            $("#room-floorplan-link").show()
        }
    })
}
function enableExclusivesNavigation() {
    $("span.exclusives-item").click(function() {
        $("span.exclusives-item").removeClass("active");
        $(this).addClass("active");
        var a = $(this).attr('name');
        pageTracker._trackPageview("/hotel/exclusives/" + a);
        var b = exclusivesContent[a].title;
        var c = exclusivesContent[a].description;
        var d = exclusivesContent[a].includes;
        var e = exclusivesContent[a].availability;
        var f = exclusivesContent[a].rates;
//        var g = "http://www.fairmont.com/EN_FA/Reservations/ReservationAvailability?hc=PLZ&pc=" + exclusivesContent[a].promocode;
        var h = "/images/hotel/exclusives/" + exclusivesContent[a].actionimg;
        $("#exclusive-title").html(b);
        $("#exclusive-description").html(c);
        $("#exclusive-includes").html(d);
        $("#exclusive-availability").html(e);
        $("#exclusive-rates").html(f);
//        $("#exclusive-promocode").attr("href", g);
        $("img.action-img").attr("src", h)
    });
    $("span.exclusives-item.activefirst").click()
}
function enablePiedATerreNavigation() {
    $("ul.piedaterre-menu li").click(function() {
        $("ul.piedaterre-menu li").removeClass("active");
        $(this).addClass("active");
        var a = $(this).attr('name');
        pageTracker._trackPageview("/hotel/pied-a-terre/" + a);
        var b = piedaterreContent[a].title;
        var c = "/images/hotel/pied-a-terre/" + piedaterreContent[a].titleimg;
        var d = piedaterreContent[a].description;
        var e = piedaterreContent[a].size;
        var f = "/images/hotel/pied-a-terre/" + piedaterreContent[a].action;
        var g = piedaterreContent[a].floorplan;
        $("#piedaterre-titleimg").attr('alt', b);
        $("#piedaterre-titleimg").attr('src', c);
        $("#description-text").html(d);
        $("#piedaterre-size").html(e);
        $("#piedaterre-img").attr("src", f);
        $("#piedaterre-floorplan-link").attr("href", g)
    });
    $("ul.piedaterre-menu li:first").click()
}
function enableNYCNavigation() {
    $("span.exclusives-item").click(function() {
        $("span.exclusives-item").removeClass("active");
        $(this).addClass("active");
        var a = $(this).attr('name');
        pageTracker._trackPageview("/hotel/new-york-city-destination-guide/" + a);
        var b = newyorkcity[a].title;
        var c = newyorkcity[a].description;
        var d = newyorkcity[a].location;
        $("#exclusive-title").html(b);
        $("#exclusive-description").html(c);
        $("#exclusive-includes").html(d)
    });
    $("span.exclusives-item:first").click()
}
function enableItinerariesNavigation() {
    $("span.exclusives-item").click(function() {
        $("span.exclusives-item").removeClass("active");
        $(this).addClass("active");
        var a = $(this).attr('name');
        pageTracker._trackPageview("/hotel/itineraries/" + a);
        var b = itineraries[a].title;
        var c = itineraries[a].description;
        $("#exclusive-title").html(b);
        $("#exclusive-description").html(c)
    });
    $("span.exclusives-item:first").click()
}
function armShopsDirectory() {
    $("div.scrollLeft").hover(function() {
        $(this).children("img").attr("src", "/images/arrow-left-on.gif")
    },
    function() {
        $(this).children("img").attr("src", "/images/arrow-left.gif")
    });
    $("div.scrollRight").hover(function() {
        $(this).children("img").attr("src", "/images/arrow-right-on.gif")
    },
    function() {
        $(this).children("img").attr("src", "/images/arrow-right.gif")
    });
    $("div.shopsIcons").scrollable({
        size: 6,
        items: '.items',
        clickable: 'true',
        easing: 'swing',
        nextPage: '.nextPage',
        prevPage: '.prevPage',
        speed: 800,
        keyboardSteps: 1,
        loop: true
    }).circular().navigator();
    $("div.items div").click(function changeImage() {
        var a = $(this).attr('name');
        pageTracker._trackPageview("/shops/directory/" + a);
        $("#shopsactionarea").fadeOut("slow",
        function() {
            $("#loadingindicator").empty().html('<img src="/images/loading.gif" />').fadeIn("fast");
            $("#shopsactionarea").load("/shops/directory/" + a,
            function() {
                $("#loadingindicator").empty();
                $("#shopsactionarea").fadeIn("slow")
            })
        })
    })
}
var plazaConf = {
    defaults: {
        autoPlay: false,
        autoBuffering: true,
        accelerated: true,
        scaling: "scale",
        onFinish: function() {
            this.getPlugin("play").hide()
        }
    },
    skins: {
        signature: {
            url: "/swf/flowplayer.controls-3.1.5.swf",
            backgroundColor: '#000000',
            buttonColor: '#A29060',
            durationColor: '#ffffff',
            buttonOverColor: '#A2977A',
            progressColor: '#A29060',
            bufferColor: '#A29060',
            timeBgColor: "#FFFFFF",
            timeColor: "#01DAFF",
            backgroundGradient: 'none',
            sliderGradient: 'none',
            progressGradient: 'medium',
            volumeSliderColor: '#000000',
            volumeSliderGradient: 'none',
            bufferGradient: 'none',
            sliderColor: '#A29060',
            opacity: 0.8,
            width: '100%',
            height: 20,
            bottom: 0,
            left: 0,
            borderRadius: '0px',
            autoHide: 'fullscreen',
            hideDelay: 1200,
            play: true,
            volume: false,
            mute: true,
            time: false,
            stop: false,
            playlist: false,
            fullscreen: true,
            scrubber: true,
            scrubberHeightRatio: 0.4,
            scrubberBarHeightRatio: 0.5,
            volumeSliderHeightRatio: 0.4,
            volumeBarHeightRatio: 1,
            timeBgHeightRatio: 0.7
        }
    },
    background: {
        black: {
            background: 'none',
            backgroundGradient: 'none'
        },
        profile: {
            background: '#000000',
            backgroundGradient: 'none'
        }
    }
};
function newsVideo(a, b) {
    var c = $("#" + a).html();
    flowplayer(a, "/swf/flowplayer.commercial-3.1.5.swf", {
        key: '#@8c331c6322e850abc8b',
        wmode: 'opaque',
        onFail: function() {
            document.getElementById(a).innerHTML = c
        },
        play: {
            opacity: 0
        },
        clip: {
            url: b,
            autoPlay: true,
            autoBuffering: true,
            accelerated: true,
            scaling: "scale",
            onFinish: function() {
                this.getPlugin("play").hide()
            },
            onBegin: function() {
                this.getPlugin("loading").show();
                flowplayer("*").each(function() {
                    this.pause()
                })
            },
            onCuepoint: function() {
                this.getPlugin("loading").show()
            },
            onBufferFull: function() {
                this.getPlugin("loading").hide()
            },
            onResume: function() {
                flowplayer("*").each(function() {
                    this.pause()
                })
            }
        },
        canvas: plazaConf.background.black,
        plugins: {
            controls: plazaConf.skins.signature,
            loading: {
                url: '/swf/loading.swf',
                top: 130,
                left: 289,
                width: 72,
                height: 110,
                display: 'none'
            }
        }
    })
}
function enableHomePageExperience() {
    var a = $("#signature").html();
    var b = 0;
    flowplayer("signature", {
        src: '/swf/flowplayer.commercial-3.1.5.swf',
        wmode: 'opaque',
        onFail: function() {
            document.getElementById("signature").innerHTML = a
        }
    },
    {
        key: '#@8c331c6322e850abc8b',
        clip: {
            baseUrl: '/video/',
            autoPlay: true,
            autoBuffering: true,
            accelerated: true,
            scaling: "fit"
        },
        canvas: {
            background: '#000000',
            backgroundGradient: 'none'
        },
        play: {
            opacity: 0
        },
        playlist: [{
            url: 'welcome.flv',
            onBegin: function() {
                this.getPlugin("loading").show()
            },
            onBufferFull: function() {
                this.getPlugin("loading").hide()
            }
        },
        {
            url: 'timelapse.flv',
            onFinish: function() {
                b++;
                if (b > 8) {
                    this.unload()
                } else {
                    this.play(0)
                }
            }
        }],
        plugins: {
            controls: {
                durationColor: '#ffffff',
                backgroundGradient: 'none',
                buttonOverColor: '#A2977A',
                progressColor: '#A29060',
                bufferColor: '#A29060',
                sliderGradient: 'none',
                volumeSliderColor: '#000000',
                progressGradient: 'medium',
                backgroundColor: '#000000',
                tooltipTextColor: '#ffffff',
                sliderColor: '#A29060',
                volumeSliderGradient: 'none',
                buttonColor: '#A29060',
                tooltipColor: '#5F747C',
                bufferGradient: 'none',
                borderRadius: '10px',
                height: 60,
                url: "/swf/flowplayer.controls-3.1.5.swf",
                top: 360,
                left: 880,
                opacity: 0.9,
                width: 70,
                autoHide: 'always',
                hideDelay: 2000,
                all: false,
                mute: true,
                tooltips: {
                    buttons: false,
                    fullscreen: 'Enter fullscreen mode'
                }
            },
            loading: {
                url: '/swf/loading.swf',
                top: 174,
                left: 455,
                width: 72,
                height: 110,
                display: 'none'
            }
        }
    })
}
function enableSignatureExperience(a, b) {
    var c = $("#signature").html();
    flowplayer("signature", {
        src: '/swf/flowplayer.commercial-3.1.5.swf',
        wmode: 'opaque',
        onFail: function() {
            document.getElementById("signature").innerHTML = c
        }
    },
    {
        key: '#@8c331c6322e850abc8b',
        clip: {
            url: a,
            autoPlay: true,
            autoBuffering: true,
            accelerated: true,
            scaling: "scale",
            onResume: function() {
                flowplayer("*").each(function() {
                    this.pause()
                })
            },
            onBegin: function() {
                this.getPlugin("loading").show()
            },
            onBufferFull: function() {
                this.getPlugin("loading").hide()
            },
            onFinish: function() {
                this.getPlugin("play").hide();
                this.unload()
            }
        },
        play: {
            opacity: 0
        },
        canvas: {
            background: '#000000',
            backgroundGradient: 'none'
        },
        plugins: {
            controls: {
                durationColor: '#ffffff',
                backgroundGradient: 'none',
                buttonOverColor: '#A2977A',
                progressColor: '#A29060',
                bufferColor: '#A29060',
                sliderGradient: 'none',
                volumeSliderColor: '#000000',
                progressGradient: 'medium',
                backgroundColor: '#000000',
                tooltipTextColor: '#ffffff',
                sliderColor: '#A29060',
                volumeSliderGradient: 'none',
                buttonColor: '#A29060',
                tooltipColor: '#5F747C',
                bufferGradient: 'none',
                borderRadius: '10px',
                height: 40,
                url: "/swf/flowplayer.controls-3.1.5.swf",
                bottom: 5,
                right: 0,
                opacity: 0.9,
                width: 54,
                autoHide: 'always',
                hideDelay: 2000,
                all: false,
                mute: true,
                play: false,
                tooltips: {
                    buttons: false,
                    fullscreen: 'Enter fullscreen mode'
                }
            },
            loading: {
                url: '/swf/loading.swf',
                top: 174,
                left: 455,
                width: 72,
                height: 110,
                display: 'none'
            }
        }
    })
}
function enableDouglasHannantExperience() {
    var a = $("#signature").html();
    flowplayer("signature", {
        src: '/swf/flowplayer.commercial-3.1.5.swf',
        wmode: 'opaque',
        onFail: function() {
            document.getElementById("signature").innerHTML = a
        }
    },
    {
        key: '#@8c331c6322e850abc8b',
        clip: {
            autoPlay: true,
            autoBuffering: true,
            accelerated: true,
            scaling: "scale",
            onResume: function() {
                flowplayer("*").each(function() {
                    this.pause()
                })
            },
            onBegin: function() {
                this.getPlugin("loading").show()
            },
            onCuepoint: function() {
                this.getPlugin("loading").show()
            },
            onBufferFull: function() {
                this.getPlugin("loading").hide()
            },
            onFinish: function() {
                this.getPlugin("play").hide();
                this.unload()
            }
        },
        play: {
            opacity: 0
        },
        canvas: {
            background: '#000000',
            backgroundGradient: 'none'
        },
        plugins: {
            controls: {
                durationColor: '#ffffff',
                backgroundGradient: 'none',
                buttonOverColor: '#A2977A',
                progressColor: '#A29060',
                bufferColor: '#A29060',
                sliderGradient: 'none',
                volumeSliderColor: '#000000',
                progressGradient: 'medium',
                backgroundColor: '#000000',
                tooltipTextColor: '#ffffff',
                sliderColor: '#A29060',
                volumeSliderGradient: 'none',
                buttonColor: '#A29060',
                tooltipColor: '#5F747C',
                bufferGradient: 'none',
                borderRadius: '10px',
                height: 40,
                url: "/swf/flowplayer.controls-3.1.5.swf",
                bottom: 5,
                right: 0,
                opacity: 0.9,
                width: 54,
                autoHide: 'always',
                hideDelay: 2000,
                all: false,
                mute: true,
                play: false,
                tooltips: {
                    buttons: false,
                    fullscreen: 'Enter fullscreen mode'
                }
            },
            loading: {
                url: '/swf/loading.swf',
                top: 174,
                left: 455,
                width: 72,
                height: 110,
                display: 'none'
            }
        }
    }).playlist("div#playlist-entries", {
        loop: true
    })
}
function enableProfileVid(a, b) {
    var c = $("#" + a).html();
    flowplayer(a, "/swf/flowplayer.commercial-3.1.5.swf", {
        key: '#@8c331c6322e850abc8b',
        wmode: 'opaque',
        onFail: function() {
            document.getElementById(a).innerHTML = c
        },
        play: {
            opacity: 0
        },
        clip: {
            url: b,
            autoPlay: true,
            autoBuffering: true,
            accelerated: true,
            scaling: "fit",
            onBegin: function() {
                flowplayer("*").each(function() {
                    this.pause()
                })
            },
            onResume: function() {
                flowplayer("*").each(function() {
                    this.pause()
                })
            },
            onBeforeFinish: function() {
                this.unload()
            },
            onFinish: function() {
                this.unload()
            }
        },
        play: {
            opacity: 0
        },
        canvas: {
            background: '#000000',
            backgroundGradient: 'none'
        },
        plugins: {
            controls: {
                durationColor: '#ffffff',
                backgroundGradient: 'none',
                buttonOverColor: '#A2977A',
                progressColor: '#A29060',
                bufferColor: '#A29060',
                sliderGradient: 'none',
                volumeSliderColor: '#000000',
                progressGradient: 'medium',
                backgroundColor: '#000000',
                tooltipTextColor: '#ffffff',
                sliderColor: '#A29060',
                volumeSliderGradient: 'none',
                buttonColor: '#A29060',
                tooltipColor: '#5F747C',
                bufferGradient: 'none',
                borderRadius: '0px',
                height: 20,
                url: "/swf/flowplayer.controls-3.1.5.swf",
                bottom: 0,
                left: 0,
                opacity: 0.9,
                autoHide: 'always',
                hideDelay: 2000,
                all: false,
                play: true,
                scrubber: true,
                mute: true,
                fullscreen: true,
                tooltips: {
                    buttons: false,
                    fullscreen: 'Enter fullscreen mode'
                }
            }
        }
    })
}