
if(typeof ($.AWA) == "undefined") {
	jQuery.AWA = Object;
}

//Create the hompage carousel
jQuery.AWA.addGoogleMap = {
	init: function(){
		jQuery('.landing-page .article h2:contains("How to find us")').next('p').after('<div id="map"></div>')
		
		// Google Map Maker script v.1.1
		// Slight restructure of (c) 2006 Richard Stephenson http://www.donkeymagic.co.uk
		// Email: donkeymagic@gmail.com
		// http://mapmaker.donkeymagic.co.uk
		var map;
		var icon0;
		var newpoints = new Array();
		 
		function addLoadEvent(func) { 
			var oldonload = window.onload; 
			if (typeof window.onload != 'function'){ 
				window.onload = func
			} else { 
				window.onload = function() {
					oldonload();
					func();
				}
			}
		}
		 
		addLoadEvent(loadMap);
		addLoadEvent(addPoints);
		 
		function loadMap() {
			map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng( 53.3882843407687, -1.4660283923149109), 15); // First figure Lat, Second Long, Third zoom level
			map.setMapType(G_NORMAL_MAP);
		 
			icon0 = new GIcon();
			icon0.image = "http://www.google.com/mapfiles/marker.png";
			icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
			icon0.iconSize = new GSize(20, 34);
			icon0.shadowSize = new GSize(37, 34);
			icon0.iconAnchor = new GPoint(9, 34);
			icon0.infoWindowAnchor = new GPoint(9, 2);
			icon0.infoShadowAnchor = new GPoint(18, 25);
		}
		 
		function addPoints() {
		 
			newpoints[0] = new Array(53.38828434076877, -1.4660283923149109, icon0, 'Qualsys', '<p>Qualsys<br />Aizelwood\'s Mill, Nursery Street,<br />Sheffield, S3 8GG, England</p><p><a href="http://maps.google.co.uk/maps?f=d&source=s_d&saddr=&daddr=Aizlewood%E2%80%99s+Mill,+S3+8GG&hl=en&geocode=&mra=ls&sll=53.800651,-4.064941&sspn=16.973616,39.506836&ie=UTF8&t=h&z=16">Get directions to the office</a></p>'); 
		 
			for(var i = 0; i < newpoints.length; i++) {
				var point = new GPoint(newpoints[i][1],newpoints[i][0]);
				var popuphtml = newpoints[i][4] ;
				var marker = createMarker(point,newpoints[i][2],popuphtml);
				map.addOverlay(marker);
			}
		}
		 
		function createMarker(point, icon, popuphtml) {
			var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
			var marker = new GMarker(point, icon);
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(popuphtml);
			});
			return marker;
		}
		
	} // End init
}

jQuery(document).ready(function(){
	jQuery.AWA.addGoogleMap.init();
});	
