﻿var MenuFadeAnimationDuration = 0.4;
var MenuFadeAnimationFramesPerSecond = 20;
function InitializeTopMenu()
{        
    // Find location
    map.addControl(new PositionedMapControl(30,-3,'FindLocation'));

    // Map options
    map.addControl(new PositionedMapControl(250,-3,'MapOptions'));

    // Markers
    map.addControl(new PositionedMapControl(385,-3,'MarkersMenu'));
    
    // File menu
    map.addControl(new PositionedMapControl(551,-3,'FileMenu'));
    map.addControl(new PositionedMapControl(7,320,'DistanceDisplayOutside'));

    HideAllTopMenus();
    //setTimeout("ShowDropDownMenu('MarkersMenu',true);",1500);
    //setTimeout("ShowDropDownMenu('FindLocation',true);",1500);
}

function ToggleSlider_Nav(MenuID) {
    toggleSlide(MenuID);
    RefreshListOfSavedMaps();
}


function ShowSaveDialog() {
    if(ReadCookie("muid")==null||ReadCookie("muid")=="")
        $get('LoginDialogBox').style['display']='block';
    else
    {
        $get('saveDialogBox').style.display = 'block';
        $get('txtSaveMapName').focus();
    }
    ToggleSlider_Nav("FileMenu");
}

function CloseSaveDialog() {
    $get('saveDialogBox').style.display = 'none';
}

function CloseToLoginDialog() {
    $get('LoginDialogBox').style.display = 'none';
}


function ShowMapsDialog() {
    if(ReadCookie("muid")==null||ReadCookie("muid")=="")
        $get('LoginDialogBox').style['display']='block';
    else
    {
        $get('dialogLoadMaps').style.display = 'block';
    }
    ToggleSlider_Nav("FileMenu");
}

function ClosMapsDialog() {
    $get('dialogLoadMaps').style.display = 'none';
}

function ShowMarkersDialog() {
    $get('MarkersMenu').style.display = 'block';
}

function CloseMarkersDialog() {
    $get('MarkersMenu').style.display = 'none';
}



function HideAllTopMenus()
{
    $get('FindLocation').style['display']='none';
    $get('MapOptions').style['display']='none';
    $get('MarkersMenu').style['display']='none';
    $get('FileMenu').style['display']='none';
}

/*function FadeAllTopMenus()
{
    if(IsDropDownMenuVisible('FindLocation'))
        HideDropDownMenu('FindLocation');
    if(IsDropDownMenuVisible('MapOptions'))
        HideDropDownMenu('MapOptions');
    if(IsDropDownMenuVisible('MarkersMenu'))
        HideDropDownMenu('MarkersMenu');
    if(IsDropDownMenuVisible('FileMenu'))
        HideDropDownMenu('FileMenu');
}

function ShowDropDownMenu(MenuId, NoFadeAllOtherMenus)
{
    if(NoFadeAllOtherMenus==null||NoFadeAllOtherMenus==false)
        FadeAllTopMenus();
    $get(MenuId).style['display']='block';
    AjaxControlToolkit.Animation.FadeInAnimation.play($get(MenuId), MenuFadeAnimationDuration, MenuFadeAnimationFramesPerSecond, 0, 1, true);
    
    // If the user is showing the find location box, set focus to the textbox it contains
    if(MenuId=='FindLocation')
        setTimeout("$get('txtFindLocation').focus();",333);
    if(MenuId=='FileMenu')
    {
        // Reset the submenus to be hidden
        HideFileMenuSubMenus();
        HideAllSaveMapComponents();

        // Best perform this async call now so by the time the user clicks the Load Maps button
        // the call will have been completed.
        RefreshListOfSavedMaps();
    }
}

function HideDropDownMenu(MenuId)
{    
    AjaxControlToolkit.Animation.FadeOutAnimation.play($get(MenuId), MenuFadeAnimationDuration, MenuFadeAnimationFramesPerSecond, 0, 1, true);    
    setTimeout("$get('" + MenuId + "').style['display'] = 'none';", MenuFadeAnimationDuration*1000);
}*/

function IsDropDownMenuVisible(MenuId)
{
    return $get(MenuId).style['display']=='block';
}