var rotatorIndex = 0;

$(document).ready(function() {


    if ($('.javascript_hook')[0]) {
        $('#main').addClass('mainBlue');
    }

    //If browser is IE > strip border left on top right li
    if (jQuery.browser.msie) {
        jQuery('#top_bar a').css('border-left', '0');
    };

    //Lodges Package Selection JQuery
    jQuery('.cat_title').live("click", function() {
        if ($(this).parent().find(".category").css('display') == 'block') {
            $(this).parent().find(".category").slideUp({ duration: 800, easing: 'easeInOutSine' });
            $(this).removeClass('cat_active');
            $(this).addClass('cat_passive');
        }

        else {
            $(this).removeClass('cat_passive');
            $(this).addClass('cat_active');
            if ($(this).parent().find(".category").is(':hidden') == true) {
                $(this).parent().find(".category").hide().slideDown({ duration: 700, easing: 'easeInOutSine' })
            };
        }
    });

    //Iterate through each category. If it has a selected class display it as CSS block
    jQuery('.category').each(function() {
        if ($(this).hasClass('open')) {
            $(this).css('display', 'block');
            $(this).parent().find(".cat_title").removeClass('cat_passive');
            $(this).parent().find(".cat_title").addClass('cat_active');
        }
    });

    $('#' + $("#top li.selected a").attr("rel")).show();

    $(".tMenu").hover(
        function() {
            $('.tSub').hide();
            $('#' + $(this).attr("rel")).show();
            $('#top li').removeClass("selected");
            $(this).parent().addClass("selected");
        }
    );

    var hConfig = {
        sensitivity: 6,
        interval: 20,
        over: function() { },
        timeout: 200,
        out: resetMenu
    };
    $("#header").hoverIntent(hConfig);

    function resetMenu() {
        $('.tSub').hide();
        $('#' + $("#top li.current a").attr("rel")).show();
        $('#top li').removeClass("selected");
        $("#top li.current").addClass("selected");
    }

    //Rotating Banner updated.
    //30th November 2010

    if (jQuery('#rotatingBanner').is(':visible')) {
        //If the about us picture wall is present don't cycle.
        comp = jQuery('#vidPageTop');
        if (!comp.size()) {
            var startCycle = new setCycle('fade', 1000, 5000);
        } else {
            startCycle2 = new setCycle2('fade', 1000, 5000);
        }
    };

    //Cycle with pager
    function setCycle(transition, speed, timeout) {
        this.transition = transition;
        this.speed = speed;
        this.timeout = timeout;
        this.pager = '#slidePanels';
        jQuery("<div id='slidePanels'></div>").insertAfter("#rotatingBanner");
        jQuery('#rotatingBanner')
        .cycle({
            fx: this.transition,
            speed: this.speed,
            timeout: this.timeout,
            pager: this.pager

        });

    };

    //Cycle without pager
    function setCycle2(transition, speed, timeout) {
        this.transition = transition;
        this.speed = speed;
        this.timeout = timeout;
        jQuery('#rotatingBanner')
        .cycle({
            fx: this.transition,
            speed: this.speed,
            timeout: this.timeout
        });

    };

    function addActive(el) {
        this.el = el;
        jQuery(el).addClass('selected');
    };

    if (jQuery('#home').size()) {
        addActive('#top li:eq(0)');
    };

    function setSearch(string) {
        searchBox = jQuery('.search input:text');
        jQuery(searchBox).attr('value', string);
        jQuery(searchBox).focus(function() {
            jQuery(this).attr('value', '');
        });
        jQuery(searchBox).blur(function() {
            jQuery(this).attr('value', string);
        });
    }

    setSearch("Search...");

    //End Document Ready

});

//Video JS

function loadPlayer(video) {
    var videoclip = $(video).attr("href");
    var vidTitle = $(video).attr("name");
    var vidDescription = $(video).parent().find(".vidDesc").html();

    loadPlayer2(videoclip, vidTitle, vidDescription);
}
function loadPlayer2(vid, title, description) {
    var player = $f("videoGallery", { src: "http://" + window.location.host + "/flash/flowplayer-3.2.2.swf", wmode: 'opaque' }, {
        play: { opacity: 0 },

        plugins: {
            controls: {
                timeColor: "rgba(78, 78, 78, 1)",
                borderRadius: 5,
                bufferGradient: "none",
                slowForward: true,
                backgroundColor: "rgba(234, 233, 223, 1)",
                volumeSliderGradient: "none",
                slowBackward: false,
                timeBorderRadius: 20,
                time: true,
                progressGradient: "none",
                height: 26,
                volumeColor: "#ffffff",
                tooltips: {
                    marginBottom: 5,
                    volume: true,
                    scrubber: true,
                    buttons: false
                },
                opacity: 1,
                fastBackward: false,
                timeFontSize: 12,
                bufferColor: "#a3a3a3",
                volumeSliderColor: "#ffffff",
                border: "0px",
                buttonColor: "rgba(65, 111, 143, 1)",
                mute: true,
                autoHide: {
                    enabled: true,
                    hideDelay: 500,
                    hideStyle: "fade",
                    mouseOutDelay: 500,
                    hideDuration: 400,
                    fullscreenOnly: false
                },
                backgroundGradient: "none",
                width: "95pct",
                display: "block",
                sliderBorder: "1px solid rgba(128, 128, 128, 0.7)",
                buttonOverColor: "rgba(78, 78, 78, 1)",
                fullscreen: true,
                timeBgColor: "rgb(0, 0, 0, 0)",
                borderWidth: 0,
                scrubberBarHeightRatio: "0.1",
                bottom: "12px",
                stop: false,
                sliderColor: "#000000",
                zIndex: 1,
                scrubberHeightRatio: 0.6,
                tooltipTextColor: "#ffffff",
                sliderGradient: "none",
                timeBgHeightRatio: 0.8,
                volumeSliderHeightRatio: 0.6,
                name: "controls",
                timeSeparator: " ",
                volumeBarHeightRatio: 0.1,
                left: "50pct",
                tooltipColor: "#000000",
                playlist: false,
                durationColor: "rgba(129, 129, 129, 1)",
                play: true,
                fastForward: true,
                timeBorder: "0px solid rgba(0, 0, 0, 0.3)",
                progressColor: "#ffffff",
                scrubber: true,
                volume: true,
                builtIn: false,
                volumeBorder: "1px solid rgba(128, 128, 128, 0.7)"
            }
        },
        clip: {
            autoPlay: true,
            autoBuffering: true,
            url: vid
        }
    });

    player.load();

    $('#videoGalleryDescription h2').html(title);
    $('#videoGalleryDescription p').html(description);
};

//End Video JS



