﻿/// <reference path="VEJS/VeJavaScriptIntellisenseHelper.js" />
/// <reference path="TPHelpers.js" />
function FindAddress(map, address, callback)
{
    /// <summary>Finds an address and calls the callback function.</summary>
    /// <param name="map" type="VEMap">The VEMap object.</param>
    /// <param name="address" type="String">The address to find.</param>
    /// <param name="callback">The callback function to call.</param>    
    map.Find(null,address, null, null, null, null, true, false, false, false, callback);                                
}

function AddPushpin(map, latitude, longitude, title, description, icon, sidebarID)
{
    /// <summary>Adds a pushpin to the map.</summary>
    /// <param name="map" type="VEMap">The VEMap object.</param>
    /// <param name="latlong" type="VELatLong">The VELatLong object containing latitude and longitude.</param>
    /// <param name="title" type="String">The title of the pushpin.</param>
    /// <param name="description" type="String">The text or markup to contain within the pushpin flyout.</param>
    var latlong = new VELatLong(latitude,longitude);
    var shape = new VEShape(VEShapeType.Pushpin, latlong);
    shape.SetTitle(title);
    shape.SetDescription(description);   
    if(icon)
    { 
        shape.SetCustomIcon(icon);  
    }
   
    map.AddShape(shape);
    if(sidebarID){
   var branch = document.getElementById(sidebarID);
       if(branch){
       branch.href = "#";
        branch.onclick = function(){SidebarShowInfo(shape.GetID(), sidebarID); return false;}
       }
   }
   //  if(clickEvtHdlr){
   // var el = document.getElementById(shape.GetID());
   // addEvent(el,"click", clickEvtHdlr);   
   // }
}
 var myArray=new Array();
function SidebarShowInfo(shapeID, sidebarID){
 map.HideInfoBox();
 currentShape = map.GetShapeByID(shapeID);
   map.ShowInfoBox(currentShape);
   //meh hack tastic!
   setTimeout("myArray.reverse()",6000);
    //currentIcon = currentShape.GetCustomIcon();
    //currentShape.SetCustomIcon(currentIcon.replace('pinStyle', 'pinHoverStyle'));
//
}

 function shape_onclick(e)
  {
   if (e.elementID != null)
   {
   map.HideInfoBox();
    var shape = map.GetShapeByID(e.elementID);
    map.ShowInfoBox(shape);
     //meh hack tastic!
    setTimeout("myArray.reverse()",3000);
    return true;
  }
 }


var map;
 
function doMapLoad()
{
    InitializeMap("MyMap");
}
var lastRequest = 0;
function InitializeMap(divName)
{
    map = new VEMap(divName);    
    map.LoadMap(new VELatLong(53.0,-1.0), 6);
  
    //map.HideDashboard();
  RequestData();
  
   // map.ZoomIn(15);
}
function RequestData(){
if(lastRequest < BranchAddys.length){
//branchLatLongs = branchLatLongs + "<br />" + BranchAddys[lastRequest] + " =";
  map.Find(null, BranchAddys[lastRequest], null, null, null, null, true, false, false, false, FindCallback);   
}
//var blah = document.getElementById("mapLatLong");
//blah.innerHTML = branchLatLongs;
}
var branchLatLongs = "";

function FindCallback(shape, results, place, err)
{
    //map.Clear();
    if(place){
        for(var i=0;i<place.length;i++){
            var newPlace = place[i];
            if(newPlace.MatchCode == VEMatchCode.Good && newPlace.MatchConfidence == VEMatchConfidence.High){
                var latlong = newPlace.LatLong;
                //map.SetCenter(latlong); 
                //branchLatLongs = branchLatLongs + "lat=" + latlong.Latitude + + "long=" +latlong.Longitude;
                var content = '<img src="http://www.att.com/Common/indc/homepage/images/logo.gif"><br/><b>at&amp;t Southeast</b><br/>This is the headquarters for the former BellSouth, now at&amp;t SouthEast.';
                AddPushpin(map,latlong.Latitude, latlong.Longitude, "My Pin",content, "http://localhost/tpwebsite/assets/images/TPApple22.gif");            
            }
        }
    }
    lastRequest++;
   RequestData();
}

