﻿var BookingTabsHeight = 0;

function SetUpBookingTabs() {

    $("#BookingTabs li").removeClass("noShow");
    
    $("#BookingTabs a").each(function ()
    {
        $(this).click(function ()
        {
            $("#BookingTabs li").removeClass("selected");
            $(this).parent().addClass("selected")

            $("#BookingTabs .contentDiv").removeClass("visible");
            $($(this).attr("href")).addClass("visible");

            return false;
        });
    });

    $("#BookingTabs .contentDiv").each(function ()
    {
        var height = $(this).height();
        if (height > BookingTabsHeight)
        {
            BookingTabsHeight = height;
        }
    });

    $("#BookingTabsContent .inner").height(BookingTabsHeight);
}

function SetUpNavigation() 
{
    //make the show and hide icons
    $(".navigationHolder .openLi").each(function () {
        $(this).addClass("ieHeight");

        var showHide = 'Show';
        if ($(this).hasClass("highlightedLI")) {
            showHide = 'Hide';
        }

        var link = $(this).find('> .cmsListMenuLink');
        link.addClass("iconLink");

        $('<span class="icon ' + showHide.toLowerCase() + 'Icon" title="' + showHide + ' navigation">&nbsp;</span><span class="clearSpacer">&nbsp;</span>').insertAfter(link);
    });

    //set the show click function
    $('.showIcon').click(function () { ShowNav($(this)); });

    //set the hide click function
    $('.hideIcon').click(function () { HideNav($(this)); });
}

function ShowNav(clickedObject) {

    $('.navigationHolder .level1').slideUp();
    $('.navigationHolder .hideIcon').each(function () {
        $(this).removeClass("hideIcon");
        $(this).removeAttr("title");
        $(this).addClass("showIcon");
        $(this).attr("title", "Show navigation");
        $(this).unbind('click');
        $(this).click(function () { ShowNav($(this)); });
    });

    var icon = clickedObject.parent().find('> .showIcon');
    icon.unbind('click');
    icon.removeClass("showIcon");
    icon.removeAttr("title");
    icon.addClass("hideIcon");
    icon.attr("title", "Hide navigation");
    icon.click(function () { HideNav($(this)); });

    clickedObject.parent().find('.level1').slideDown();
}

function HideNav(clickedObject) {

    var icon = clickedObject.parent().find('> .hideIcon');
    icon.unbind('click');
    icon.removeClass("hideIcon");
    icon.removeAttr("title");
    icon.addClass("showIcon");
    icon.attr("title", "Show navigation");
    icon.click(function () { ShowNav($(this)); });

    clickedObject.parent().find('.level1').slideUp();
}

window.onload = function () {
    SetUpBookingTabs();
    SetUpNavigation();
    if (window.RunBannerFader) RunBannerFader();
    if (window.RunCalendar) RunCalendar();
    if (window.RunCodaSlider) RunCodaSlider();
    if (window.RunLightbox) RunLightbox();
    if (window.StyleCheckboxes) StyleCheckboxes();
};
