   var map = null;
   var pinID = 1;

    //load the addresses in from the server
     function isEven(x) { return (x%2)?false:true; }
    
    function GetMap()
    {   
        try
        {    
            // If the browser is Firefox get the version number
            var ffv = 0;
            var ffn = "Firefox/"
            var ffp = navigator.userAgent.indexOf(ffn);
            if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
            // If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
            if (ffv >= 1.5) {
              Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
            }
        
            map = new VEMap('map');
            map.LoadMap();  
            map.ZoomOut();  
            
            //map.AttachEvent('onchangemapstyle', ChangeMapStyleHandler);
        }
        catch(e)
        {
            // FF likes to throw an exception here.
        }
    } 

    function PlacePins()
    {      
        if (addresses)
        { 

            for(var i = -1; i < addresses.length - 1; i++)
            {   
                //debugger
                //do we have a geo code???
                if(addresses[i + 1].lng!=null)
                {
                    var location = new VELatLong(parseFloat(addresses[i + 1].lat), parseFloat(addresses[i + 1].lng));
                
                    AddClickablePin(location,"","", GetSubjectPropertyContent(addresses[i + 1]));
		}
		else
		{
	
	
		} 
            }
        }
    }

     function CenterThis(lat, lng, pinid){
     	var location = new VELatLong(parseFloat(lat), parseFloat(lng));
		map.SetCenterAndZoom(location, 14);
		document.getElementById(pinid + "_" + map.GUID).onmouseover();

	}
	
	function AddClickablePin(location, icon_url, title, details)
{
    var pin = new VEPushpin(pinID, location, icon_url, title, details);
    map.AddPushpin(pin);
    //var element = document.getElementById(pinID);
    //element.onclick = EventHandlerOnClick;
    pinID++;
}


function EventHandlerOnClick(e)
{
    if (e!=null)
    {
        document.getElementById(e.currentTarget.id + "_" + map.GUID).onmouseover();
    } else
    {
        document.getElementById(window.event.srcElement.id).onmouseover();
    
    }
    }
    function ListBox()
    {     
         if (addresses)
        { 

            for(var i = -1; i < addresses.length - 1; i++)
            {   var location = new VELatLong(parseFloat(addresses[i + 1].lat), parseFloat(addresses[i + 1].lng));
                if(isEven(i))
				{
                this.document.write("<div class='companyListingBlue' onclick='CenterThis("+ addresses[i + 1].lat +","+addresses[i + 1].lng +","+addresses[i + 1].ID + ")'>");
                document.write("<div class='companyListingBlueExternal'>");
                document.write("<p>");
                document.write("<a href='" );
				document.write(addresses[i + 1].URL );
				document.write("' title='"+ addresses[i + 1].CompanyName +"'>Website</a>" );
				document.write("</p>");
                document.write("<p>");
                document.write("<a href='" );
				document.write(addresses[i + 1].Blog);
				document.write("' title='"+ addresses[i + 1].CompanyName +"'>Blog</a>" );
				document.write("</p>");
				document.write("</div>");
                document.write("<div class='companyListingBlueInternal'>");
                document.write("<p>");
				document.write("<span class='companyNameBlue'>" );
				document.write(addresses[i + 1].CompanyName);
				document.write("</span>"  );
				document.write("</p>");
        		document.write("<p>");
				document.write("<span class='companyCityBlue'>" + addresses[i + 1].City + ", " + addresses[i + 1].State  +   "</span>"  );
				document.write("</p>");
				document.write("</div>");
				document.write("</div>");
			}
			else
			{
			    this.document.write("<div class='companyListingGray'onclick='CenterThis("+ addresses[i + 1].lat +","+addresses[i + 1].lng +","+addresses[i + 1].ID + ")'>");
                document.write("<div class='companyListingGrayExternal'>");
                document.write("<p>");
                document.write("<a href='" );
				document.write(addresses[i + 1].URL );
				document.write("' title='"+ addresses[i + 1].CompanyName +"'>Website</a>" );
				document.write("</p>");
                document.write("<p>");
                document.write("<a href='" );
				document.write(addresses[i + 1].Blog);
				document.write("' title='"+ addresses[i + 1].CompanyName +"'>Blog</a>" );
				document.write("</p>");
				document.write("</div>");
                document.write("<div class='companyListingGrayInternal'>");
                document.write("<p>");
				document.write("<span class='companyNameGray'>" );
				document.write(addresses[i + 1].CompanyName);
				document.write("</span>"  );
				document.write("</p>");
        		document.write("<p>");
				document.write("<span class='companyCityGray'>" + addresses[i + 1].City + ", " + addresses[i + 1].State  +   "</span>"  );
				document.write("</p>");
				document.write("</div>");
				document.write("</div>");
				
			}	

            }
        }
    }

 function Mappit(){
    GetMap(); 
    PlacePins();
}

function GetSubjectPropertyContent(prop)    
    {
        var content = '';
    
        
        
        content += '<div class="PropertyPopup">';
        content += '<h1><span class="Subject">'+ prop.CompanyName +'</span></h1>';
        content += '<div>';
        content += '<table>';
        content += '<tr><td>' + prop.City + ', '+  prop.State + '</td></tr>';
        content += '<tr class="AltRow"><td></td></tr>';
        content += '<tr><td>' + prop.Description + '</td></tr>';
        content += '</table>';
            content += '</div>';
        content += '</div>';

        
        
        return content;
    }


function LoadingPage(){
Mappit();


}
 
