	var currentOffice = 0;
	function showMap(index)
	{
		elm = $("#map" + index).parent();
		if(elm == currentOffice)
			return false;
		var company = $(elm).find(".headingText").html();
		var streetAddress = $(elm).find(".street-address").html();
		var locality = $(elm).find(".locality").html();
		var postalCode = $(elm).find(".postal-code").html();
		var imageSrc = $(elm).find(".officeImage").attr("src");
		var imageAlt = $(elm).find(".officeImage").attr("alt");
		
		$("#map" + index + " h4").remove();
		$("#map" + index).append("<h4>" + streetAddress + ", " + locality + "<span onclick='hideMap()'><span>Close</span></span></h4>");
		$("#map" + index).append($("#map_canvas"));
		if(currentOffice)
		{
            $(".mapOn .mapArea").hide();
			//$(".mapOn .showMap").css("opacity", "1");
			$(".mapOn .showMap").show();
			$("#map" + index).show();
			//$("#map" + index).parent().find(".showMap").css("opacity", "0");
			$("#map" + index).parent().find(".showMap").hide();
		}
		else
		{
			$(".showMap:first").hide();
		}
		var address = streetAddress + ", " + locality + ", " + getCountry();
		
		var infoWindowContent = "";
		
		if(imageSrc)
			infoWindowContent = "<img src='" + imageSrc + "' class='companyImage' alt='" + imageAlt + "'>";
		
		infoWindowContent += "<h5>" + company + "</h5><p><strong>" + locality + "</strong></p><p>" + streetAddress + "<br/>" + postalCode + " " + locality + "</p>";
		showAddress(address, infoWindowContent);
		
		$(".mapOn").removeClass("mapOn");
		$(elm).addClass("mapOn");
		currentOffice = elm;
	}
	
	
	var map;
	var geocoder;
	var gdir;
	var directionsPanel;
	var address;
	onload = function initialize()
	{
		if (GBrowserIsCompatible())
		{
			map = new GMap2(document.getElementById("map_canvas"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			geocoder = new GClientGeocoder();
			showMap(1);
		}
	}
	

	var baseIcon = new GIcon();
	baseIcon.iconSize = new GSize(47, 43);
	baseIcon.shadowSize = new GSize(37, 43);
	baseIcon.iconAnchor = new GPoint(23, 35);
	baseIcon.infoWindowAnchor = new GPoint(120, 120);

	// Creates a marker whose info window displays the letter corresponding
	// to the given index.
	function createMarker(point)
	{
		// Create a lettered icon for this point using our icon class
		var eonIcon = new GIcon(baseIcon);
		eonIcon.image = "http://demo.kan.se/eon/images/eon2/eonMarker.png";
		// Set up our GMarkerOptions object
		markerOptions = { icon:eonIcon };
		var marker = new GMarker(point, markerOptions);
		return marker;
	}
	
	
	function showAddress(address, infoWindowContent)
	{
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert(address + " not found");
					} else {
						map.setCenter(point, 15);
						var marker = createMarker(point);

						var infoWindowHtml = infoWindowContent;

						map.addOverlay(marker);
						
						var infoWindow = map.getInfoWindow();
						
						GEvent.addListener(marker,"click", function() {
							map.openInfoWindowHtml(marker.getLatLng(),infoWindowHtml, {pixelOffset: new GSize(10,-20), maxWidth: 200});
						});
						
						map.openInfoWindowHtml(marker.getLatLng(),infoWindowHtml, {pixelOffset: new GSize(10,-20), maxWidth: 200});
						
						var infoWindow = map.getInfoWindow();
					}
				}
			);
		}
	}
		
		
	function handleErrors(){
		if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
			alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
			alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
		else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
			alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		else if (gdir.getStatus().code == G_GEO_BAD_KEY)
			alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
		else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
			alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		else alert("An unknown error occurred.");
	}
	
	function hideMap(index)
	{
		$(".mapOn").removeClass("mapOn");
	}
	
	function getCountry() 
	{
        var metas = document.getElementsByTagName('META');
        var i;
        for (i = 0; i < metas.length; i++)
            if (metas[i].getAttribute('NAME') == "country")
        break;
        var TestVar = metas[i].getAttribute('CONTENT');
        return TestVar;
    }

