
var Map = Class.create();
Map.prototype = {
	initialize: function(options) {
		this.locale = "en_AU";
		this.markerManager = null;
		this.bounds = null;
		this.isBusy = false;
		this.icons = null;
		this.options = {
			baseURL: '../',
			canvas: 'map-google-airport',
			latitude: -37.25243661002686,
			longitude: 144.9009132385254,
			zoom: 14,
			useSmallMapControl: true,
			useLargeMapControl: false,
			useMapTypeControl: true,
			useMapOverviewControl: false,
			enableDragging: true
		};
		Object.extend(this.options, options || {});
		
		if (typeof("GBrowserIsCompatible") != "undefined") {
			if (GBrowserIsCompatible()) {
				this.registerEvents();
			}
		}
	},
	
	registerEvents: function() {
		// CREATE MAP
		this.mapControl = new GMap2($(this.options.canvas));
 //       this.mapControl.setCenter(new GLatLng(this.options.latitude, this.options.longitude), parseInt(this.options.zoom));
        this.mapControl.setCenter(new GLatLng(this.options.latitude, this.options.longitude), parseInt(this.options.zoom));
        Event.observe(window, 'unload', GUnload);
        
		// Include small map control
        if (this.options.useSmallMapControl) {
			this.mapControl.addControl(new GSmallMapControl());
        }
        
        if (this.options.useLargeMapControl) {
			this.mapControl.addControl(new GLargeMapControl());
        }
        
        // Include satellite/hybrid/map views
        if (this.options.useMapTypeControl) {
			this.mapControl.addControl(new GMapTypeControl());
        }
        
        // Disable dragging?
        if (!this.options.enableDragging) {
			//this.mapControl.disableDragging();
        }
        else
        {
        	
        }
        this.mapControl.enableDragging();
        // create icons	
        if (this.options.canvas == "map-google-airport")
        {
			this.createIcons();	
        }
	},
	
	createIcons: function()
	{
		this.icons = new Array();
		this.icons[0] = new GIcon();
		this.icons[0].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/autocentro.png";
		this.icons[0].iconsize = new GSize(46, 40);
		this.icons[0].iconAnchor = new GPoint(23, 38);
		this.icons[0].infoWindowAnchor = new GPoint(23, 4);

		this.icons[1] = new GIcon();
		this.icons[1].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/dfo-homemaker.png";
		this.icons[1].iconSize = new GSize(46, 40);
		this.icons[1].iconAnchor = new GPoint(23, 38);
		this.icons[1].infoWindowAnchor = new GPoint(23, 4);

/*
		this.icons[2] = new GIcon();
		this.icons[2].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/police-airwing.png";
		this.icons[2].iconSize = new GSize(46, 40);
		this.icons[2].iconAnchor = new GPoint(23, 38);
		this.icons[2].infoWindowAnchor = new GPoint(23, 4);

		this.icons[3] = new GIcon();
		this.icons[3].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/rfds.png";
		this.icons[3].iconSize = new GSize(46, 40);
		this.icons[3].iconAnchor = new GPoint(23, 38);
		this.icons[3].infoWindowAnchor = new GPoint(23, 4);
*/
		this.icons[2] = new GIcon();
		this.icons[2].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/linfox.png";
		this.icons[2].iconSize = new GSize(46, 40);
		this.icons[2].iconAnchor = new GPoint(23, 38);
		this.icons[2].infoWindowAnchor = new GPoint(23, 4);

		this.icons[3] = new GIcon();
		this.icons[3].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/coles.png";
		this.icons[3].iconSize = new GSize(46, 40);
		this.icons[3].iconAnchor = new GPoint(23, 38);
		this.icons[3].infoWindowAnchor = new GPoint(23, 4);
				
		this.icons[4] = new GIcon();
		this.icons[4].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/museum.png";
		this.icons[4].iconSize = new GSize(46, 40);
		this.icons[4].iconAnchor = new GPoint(23, 38);
		this.icons[4].infoWindowAnchor = new GPoint(23, 4);	

		this.icons[5] = new GIcon();
		this.icons[5].image = "http://staging.lemonade.com.au/essendonairport/images/googlemaps/ess-fields.png";
		this.icons[5].iconSize = new GSize(46, 55);
		this.icons[5].iconAnchor = new GPoint(23, 38);
		this.icons[5].infoWindowAnchor = new GPoint(23, 4);
			
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.71943715831719, 144.89601844482422), "Auto Centro - Wirraway Road, Essendon Fields<br />Essendon Fields House", 0));
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.73248859507666, 144.9068064025879), "DFO Essendon - 100 Bulla Rd, Strathmore, VIC 3041", 1));
/*
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.718556378467014, 144.89271640777588), "Police Airwing", 2));
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.72103447742806, 144.89456176757812), "Royal Flying Doctors", 3));
*/		
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.72550971693058, 144.89721722259521), "Linfox - 55 English St, Essendon Fields", 2));
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.72746378467014, 144.89581640777588), "Coles Supermarket - 30 English St, Essendon Fields", 3));
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.72381171693058, 144.89721722259521), "Airways Museum", 4));		
		this.mapControl.addOverlay(this.createMarker(new GLatLng(-37.72500971693058, 144.89331722259521), "Essendon fields - Level 2, 7 Engligh St, Essendon Fields", 5));		
	},
	
	createMarker: function(point, description, iconIndex) {
		// Set up our GMarkerOptions object
//		markerOptions = { icon:this.icons[iconIndex], zIndexProcess:iconIndex};
		markerOptions = { icon:this.icons[iconIndex]};
		var marker = new GMarker(point, markerOptions);

		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<br>" + description + "</b>");
		});
		return marker;
	}
};