// NYU Implementation of Google Maps API
// (rev 7/24/06)
// by Ari Russo (ari.russo@nyu.edu)
//	
// please see the Google Maps api at http://www.google.com/apis/maps/ for guidelines and full API
//
//
// **********************************************************************************
//
	
// NyuMapManager: static singleton object which references the map and all markers 
//                for global use (for instance, in the html of your page) 	
var NyuMapManager =
{
	_markers: [],
	_map:0,
	setMap: function(aMap) { this._map = aMap; },		
	setMarkers: function(anArray) { this._markers = anArray; },
    getMap: function() { return this._map; },
	getMarkers: function() { return this._markers; }, 
	addMarker: function(aMarker) { this.getMarkers().push(aMarker); },
	getMarkerByName: function(theName) {
		for (i=0; i<this.getMarkers().length; i++)
		{
			aMarker = NyuMapManager.getMarkers()[i];
			if (theName == aMarker.getName())
				return aMarker;
		}
	}
};

// NyuMarker class extends (Google) GMarker.  
// On construction, initializes a mouse click event to show arbitrary html (theHtml) when a marker is clicked on.
// usage: new NyuMarker (name, theHtml, theGLatLng)
function NyuMarker ()
{
	args=NyuMarker.arguments; 
	if (args.length == 4) var self = new GMarker(args[2],args[3]); // pseudo constructor overload
	else
		var self = new GMarker(args[2]);
	self._html=args[1];
	self._name=args[0];
	self._visible=true;
	GEvent.addListener(self, "click", function() 
		{ 
			self.openInfoWindowHtml(self.getHtml()); 
		}); 
	self.setHtml = function(theHtml) { self._html = theHtml; };
	self.setName = function(theName) { self._name = theName; };
    self.getHtml = function() { return self._html; };
	self.getName = function() { return self._name; };
	self.setVisible = function(bool) {  
		self._visible = bool; 
		if (!self.isVisible()) 
			self.remove();
		else self.initialize(NyuMapManager.getMap());
	};
	self.isVisible = function() { return self._visible; }
	self.toggleVisible = function() { self.setVisible(!self.isVisible()); };
	self.focusOnMe = function ()
	{
		NyuMapManager.getMap().setCenter(self.getPoint(), 16);
		self.openInfoWindowHtml(self.getHtml());	
	};
	return self;
}
	
// NyuCustomIconMarker class extends NyuMarker
// the same as NyuMarker but displays a custom icon
function NyuCustomIconMarker ( theName, theHtml, theGLatLng, customIcon, group)
{
    var customIcon;
	//var customIcon = new GIcon();
 	//customIcon.image = iconUrl; 
	//customIcon.iconSize = new GSize(28, 47);
	//customIcon.iconAnchor = new GPoint(1, 47);
	//customIcon.infoWindowAnchor = new GPoint(5, 1); 
	//var self = new NyuMarker(theName, theHtml, theGLatLng,customIcon); 

    switch(group)    {        case "visit":       customIcon = customIconBlue;                            break;            case "school":      customIcon = customIconRed;                            break;
        case "photo":       customIcon = customIconGreen;                            break;            case "residence":   customIcon = customIconOrange;                            break;            case "misc":        customIcon = customIconGray;                            break;            default:            customIcon = customIconBlue;    }
	
	var self = new NyuMarker(theName, theHtml, theGLatLng, customIcon);
		return self;
}


 
// NyuMap class extends (google) GMap2
// has convenience methods for adding additional NyuMarkers
function NyuMap (container) 
{
	var self = new GMap2(container);
    		
	self.addMarker = function ( theName, lat, lng, theHtml ) 
	{
		var aMarker = new NyuMarker( theName,theHtml, new GLatLng(lat,lng));
		self.addOverlay(aMarker);
		NyuMapManager.addMarker(aMarker);  	
    };
		
	self.addCustomIconMarker = function ( theName, lat, lng, theHtml, iconUrl, group ) 
	{
		var aMarker = new NyuCustomIconMarker( theName, theHtml, new GLatLng(lat,lng), iconUrl, group );
		self.addOverlay(aMarker);
		NyuMapManager.addMarker(aMarker);
	};
		
	return self;	
}

// utility method for focusing (zooming in) on a marker in a way that reduces the amount of html code necessary
function focusOnMarker(markerName)
{
	aMarker = NyuMapManager.getMarkerByName(markerName);
	aMarker.focusOnMe();
}

var customIconBlue = new GIcon();
customIconBlue.image = "../images/custom.marker.blue.png";
customIconBlue.iconSize = new GSize(15, 27);
customIconBlue.shadowSize = new GSize(1, 1);
//customIconBlue.iconAnchor = new GPoint(5, 17);
customIconBlue.iconAnchor = new GPoint(6, 22);
//customIconBlue.iconAnchor = new GPoint(0, 0);
customIconBlue.infoWindowAnchor = new GPoint(6, 4);
customIconBlue.infoShadowAnchor = new GPoint(9, 13);	 

var customIconRed = new GIcon();
customIconRed.image = "../images/custom.marker.red.png";
customIconRed.iconSize = new GSize(15, 27);
customIconRed.shadowSize = new GSize(1, 1);
//customIconRed.iconAnchor = new GPoint(5, 17);
customIconRed.iconAnchor = new GPoint(16, 22);
// customIconRed.iconAnchor = new GPoint(0, 0);
customIconRed.infoWindowAnchor = new GPoint(6, 4);
customIconRed.infoShadowAnchor = new GPoint(9, 13);	 

var customIconGreen = new GIcon();
customIconGreen.image = "../images/custom.marker.green.png";
customIconGreen.iconSize = new GSize(15, 27);
customIconGreen.shadowSize = new GSize(1, 1);
customIconGreen.iconAnchor = new GPoint(5, 17);
customIconGreen.iconAnchor = new GPoint(6, 22);
customIconGreen.iconAnchor = new GPoint(0, 0);
customIconGreen.infoWindowAnchor = new GPoint(16, 4);
customIconGreen.infoShadowAnchor = new GPoint(9, 13);	

var customIconOrange = new GIcon();
customIconOrange.image = "../images/custom.marker.orange.png";
customIconOrange.iconSize = new GSize(15, 27);
customIconOrange.shadowSize = new GSize(1, 1);
customIconOrange.iconAnchor = new GPoint(5, 17);
customIconOrange.iconAnchor = new GPoint(6, 22);
customIconOrange.iconAnchor = new GPoint(0, 0);
customIconOrange.infoWindowAnchor = new GPoint(6, 4);
customIconOrange.infoShadowAnchor = new GPoint(9, 13);	

var customIconGray = new GIcon();
customIconGray.image = "../images/custom.marker.gray.png";
customIconGray.iconSize = new GSize(15, 27);
customIconGray.shadowSize = new GSize(1, 1);
customIconGray.iconAnchor = new GPoint(5, 17);
customIconGray.iconAnchor = new GPoint(6, 22);
customIconGray.iconAnchor = new GPoint(0, 0);
customIconGray.infoWindowAnchor = new GPoint(6, 4);
customIconGray.infoShadowAnchor = new GPoint(9, 13);	 

			