var iwsMap = {
	init: function() { 
		this.projMap.initMap();
	},
	// the map object
	projMap : {
		assetDir: 'http://integratedwaterservices.com/typo3conf/ext/projmap/assets/img/',
		pins: new Array(),
		initMap: function() {
			if ($('mapDiv') && GBrowserIsCompatible()) {
				// create map object
			    this.map = new GMap2(document.getElementById("mapDiv"));
				var center = new GLatLng(37.0902, -95.7129);			
				this.map.setCenter(center, 4);
				this.map.addControl(new GLargeMapControl());	
				this.map.addControl(new GMapTypeControl());

				var baseIcon = new GIcon();
//				baseIcon.shadow = this.assetDir + 'map_star_shadow.png';
//				baseIcon.iconSize = new GSize(35, 35);
				baseIcon.iconSize = new GSize(15, 35);
//				baseIcon.shadowSize = new GSize(35, 35);
				baseIcon.iconAnchor = new GPoint(7, 32);
				baseIcon.infoWindowAnchor = new GPoint(10, 5);
//				baseIcon.infoShadowAnchor = new GPoint(50, 50);

				// create our pin icons
				this.bluePin = new GIcon(baseIcon);
				this.redPin = new GIcon(baseIcon);
				var iconSize = new GSize(35,35);

//				this.redPin.image = this.assetDir + 'map_star_red.png';
//				this.bluePin.image = this.assetDir + 'map_star_blue.png';
				this.redPin.image = this.assetDir + 'pin_orange.png';
				this.bluePin.image = this.assetDir + 'pin_blue.png';

				this.displayPins();				
			}		
		},
		displayPins: function() {
			this.pins.each(function(pin,index) {
				var color = pin.get('color');
				var lat = pin.get('lat');
				var lng = pin.get('lng');
				var txt = pin.get('txt');
				if ($('mapDiv') && GBrowserIsCompatible()) {
					if(color == 'red') {
						markerOptions = { icon:iwsMap.projMap.redPin};
					}
					if(color == 'blue') {
						markerOptions = { icon:iwsMap.projMap.bluePin};			
					}
					if(color == 'green') {
						markerOptions = { icon:iwsMap.projMap.greenPin};			
					}
					var point = new GLatLng(lat,lng);
					var marker = new GMarker(point,markerOptions);
					var template = new Template('#{text}#{link}');
					
					GEvent.addListener(marker, "click", function() {						
						marker.openInfoWindowHtml(template.evaluate(txt)); // TODO: max width not working. why?
					});
					iwsMap.projMap.map.addOverlay(marker);
				}				
			});
		},
		addPin: function(color,lat,lng,txt) {
			var hash = $H({'color':color,'lat':lat,'lng':lng,'txt':txt});
			this.pins.push(hash);
		}				
	}
};

Element.observe(document, 'dom:loaded', function(){
	iwsMap.init();
});

