
var map = null;	// VEMap instance
var pinid = 0;	// Pushpin id
var addr = "2649 Production Dr.";
var city = "Virginia Beach";
var st = "VA";
var title = "Dynamic Systems Integration"; // Pushpin Title
var phone = "(757) 431-5000";
var initialized = false;	// Is map initialized with location?
var defaultZoom = 16;	// Default Zoom Level
var titleBox;	// Div holding address info
var paraDesc;	// Description Paragraph
var paraTitle;	// Title Paragraph
var paraPhone;	// Phone Paragraph
var hideButton;	// Button to show/hide Caption
var showCaption = "Show Caption";
var hideCaption = "Hide Caption";
var loc;		// LatLong of location
var visible = false;	// Title Box visible
var pushpinSrc; // Url of Pushpin image
var mapBox;     // The div containing the map
var centerX, centerY;   // Pixel locations of center of map
var defaultX;	// default balloon X offset
var defaultY;	// default balloon Y offset
var boxOffset;	// current balloon X offset
var boxOffsetY;	// current balloon Y offset
var balloonImageUrl;	// Current Balloon Image URL
var balloonUrUrl;  // UpRight Balloon Image URL
var balloonDrUrl;  // DownRight Balloon Image URL
var balloonUlUrl;  // UpLeft Balloon Image URL
var balloonDlUrl;  // DownLeft Balloon Image URL
var balloonTextBox;	// Div with Caption Box Text
var balloonCloseDiv;	// Div with close Button image
var captionTopMargin;  // Top Margin of Caption Balloon text
var imageTds = new Array('our', 'odr', 'oul', 'odl');

function reorient(o)
{
	setOrientation(o);
	setTitle();
}

function setOrientation(o)
{
	var tdId;
	switch(o)
	{
		case 1:
			balloonImageUrl = balloonUrUrl;
			boxOffsetX = defaultX;
			boxOffsetY = defaultY;
			balloonTextBox.style.marginTop = captionTopMargin + "px";
			balloonCloseDiv.style.top = "8px";
			break;
		case 2:
			balloonImageUrl = balloonDrUrl;
			boxOffsetX = defaultX;
			boxOffsetY = defaultY + 200;
			balloonTextBox.style.marginTop = (captionTopMargin + 50) + "px";
			balloonCloseDiv.style.top = "58px";
			break;
		case 3:
			balloonImageUrl = balloonUlUrl;
			boxOffsetX = defaultX - 220;
			boxOffsetY = defaultY;
			balloonTextBox.style.marginTop = captionTopMargin + "px";
			balloonCloseDiv.style.top = "8px";
			break;
		case 4:
			balloonImageUrl = balloonDlUrl;
			boxOffsetX = defaultX - 220;
			boxOffsetY = defaultY + 200;
			balloonTextBox.style.marginTop = (captionTopMargin + 50) + "px";
			balloonCloseDiv.style.top = "58px";
			break;
	}
	for (var i = 0; i < 4; i++)
	{
		if ((i + 1) == o) document.getElementById(imageTds[i]).style.backgroundColor = '#FF0000';
		else document.getElementById(imageTds[i]).style.backgroundColor = '';
	}
}

function fullAddress()
{
	return addr + ", " + city + ", " + st;
}
function htmlAddress()
{
	return addr + "<br />" + city + ", " + st;
}
function setPushpin()
{
	VEPushpin.ShowDetailOnMouseOver = false;	
	paraTitle.innerHTML = title;
	paraDesc.innerHTML = htmlAddress();
	paraPhone.innerHTML = phone;

	var pin = new VEPushpin(pinid++, loc, pushpinSrc, null, null, 'pushpin', 'pushPinTitle', 'pushPinDetail');
	map.AddPushpin(pin);
	map.SetZoomLevel(defaultZoom);
}
function showTitle(e)
{
	if (visible) return;
	hideButton.value = hideCaption;
	titleBox.style.display = "block";
	visible = true;
}
function closeTitle()
{
	if (!visible) return;
	hideButton.value = showCaption;
	titleBox.style.display = "none";
	visible = false;
}
function showHide()
{
	if (visible) closeTitle();
	else showTitle();
}
function setTitle(e)
{
	var center;
	var x, y;
	if (!initialized) loc = map.GetCenter();
	center = map.LatLongToPixel(loc);
	x = centerX - center.x;
	y = centerY - center.y;
	titleBox.style.top = (boxOffsetY - y) + "px";
	titleBox.style.left = (boxOffsetX - x) + "px";
	titleBox.style.backgroundImage = "url(" + balloonImageUrl + ")";
	if (!initialized)
	{
		initialized = true;
		setPushpin();
		showTitle();
	}
}
function gotoLoc(where)
{
	closeTitle();
	map.DeleteAllPushpins();
	visible = initialized = false;
	map.Find(null, where);
}

function GetMap()
{
	try
	{
	    map = new VEMap("mapDiv");
		map.AttachEvent("onendzoom", setTitle);
		map.AttachEvent("onresize", setTitle);
		map.AttachEvent("onendcontinuouspan", setTitle);
		map.AttachEvent("onchangeview", setTitle);
		map.AttachEvent("onchangemapstyle", setTitle);
	    map.LoadMap();
		gotoLoc(fullAddress());
    }
	catch(e)
	{
		alert(e.message);
	} 
}