﻿var map;

function load()
{
	if (GBrowserIsCompatible)
	{
		var stjamesPoint = new GPoint(0.2735, 51.1355);
		map = new GMap(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GScaleControl())
		map.centerAndZoom(stjamesPoint, 2);

		var marker = new GMarker(stjamesPoint);
		var markerHTML = "<img src=\"../images/stjames.png\" width=\"200px\" height=\"217px\"/><br/><a href=\"http://maps.google.co.uk/maps?q=TN23RL\">Need Directions?</a>";
		GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(markerHTML); });

		map.addOverlay(marker);
		marker.openInfoWindowHtml(markerHTML);
		   
		// Monitor the window resize event and let the map know when it occurs
		if (window.attachEvent)
		{
			window.attachEvent("onresize", function() {resizeMapDiv()} );
		}
		else
		{
			window.addEventListener("resize", function() {resizeMapDiv()} , false);
		}

		resizeMapDiv();
		map.centerAndZoom(stjamesPoint, 2);
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function windowWidth()
{
	var width = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			width = window.innerWidth;
	} else if( document.documentElement && document.documentElement.clientWidth ) {
			//IE 6+ in 'standards compliant mode'
			width = document.documentElement.clientWidth;
	} else if( document.body && document.body.clientWidth ) {
			//IE 4 compatible
		width = document.body.clientWidth;
	}
	return width;	
}

function windowHeight()
{
	var height = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
			//Non-IE
			height = window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
			//IE 6+ in 'standards compliant mode'
			height = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight ) {
			//IE 4 compatible
		height = document.body.clientHeight;
	}
	return height;	
}


function resizeMapDiv()
{
	var topMarker = document.getElementById("top_marker");
	var left = findPosX(topMarker);
	var top = findPosY(topMarker);
	var bottom = windowHeight();
	var right = windowWidth() - left;
	
	var mapDiv = document.getElementById("map");
	mapDiv.style.left = left + "px";
	mapDiv.style.top = top + "px";
	mapDiv.style.width = (right - left) + "px";
	mapDiv.style.height = (bottom - top - left) + "px";
	map.checkResize();
}


