var currHighlighted = '';
var intiallySelected = '';

function showSubMenuHolder(subNavToShow) {
    // Initially, hide the subNavs
    $(".mnuSubBox").hide();

    if (!$("#mnuSubHolder").is(":visible")) {
        $('#mnuSubHolder').slideDown(300, function() {
            subNavToShow.show(); // Show the Sub Nav
        });
    } else {
        subNavToShow.show(); // Show the Sub Nav
    }
}
function hideAllSubNavElms() {
    $('.mnuSubBox').hide(); // Hide all sub nav blocks
    $('a.navBtn').css('background-position', '0px 0px'); // Set all main nav BGs to default.
}
function mainNavBGSelected(selectedMainNav) {
    selectedMainNav.css('background-position', '0px 35px');
    currHighlighted = selectedMainNav;
}
function showHomeNav() {
    $('#mnuSubHolder').slideUp(300, function () {
        // Do this first, or currHighlighted will be set to this nav element.
        if (currHighlighted) {
            currHighlighted.css('background-position', '0px 0px');
        }
        mainNavBGSelected($('#mnuHome')); // Set the main nav's BG
    });
}
function showExpressNav() {
    hideAllSubNavElms();// Hide all sub navs.
    showSubMenuHolder($('#mnuSubExpress'));// Make sure the holder is visible.
    mainNavBGSelected($('#mnuExpress'));// Finally, show the correct rollover state.Set the main nav's BG
}
function showCharterNav() {
    hideAllSubNavElms();// Hide all sub navs.
    showSubMenuHolder($('#mnuSubCharter'));// Make sure the holder is visible.
    mainNavBGSelected($('#mnuCharter'));// Set the main nav's BG
}

//usage javascript:showDialog('4908','Testing');
function showDialog(ID, Title, Width, Height) {
    if (jQuery(".btDialogBox").length > 0) {
        jQuery(".btDialogBox").dialog("open");
        if ($.browser.msie && $.browser.version < 8) { jQuery('.ui-dialog-titlebar-close').css('margin-top', '1px'); }
    } else {
        jQuery('body').append('<div class="btDialogBox"></div>');
        Width = (Width != null && Width != '') ? Width : 640;
        Height = (Height != null && Height != '') ? Height : 480;
        jQuery(".btDialogBox").dialog({ autoOpen: true, height: Height, width: Width, modal: true, draggable: false, resizable: false, position: 'center', title: Title });
    }

    jQuery.ajax({
        url: '/dialogbox.aspx?id=' + ID,
        async: false,
        success: function (data) {
            jQuery(".btDialogBox").html(data);
        }
    });
}

$(function () {
    // ul.tabs now functions as our navigator
    $("#carouselLayout").scrollable().navigator({navi: '.navi1'});
    // ul.tabs now functions as our navigator
    $("#majorItemImage").scrollable({circular: true}).navigator({navi: '.navi2'}).autoscroll({ autoplay: true, interval: 4500 });

    // Bind a trigger to the whole nav block, so when the mouse leaves, the sub navs close.
    $('#mainMenuBox').mouseleave(function () {
        if (currHighlighted.selector != intiallySelected) {
            switch (intiallySelected) {
                case '#mnuHome':
                    showHomeNav();
                    break;
                case '#mnuExpress':
                    showExpressNav();
                    break;
                case '#mnuCharter':
                    showCharterNav();
                    break;
            }
        }
    });

    $('#mnuHome').mouseover(function () {showHomeNav();});
    $('#mnuHome').mouseout(function () {hideAllSubNavElms(); });
    $('#mnuExpress').mouseover(function () {showExpressNav();});
    $('#mnuCharter').mouseover(function () {showCharterNav();});
});

//Cufon Call
Cufon.replace('h1,h2,h3,h4,#message');


//usage javascript:showDialog('4908','Testing');
function showDialog(ID, Title, Width, Height) {
    if ($(".popUpDialog").length > 0) {
        $(".popUpDialog").dialog("open");
        if ($.browser.msie && $.browser.version < 8) { $('.ui-dialog-titlebar-close').css('margin-top', '1px'); }
    } else {
        $('body').append('<div class="popUpDialog"></div>');
        Width = (Width != null && Width != '') ? Width : 640;
        Height = (Height != null && Height != '') ? Height : 480;
        $(".popUpDialog").dialog({ autoOpen: true, height: Height, width: Width, modal: true, draggable: false, resizable: false, position: 'center', title: '<h4>' + Title + '</h4>', zIndex: 100000 });
    }

    $.ajax({
        url: '/popupdialog.ashx?id=' + ID,
        async: false,
        success: function (data) {
            $(".popUpDialog").html(data);
        }
    });
}
