﻿
var oMapLocation = Class.create()
oMapLocation.prototype = {
	initialize: function(type,name,address,city,state,zip,phone,fax,url,contact)
	{
		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.fax = fax;
		this.url = url;
		this.contact = contact;
		this.marker=null;
		this.infoWindow=null;
		this.point = null;
		this.icon = null;
		this.map = null;
		this.directions = new Array();
		
		this.createInfoWindow();
		this.setIcon();	
		
	},
	getTwoLineAddress: function()
	{
		return this.address+"<br />"+this.city+", "+this.state+" "+this.zip
	},
	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()
	{
		var template = "<h2 style='margin: 0px 0px'>#{name}</h2>\n<div style='margin-left: 20px'>#{address}<br />\n#{city}, #{state} #{zip}<br />\n";
		if (this.phone != null && this.phone != '' && this.phone != '0')
			template += "#{phone}<br />\n";
		if (this.fax!= null && this.fax != '' && this.fax != '0')
			template += "#{fax}(fax)<br />\n";
		template += "</div>";
		if (this.url != null && this.url != '')
			template += "<a href='#{url}'>Visit Website</a><br />";
		if (this.contact !=null && this.contact != '')
			template += "#{contact}<br />";
		template += "<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>";
		template += "<input style='margin: 3px 5px 3px 0px; display: none' id='"+this.id+"fromHotel' onfocus='this.select()' ' value='Type Your Address' />";
		template += "<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 = '#{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>"; 
       		template += select;
       		template += "<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)
       	{
       		template += "<a href='#' onclick='GetDirectionsNew(\""+this.getFullAddress()+"\",\""+this.directions[0].getFullAddress()+"\",true); return false'' >Directions To "+this.directions[0].name+"</a></div>";
       	}
		var myTemplate = new Template(template);
		this.infoWindow = myTemplate.evaluate(this)
	}
}