﻿var currHighlighted = '';
var intiallySelected = '';

$(function() {
    /* Main Menu Settings */
    // Bind a trigger to the whole nav block, so when the mouse leaves, the sub navs close.
    $('#mainMenuBox').mouseleave(function() {
        if(currHighlighted.selector != intiallySelected)
        {
            //$("#mnuSubHolder").slideUp(300, function () {
            //    currHighlighted.css('background-position', '0px 0px');
            //    if (intiallySelected && intiallySelected != '')
            //    {
                    switch(intiallySelected)
                    {
                        case '#mnuActivities':
                            showActivitiesNav();
                            break;
                        case '#mnuBanffGondola':
                            showBanffGondolaNav();
                            break;
                        case '#mnuBanffLakeCruise':
                            showBanffLakeCruiseNav();
                            break;
                        case '#mnuColumbiaIcefieldExperience':
                            showColumbiaIcefieldExperienceNav();
                            break;
                        case '#mnuAirportShuttles':
                            showAirportShuttlesNav();
                            break;
                        case '#mnuStoreLocations':
                            showStoreLocationsNav();
                            break;
                        case '#mnuWebcams':
                            showWebcamsNav();
                            break;
                        case '#mnuHome':
                            showHomeNav();
                            break;                            
                    }
            //    }
            //});
        }
    });
    
    $('#mnuActivities').mouseover(function() {
        showActivitiesNav();
    });
    
    $('#mnuBanffGondola').mouseover(function() {
        showBanffGondolaNav();
    });
    
    $('#mnuBanffLakeCruise').mouseover(function() {
        showBanffLakeCruiseNav();
    });
    
    $('#mnuColumbiaIcefieldExperience').mouseover(function() {
        showColumbiaIcefieldExperienceNav();
    });
    
    $('#mnuAirportShuttles').mouseover(function() {
        showAirportShuttlesNav();
    });
    
    $('#mnuStoreLocations').mouseover(function() {
        showStoreLocationsNav();
    });
    
    $('#mnuWebcams').mouseover(function() {
        showWebcamsNav();
    });
    
    $('#mnuHome').mouseover(function() {
        showHomeNav();
    });    
    
    // Search Fields Settings
    $('.searchField').focus(function() {
      if (!this.modified) { this.value = ''; this.modified = true; }
    });
    // Set the calendar field to be a DatePicker
    $('.searchFieldCal').datepicker();
    
    /* End Main Menu Settings */
});

function showSubMenuHolder(subNavToShow)
{
    if (!$("#mnuSubHolder").is(":visible")) {
        /* Do rounding (native in Firefox and Safari) */
        //$('#mnuSubHolder').css('-webkit-border-radius', '5px');
        //$('#mnuSubHolder').css('-moz-border-radius', '5px');
        $('#mnuSubHolder').slideDown(300, function(){
            // Show the Sub Nav
            subNavToShow.show();
        });
    }
    else
    {
        // Show the Sub Nav
        subNavToShow.show();
    }
}
function hideAllSubNavElms()
{
    $('.mnuSubBox').hide(); // Hide all sub nav blocks
    $('a.mnuMain').css('background-position', '0px 0px'); // Set all main nav BGs to default.
}
function mainNavBGSelected(selectedMainNav)
{
    selectedMainNav.css('background-position', '0px 29px');
    currHighlighted = selectedMainNav;
}
function showActivitiesNav()
{
    // Hide all sub navs.
    hideAllSubNavElms();
    // Make sure the holder is visible.
    showSubMenuHolder($('#mnuSubActivities'));
    // Finally, show the correct rollover state.
    // Set the main nav's BG
    mainNavBGSelected($('#mnuActivities'));
}
function showBanffGondolaNav()
{
    // Hide all sub navs.
    hideAllSubNavElms();
    // Make sure the holder is visible.
    showSubMenuHolder($('#mnuSubBanffGondola'));
    // Set the main nav's BG
    mainNavBGSelected($('#mnuBanffGondola'));
}
function showBanffLakeCruiseNav()
{
    // Hide all sub navs.
    hideAllSubNavElms();
    // Make sure the holder is visible.
    showSubMenuHolder($('#mnuSubBanffLakeCruise'));
    // Set the main nav's BG
    mainNavBGSelected($('#mnuBanffLakeCruise'));
}
function showColumbiaIcefieldExperienceNav()
{
    // Hide all sub navs.
    hideAllSubNavElms();
    // Make sure the holder is visible.
    showSubMenuHolder($('#mnuSubColumbiaIcefieldExperience'));
    // Set the main nav's BG
    mainNavBGSelected($('#mnuColumbiaIcefieldExperience'));
}
    
function showAirportShuttlesNav()
{
    // Hide all sub navs.
    hideAllSubNavElms();
    // Make sure the holder is visible.
    showSubMenuHolder($('#mnuSubAirportShuttles'));
    // Set the main nav's BG
    mainNavBGSelected($('#mnuAirportShuttles'));
}
function showStoreLocationsNav()
{
    // Hide the Sub Nav Holder.
    $('#mnuSubHolder').slideUp(300, function(){
        // Do this first, or currHighlighted will be set to this nav element.
        if (currHighlighted)
            currHighlighted.css('background-position', '0px 0px');
        // Set the main nav's BG
        mainNavBGSelected($('#mnuStoreLocations'));
    });
}
function showWebcamsNav()
{
    // Hide the Sub Nav Holder.
    $('#mnuSubHolder').slideUp(300, function(){
        // Do this first, or currHighlighted will be set to this nav element.
        if (currHighlighted)
            currHighlighted.css('background-position', '0px 0px');
        // Set the main nav's BG
        mainNavBGSelected($('#mnuWebcams'));
    });
}


function showHomeNav()
{
    // Hide the Sub Nav Holder.
    $('#mnuSubHolder').slideUp(300, function(){
        // Do this first, or currHighlighted will be set to this nav element.
        if (currHighlighted)
            currHighlighted.css('background-position', '0px 0px');
        // Set the main nav's BG
        mainNavBGSelected($('#mnuHome'));
    });
}

//Cookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//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);
        }
    });
}
