var map = null;
var directionsPanel;
var directions;
var removed = false;
var markSHM = null
var endAddy = "99+Route+25a,+11786";
var win;

function initialize() {
	if (GBrowserIsCompatible()) {
		//CREATE MAP
		var shm = new GLatLng(40.94425, -72.892892)
		map = new GMap2(document.getElementById("googleMap"));
		map.setCenter(shm, 13);
		
		directionsPanel = document.getElementById("directionsPlaceHolder");
		directions = new GDirections(map, directionsPanel);
		
		//SET CUSTOM UI
		var customUI = map.getDefaultUI();
			customUI.controls.scalecontrol = false;
			customUI.controls.largemapcontrol3d = false;
			customUI.controls.smallzoomcontrol3d = true;
			customUI.controls.maptypecontrol = false;
		map.setUI(customUI);
		
		setSHM();
	}
}

function viewDir(directions)
{
		if (!win || win.closed) {
			win = window.open("", "Window2", "width=500,height=400,scrollbars=yes");
			writeToWindow(document.getElementById('directionsPlaceHolder').innerHTML);
    	} else {
        	win.focus();
			writeToWindow(document.getElementById('directionsPlaceHolder').innerHTML);
    	}
}

function writeToWindow(data)
{
    var newContent = "<html><head><title>Directions to Shoreham Wireless</title></head><body>";
    newContent += data;
    newContent += "</body></html>";
	
    win.document.write(newContent);
    win.document.close();
}

function getDir(startAddy)
{
	if(markSHM != null)
	{
		removeSHM(markSHM);
	}
	
	directions.load(startAddy + " to: " + endAddy);
	document.getElementById("viewlargemap").setAttribute("href", "http://maps.google.com/maps?f=q&source=s_q&hl=en&&q=" + startAddy + "+to:+" + endAddy);
}

function setSHM()
{
	document.getElementById('directionsPlaceHolder').innerHTML = "To view directions please click on a town where you are coming from.";
	markSHM = new GMarker(new GLatLng(40.94425, -72.892892));
	map.addOverlay(markSHM);
	markSHM.openInfoWindowHtml('<div style="color: #000; font-size: 16px;"><b>Shoreham Wireless</b><br>99 Route 25a Suite 9<br>Shoreham, NY 11786</div>');
}

function removeSHM(marker)
{
	map.removeOverlay(marker);
	markSHM = null;
	document.getElementById('directionsPlaceHolder').innerHTML = '<form><input type="button" value=" Print this page " onclick="window.print();return false;" /></form>';
}

function goHome()
{
	directions.clear();
	
	if(markSHM == null)
	{
		setSHM();
	}
}