if(!window.Menu)
{
    window.Menu = {};
}

if(!window.Directions)
{
    window.Directions = {};
}

Menu.ListItemSelected = null;
Directions.MapControl = null;
Directions.FirstRun   = true;
Directions.StartLocation = null;

function OnLoad()
{
    var url = document.location.href;
    var hasFragment = false;
    
    if(url != null)
    {
       var fragmentIndex = url.indexOf("#");
       
       if(fragmentIndex >= 0)
       {
           var fragment = url.substr(fragmentIndex + 1);
           
            if(fragment == "Home"    ||
              fragment == "Services" ||
              fragment == "Mission"  ||
              fragment == "Location" ||
              fragment == "About")
            {
                hasFragment = true;
                Menu.Click(fragment);
            }
        }
    }
    
    if(!hasFragment)
    {
        Menu.Click('Home');
    }
    
    Directions.MapControl = new VEMap('map');
    Directions.MapControl.LoadMap();
    Directions.MapControl.HideDashboard();
   
    Directions.StartLocation = new VELatLong(47.67303,-122.159218);
    var shape = new VEShape(VEShapeType.Pushpin, Directions.StartLocation);
    
    Directions.MapControl.AddShape(shape);
    
    Directions.MapControl.SetCenterAndZoom(Directions.StartLocation, 15);
}   

Menu.Click = function(menu)
{
    var listItemSelected = $(menu);
    
    if(Menu.ListItemSelected)
    {
        Menu.ListItemSelected.className = null;
        var previousSection = $(Menu.ListItemSelected.id + 'Section');
        previousSection.style.visibility = 'hidden';
    }
    
    listItemSelected.className = 'menuSelected';
    Menu.ListItemSelected = listItemSelected;
    
    //document.location = "default.aspx#" + Menu.ListItemSelected.id;
    
    var section = $(menu + 'Section');
    
    if(section)
    {   
        section.style.visibility = 'visible';
    }        
}
    
Directions.Focus = function(element)
{
    if(Directions.FirstRun)
    {
        element.value = "";
        Directions.FirstRun = false;
    }   
}

Directions.GetRoute = function()
{
    var startAddress = $('startAddress');
    
    if(startAddress)
    {
        try
        {
            Directions.MapControl.GetRoute(Directions.StartLocation, startAddress.value);
        }
        catch(err)
        {
        
        }
    }
}