﻿var oMapLocation = Class.create()
oMapLocation.prototype = {
	initialize: function(type,name,address,city,state,zip,phone,url)
	{
		this.type = type;
		this.name = name;
		this.id = name.replace(" ","-").camelize();
		this.address = address;
		this.city = city;
		this.state = state;
		this.zip = zip;
		this.phone = phone;
		this.url = url;
		this.marker=null;
		this.infoWindow=null;
		this.point = null;
		this.icon = null;
		this.map = null;
		this.directions = new Array();
		
		this.createInfoWindow();
		this.setIcon();	
	},
	getFullAddress: function()
	{
		return this.address+", "+this.city+", "+this.state+", "+this.zip
	},
	setPoint: function(point)
	{	
		this.point = point;
		//alert(this.name)
		this.createMarker();
	},
	setMap: function (map)
	{
		this.map = map;
	},
	setIcon: function()
	{
		switch(this.type)
		{
			case "hotel":
				this.icon = new GIcon();
				this.icon.image = "lodging.png";
				this.icon.shadow = "lodging_shadow.png";
				this.icon.iconSize = new GSize(35, 34);
				this.icon.iconAnchor = new GPoint(10, 34);
				this.icon.infoWindowAnchor = new GPoint(10, 0);
				break;
			case "airport":
				this.icon = new GIcon();
				this.icon.image = "plane.png"
				this.icon.shadow = "plane_shadow.png";;
				this.icon.iconSize = new GSize(35, 34);
				this.icon.iconAnchor = new GPoint(10, 34);
				this.icon.infoWindowAnchor = new GPoint(10, 0);
				break;
			case "arena":
				this.icon = new GIcon();
				this.icon.image = "event.png";
				this.icon.shadow = "event_shadow.png";
				this.icon.iconSize = new GSize(35, 34);
				this.icon.iconAnchor = new GPoint(5, 34);
				this.icon.infoWindowAnchor = new GPoint(10, 0);
				break;
		}
	},
	addDirections: function(directions)
	{
		this.directions.push(directions);
		this.directions = this.directions.uniq();
		this.createInfoWindow();
	},
	createMarker: function()
	{
		this.marker = new GMarker(this.point, this.icon);
		this.map.addOverlay(this.marker);	
		GEvent.bind(this.marker,"click",this,this.openInfoWindow);
	},
	setMarker: function(marker)
	{
		this.marker = marker;
	},
	removeMarker: function()
	{
		this.map.removeOverlay(this.marker);
	},
	openInfoWindow: function()
	{
		this.marker.openInfoWindowHtml(this.infoWindow);
	},
	createInfoWindow: function()
	{
		this.infoWindow = "<h2 style='margin: 0px 0px'>"+this.name+"</h2>";
       	this.infoWindow += "<div style='margin-left: 20px'>"+this.address+"<br />";
       	this.infoWindow += this.city+", "+this.state+" "+this.zip+"<br />";
       	this.infoWindow += this.phone+"<br />";
       	if (this.url != null)
       		this.infoWindow += "<a href='"+this.url+"'>Visit Website</a></div>";
       	this.infoWindow += "<div style='margin: 10px 0px 20px 0px'><a href='#' onclick='this.style.display=\"none\"; document.getElementById(\""+this.id+"fromHotel\").style.display=\"inline\"; document.getElementById(\""+this.id+"gobtnHotel\").style.display=\"inline\"; document.getElementById(\""+this.id+"fromHotel\").focus(); document.getElementById(\""+this.id+"fromHotel\").select(); return false;'>Get Directions from Me</a>";
       	this.infoWindow += "<input style='margin: 3px 5px 3px 0px; display: none' id='"+this.id+"fromHotel' onfocus='this.select()' ' value='Type Your Address' />";
       	this.infoWindow += "<input style='margin: 3px 5px 3px 0px; display: none' id='"+this.id+"gobtnHotel' type='submit' value='Go' onclick='GetDirectionsNew(document.getElementById(\""+this.id+"fromHotel\").value,\""+this.getFullAddress()+"\",false)' /><br />";
       	if(this.directions.length >1)
       	{
       		var select = "<select id = '"+this.id+"DirectionsSelect'>";
       		for (var i = 0; i < this.directions.length; i++)
       			select += "<option value = '"+this.directions[i].getFullAddress()+"'>"+this.directions[i].name+"</option>";
       		select +="</select>"; 
       		this.infoWindow += select;
       		this.infoWindow += "<input  id='"+this.id+"gobtnSelect' type='submit' value='<-- Directions' onclick='GetDirectionsNew(document.getElementById(\""+this.id+"DirectionsSelect\").value,\""+this.getFullAddress()+"\",true)' /><br />";
       	}
       	else if (this.directions.length == 1)
       	{
       		this.infoWindow += "<a href='#' onclick='GetDirectionsNew(\""+this.getFullAddress()+"\",\""+this.directions[0].getFullAddress()+"\",true); return false'' >Directions To Arena</a></div>";
       	}
       	
	}
	
}