/****
Author:         James Condliffe
Date:           07/01/2007
Filename:       locationmap.js
Description:    Hooks into the Google Maps API to display a location
                map for Sirdar Spinning Ltd.
                
Ammend:         Andrei Vais, 10/03/2009 - moved the script that selects the correct GoogleMapKey based on the site location                
****/

var GoogleMapLink= "http://maps.google.com/maps?file=api&amp;v=2&amp;key=";
var GoogleMapKey= "";

if (location.hostname.indexOf("192.168.120.75") != -1)
{
    GoogleMapKey = "ABQIAAAAMNvQGW6scFVyKCiVoIhy-xQpI6VqKmTtQnU2OZ9rtSX5WEi_1hRVS-tdSa65lSDnD2Q8BkUapOLWLg";
}
else if (location.hostname.indexOf("preview") != -1)
{
    GoogleMapKey = "ABQIAAAAMNvQGW6scFVyKCiVoIhy-xRVKjzt-PJ6vtS_40D7cMR7_ScrrhQmy1u5LpbVCvXZf3uABCmNweh-XQ";
}
else
{
    GoogleMapKey = "ABQIAAAAMNvQGW6scFVyKCiVoIhy-xRljA2bdGTzrGOkyZwmwRh-AP2_ZRRAvA7UKeUvjpx493GG1cVsNVDVdg";		    
}
GoogleMapLink += GoogleMapKey
//alert(GoogleMapLink);
document.write("<script src=\"" + GoogleMapLink + "\" type=\"text/javascript\"><\/script>");



addLoadEvent(locationmap);

function locationmap() 
{
    if (!document.getElementById) return false;
	//check if the javascript supports document.getElementById 
    if (!document.getElementById("locationMap")) return false;
	//check if there is a page element with the required id

	//define the map coordinate
	var mapLatitude = 53.722400;
	var mapLongitude = -1.684300;
	
	if (GBrowserIsCompatible()) 
    {
        var mapContainer = document.getElementById("locationMap");

		//instanciate GoogleMap
		var map = new GMap2(mapContainer);
        //set map latitude (North) and longitude (East)
		var mapLocation = new GLatLng(mapLatitude, mapLongitude);
		//set map zoom factor
		var mapZoomFactor = 13;
		//set map type - 0 (map), 1 (satellite), 2 (hybrid)
		var mapType = G_DEFAULT_MAP_TYPES[0];
		//set map label
		var mapLabel = "<span style=\"font-size: 11px;\"><strong>Camtex Stone Products</strong><br />Camtex House<br />Quarry Road<br />Gomersal<br />West Yorkshire<br />BD19 4HX<br />UK</span>";
        
        //add location, zoom factor and label to the map
        map.openInfoWindowHtml(mapLocation, mapLabel);
		//add panning, zooming controls
		map.addControl(new GLargeMapControl());
		//add map type (map, sattelite, hybrid) control
		map.addControl(new GMapTypeControl());
		//add marker to map in case user closes the location label
		//map.addOverlay(new GMarker(mapLocation));
		map.setCenter(mapLocation, mapZoomFactor,mapType);
		

		// Our info window content
		var infoTabs = [new GInfoWindowTab("Address:", mapLabel)];

		// Create our marker icon
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);


		// Place a marker in the center of the map and open the info window automatically
		var marker = new GMarker(map.getCenter(), icon);
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowTabsHtml(infoTabs);
		});
		map.addOverlay(marker);
		marker.openInfoWindowTabsHtml(infoTabs);


		// Remove fake map if necessary
		var mapdiv = document.getElementById("locationMap");		
		if(mapdiv)
		{
		    mapdiv.style.background = "none";
		}
    }
}