﻿/*

This file contains all initialization methods for location start up.
It is attached to the body onload via .NET

*/

// Initializes the UI components of the locator.
function initializeLocator(){

    // Set up the various message boxes
    loadingbox = new MessageBox("loadingbox", "ve_loadingBox");
    infobox = new MessageBox("infobox", "ve_infoBox");
    ambigbox = new MessageBox("ambigbox", "ve_ambigBox");
    
    try{
        map = new Map('atmap');        
    }
    catch(err){}
    
    dal = new DAL();    
    panel = new Panel('panel');
    
    panel_results = new ResultsPanel('resultsPanel');    
    legend = new Legend('legend');
    
    window.onresize = onWindowResize;
    onWindowResize();
}

// Initializes the locator footer.
function initFooter(){
    var footer = document.getElementById("footer");
    
    if ((footer != null) && (footer != "undefined")){
        var newTop = (document.documentElement.clientHeight - footer.offsetHeight - 15);
        footer.style.top = newTop + "px";
    }
}

// Window resize event which fires whenever the user resizes the browser window.
function onWindowResize(){
    
    resizePanels();
    
    if (map != null){
        try{
            map.Resize(panel_results.GetElement().offsetTop, null);
        }catch (err) 
        {
            alert(err.message);
        }
    }
}

// Adjusts panel sizes and locations, window resize compliment function.
function resizePanels(){
    initFooter();

    var footerOffset = document.getElementById("footer").clientHeight + 5;    
    
    if ((footerOffset == null) || (footerOffset == 'undefined')){
        footerOffset = 0;
    }
    panel_results.Resize();
    panel_results.Reposition(document.documentElement.clientHeight - panel_results.GetElement().clientHeight - footerOffset + 1, null);
    
    panel.Resize(panel_results.GetElement().offsetTop - panel.GetElement().offsetTop - 1, null);
    
    // Adjust panel position, take into account the border and some padding
    //legend.Reposition(panel.GetElement().offsetTop + 10, document.body.clientWidth - legend.GetElement().clientWidth - 4 - 10);
    
    //Relocate Legend to the left-bottom position
    legend.Reposition(panel.GetElement().offsetTop + panel.GetElement().clientHeight - legend.GetElement().clientHeight - 4 - 10, panel.GetElement().clientWidth + 50);


    // Reposition various information boxes.        
    loadingbox.AutoReposition();
    ambigbox.AutoReposition();
    infobox.AutoReposition();
    infobox.GetElement().style.top = panel.GetElement().offsetTop + 10 + "px";
    
    try {
        setTimeout("map.AttachAutoFind();", 2000);
    }catch (Err)
    {alert (Err)}
}