//*******************************************************************
// Google Map Services JavaScript Class Def.
//
//			// (c) 2000-2009 Kappa Solutions Ltd.
//*******************************************************************
//	This class contains utility methods to determine whether a user 
//  is logged in etc. 
//*******************************************************************

var KSL;
if (!KSL) KSL = {};
if (!KSL.Maps) KSL.Maps = {};

KSL.Maps.Workshops = function()
{
	this.points = [
{name:"AERO ALLIANCE Ltd.",place:"Main Terminal Building<br/>Shoreham Airport",town:"Shoreham by Sea",county:"West Sussex",postcode:"BN43 5FF",lat:50.833074, lng:-0.29146}
,{name:"Shoreham Railway Station",place:"",town:"",county:"",postcode:"",lat:50.834443, lng:-0.27174}
]
}

KSL.Maps.LocationMap = function()
{
	this.lat = 50.834443;
	this.lng = -0.27174;
	this.zoom = 9;
	this.addControl = true;
}

KSL.Maps.Workshops.prototype.getMarkerHtml = function(index)
{
	var html = "";
	var point = this.points[index];
	if (index==0)
	{
	    html = ['<b>', point.name, '</b><br/>', 
                 point.place, '<br/>', 
				 point.town, '<br/>', 
				 point.county,'<br/>', 
                 point.postcode,'<br/><br/>', 
                 '<a target="_blank" title="Get directions to Aero Alliance Ltd."'
                 ,'href="http://maps.google.com/maps?z=10&saddr=&daddr='
				 ,point.lat,',',point.lng
				 ,'">Get driving directions</a>'].join('');
	}
	else
	{
	    html = ['<b>', point.name, '</b>'].join(''); 
	
	}
  	return html;
}

KSL.Maps.Workshops.prototype.formatAddress = function(index) {
	var point = this.points[index];

	var address = point.postcode;
	return escape(address.replace(' ', ''));
}


KSL.Maps.MapManager = function (me, canvas, mapSettings, overlay)
{
	this.markers=[];
	if (GBrowserIsCompatible()) 
	{
        this.map = new GMap2(document.getElementById(canvas));
        this.map.setCenter(new GLatLng(mapSettings.lat, mapSettings.lng), mapSettings.zoom);
 
	    // Add control, if required
		if (mapSettings.addControl) this.map.addControl(new GLargeMapControl());
        
		// Add markers to the map
        for (var i = 0; i < overlay.points.length; i++) {
			this.markers[i] = new GMarker(new GLatLng(overlay.points[i].lat, overlay.points[i].lng))
			this.map.addOverlay(this.markers[i]);
			
			//this.markers[i].index = i;
			this.markers[i].popUpHtml =  overlay.getMarkerHtml(i);
			GEvent.addListener(this.markers[i], 'click', function() { return this.openInfoWindowHtml(this.popUpHtml);} );
			
		}

    }
}

KSL.Maps.MapManager.prototype.openInfoWindow = function(index) 
{    
	var marker = this.markers[index];
//	marker.openInfoWindowHtml(marker.popUpHtml);
	
    GEvent.trigger(marker, "click");

}



/**
 * Sets up the gadget by setting CSS and click events.
 */
function xloadMapGadget() {
  containerDiv = document.getElementById('container');
  mapDiv = document.getElementById('map');

  //mapDiv.onclick = function (e) {
  //  clickedX = (window.event && window.event.offsetX) || e.clientX;
  //  clickedY = (window.event && window.event.offsetY) || e.clientY;
    loadScript(); 
  //};

  mapDiv.style.cursor = 'pointer';

  var urlString = ['http://maps.google.com/staticmap?markers='];
  var markerString = [];
  for (var i = 0; i < points.length; i++) {
    markerString.push(points[i].lat + ',' + points[i].lng + ',red');
  }
  urlString.push(markerString.join('|'));
  urlString.push('&size=400x400');
  urlString.push('&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw');
  mapDiv.style.background = 'url(\'' + urlString.join('') + '\')';

}

