/**
 * Mapping Base Class
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.js
*/

var Mapping = {
	Version: 0.5
}
Mapping.Console = {}
Mapping.Console.Levels = {None: 1<<1,Info: 1<<2,Warn: 1<<3,Debug: 1<<4,Error: 1<<5}
Mapping.Console.Levels.All = Mapping.Console.Levels.Info+Mapping.Console.Levels.Warn+Mapping.Console.Levels.Debug+Mapping.Console.Levels.Error;
Mapping.Console.CurrentLevel = 1<<4;
Mapping.Console.debug = function(msg){
	if ((Mapping.Console.CurrentLevel & Mapping.Console.Levels.Debug) != 0) {
		Try.these(
		function(){console.debug(msg);},
		function(){alert(msg.toString());},
		function(){alert(msg);}
		);
	}
}
Mapping.Console.error = function(msg){
	if ((Mapping.Console.CurrentLevel & Mapping.Console.Levels.Error) != 0) {
		Try.these(function(){console.error(msg);},function(){alert(msg.toString());},function(){alert(msg);});
	}
}
Mapping.Console.info = function(msg){
	if ((Mapping.Console.CurrentLevel & Mapping.Console.Levels.Info) != 0) {
		Try.these(function(){console.info(msg);},function(){alert(msg.toString());},function(){alert(msg);});
	}
}
Mapping.Console.warn = function(msg){
	if ((Mapping.Console.CurrentLevel & Mapping.Console.Levels.Warn) != 0) {
		Try.these(function(){console.warn(msg);},function(){alert(msg.toString());},function(){alert(msg);});
	}
}/**
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.Config.js
*/

Mapping.Config = {}
Mapping.Config.icons = {
	//Zoom Levels - Smaller the number the farther out
	zoomLevels: {
		tier1: 9,
		tier2: 13,
		tier3: 19
	}
}
Mapping.Config.urls = {
	mediaServer: 'http://rubloff.media.vlmc/maps/icon/',
	staticMapServer: 'http://maps.activewebsite.com/maps/static/'
}
Mapping.Config.map = {
	failSafeZoom: 10,
	failSafeLatLng: {
		lat: 0,
		lng: 0
	}
}
Mapping.Config.zoom = {
	areas: new Array()
}
/**
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.Icons.js
*/

Mapping.Icons = {}
Mapping.Icons.Sizes = {
	Large: 'l',
	Medium: 'm',
	Small: 's'
}
Mapping.Icons.Icon = Class.create({
	initialize: function(name,level1, level2, level3, hover){
		this.name = name;
		this.level1 = level1; //Far
		this.level2 = level2; //Mid
		this.level3 = level3; //Near
		this.hover = hover;
	},
	clone: function(name, level1, level2, level3, hover){
		if(name == null){name = this.name;}
		if(level3 == null){level1 = Object.clone(this.level1);}
		if(level3 == null){level2 = Object.clone(this.level2);}
		if(level3 == null){level3 = Object.clone(this.level3);}
		if(hover == null) {hover = Object.clone(this.hover);}
		return new Mapping.Icons.Icon(name, level1, level2, level3, hover);
	},
	getLevel1: function(string){
		return this._ChangeIcon(this.level1, Mapping.Icons.Sizes.Small, string);
	},
	getLevel2: function(string){
		return this._ChangeIcon(this.level2, Mapping.Icons.Sizes.Medium, string);
	},
	getLevel3: function(string){
		return this._ChangeIcon(this.level3, Mapping.Icons.Sizes.Large, string);
	},
	getHover1: function(string){
		return this._ChangeIcon(this.level2, Mapping.Icons.Sizes.Small, string, true);
	},
	getHover2: function(string){
		return this._ChangeIcon(this.level3, Mapping.Icons.Sizes.Medium, string, true);
	},
	getHover3: function(string){
		return this._ChangeIcon(this.hover, Mapping.Icons.Sizes.Large, string, true);
	},
	getResultURL: function(string, size){
		return Mapping.Config.urls.mediaServer+"/"+this.name+"/r/"+size+"/"+string;
	},
	_ChangeIcon: function(set, size, string, isHover){
		var iconType = 'n';
		if(string == null){string = '';}
		if(isHover == true){iconType = 'h';}
		
		var icon = new google.maps.Icon(google.maps.DEFAULT_ICON);
		icon.printShadow = '';
		icon.image = Mapping.Config.urls.mediaServer+"/"+this.name+"/"+iconType+"/"+size+"/"+string;
		icon.shadow = Mapping.Config.urls.mediaServer+"/"+this.name+"/s/"+size;
		icon.printImage = Mapping.Config.urls.mediaServer+"/"+this.name+"/p/"+size+"/"+string;
		icon.mozPrintImage = Mapping.Config.urls.mediaServer+"/"+this.name+"/p/"+size+"/"+string;
		icon.transparent = Mapping.Config.urls.mediaServer+"/"+this.name+"/t/"+size+"/"+string;
		
		icon.iconSize = new google.maps.Size(set.width, set.height);
		icon.shadowSize = new google.maps.Size(set.sWidth, set.sHeight);
		icon.iconAnchor = new google.maps.Point(set.anchor.x, set.anchor.y);
		
		if (set.window.x != null && set.window.y != null) {
			icon.infoWindowAnchor = new google.maps.Point(set.window.x, set.window.y);
		}
		if (set.imageMap != null) {
			icon.imageMap = set.imageMap;
		}
		return icon;
	}
});
/* Base Icon Def Example
{
	width:, height:,
	sWidth:, sHeight:,
	anchor: {x:, y:},
	window: {x:, y:},
	imageMap: new Array()
}
*/
Mapping.Icons.NewProp = new Mapping.Icons.Icon('new',{
	width:16, height:19,
	sWidth:38, sHeight:19,
	anchor: {x:8, y:18},
	window: {x:8, y:0}, 
	imageMap: new Array(0,7, 7,0, 15,7, 13,14, 8,18, 3,14)
},{
	width:26, height:31,
	sWidth:54, sHeight:31,
	anchor: {x:12, y:30},
	window: {x:12, y:0},
	imageMap: new Array(0,12, 12,0, 24,11, 20,23, 12,30, 4,23)
},{
	width:33, height:39,
	sWidth:65, sHeight:39,
	anchor: {x:15, y:38},
	window: {x:15, y:0},
	imageMap: new Array(1,15, 15,0, 32,15, 26,27, 15,38, 5,28)
},{
	width:39, height:46,
	sWidth:65, sHeight:39,
	anchor: {x:19, y:45},
	window: {x:19, y:0},
	imageMap: new Array(1,17, 20,0, 37,17, 30,34, 19,45, 6,33)
});
Mapping.Icons.CNewProp = Mapping.Icons.NewProp.clone('cnew');
Mapping.Icons.UpdatedProp = Mapping.Icons.NewProp.clone('updated');
Mapping.Icons.CUpdatedProp = Mapping.Icons.NewProp.clone('cupdated');
Mapping.Icons.OldProp = Mapping.Icons.NewProp.clone('old');
Mapping.Icons.COldProp = Mapping.Icons.NewProp.clone('cold');
Mapping.Icons.RecentProp = Mapping.Icons.NewProp.clone('recent');
Mapping.Icons.CRecentProp = Mapping.Icons.NewProp.clone('crecent');
Mapping.Icons.OpenHouse = new Mapping.Icons.Icon('openhouse',{
	width:16, height:19,
	sWidth:38, sHeight:19,
	anchor: {x:8, y:18},
	window: {x:8, y:0}, 
	imageMap: new Array(0,7, 7,0, 15,7, 13,14, 8,18, 3,14)
},{
	width:26, height:31,
	sWidth:54, sHeight:31,
	anchor: {x:12, y:30},
	window: {x:12, y:0},
	imageMap: new Array(0,12, 12,0, 24,11, 20,23, 12,30, 4,23)
},{
	width:33, height:39,
	sWidth:65, sHeight:39,
	anchor: {x:15, y:38},
	window: {x:15, y:0},
	imageMap: new Array(1,15, 15,0, 32,15, 26,27, 15,38, 5,28)
},{
	width:39, height:46,
	sWidth:65, sHeight:39,
	anchor: {x:19, y:45},
	window: {x:19, y:0},
	imageMap: new Array(1,17, 20,0, 37,17, 30,34, 19,45, 6,33)
});

Mapping.Icons.GenericOrange = new Mapping.Icons.Icon('gorange',{
	width:16, height:18,
	sWidth:38, sHeight:18,
	anchor: {x:8, y:17},
	window: {x:7, y:0}, 
	imageMap: new Array(1,1, 15,1, 15,14, 10,14, 8,17, 5,14, 1,14)
},{
	width:25, height:29,
	sWidth:52, sHeight:29,
	anchor: {x:13, y:27},
	window: {x:13, y:0},
	imageMap: new Array(1,1, 23,1, 24,22, 17,22, 12,27, 7,22, 1,21)
},{
	width:32, height:37,
	sWidth:63, sHeight:37,
	anchor: {x:16, y:34},
	window: {x:15, y:0},
	imageMap: new Array(0,14, 15,0, 28,4, 32,15, 27,28, 15,38, 5,28)
},{
	width:38, height:44,
	sWidth:63, sHeight:37,
	anchor: {x:19, y:41},
	window: {x:19, y:0},
	imageMap: new Array(2,2, 36,2, 36,34, 26,34, 19,41, 12,34, 2,33)
});
Mapping.Icons.GenericBlue = Mapping.Icons.GenericOrange.clone('gblue');
Mapping.Icons.GenericGreen = Mapping.Icons.GenericOrange.clone('ggreen');
Mapping.Icons.GenericYellow = Mapping.Icons.GenericOrange.clone('gyellow');
Mapping.Icons.Development = Mapping.Icons.GenericOrange.clone('development');

Mapping.Icons.LittleMan = new Mapping.Icons.Icon('littleman',{
	width:10, height:17,
	sWidth:31, sHeight:17,
	anchor: {x:5, y:17},
	window: {x:5, y:0}, 
	imageMap: new Array(0,8, 3,1, 7,1, 9,8, 6,16, 3,16)
},{
	width:16, height:28,
	sWidth:43, sHeight:28,
	anchor: {x:8, y:28},
	window: {x:8, y:0},
	imageMap: new Array(0,14, 4,0, 10,0, 15,4, 10,27, 4,27)
},{
	width:20, height:35,
	sWidth:50, sHeight:35,
	anchor: {x:10, y:35},
	window: {x:10, y:0},
	imageMap: new Array(0,17, 5,0, 14,0, 19,16, 14,34, 5,34)
},{
	width:24, height:42,
	sWidth:50, sHeight:35,
	anchor: {x:12, y:42},
	window: {x:12, y:0},
	imageMap: new Array(0,17, 5,0, 14,0, 19,16, 14,34, 5,34)
});
Mapping.Icons.POI_Health = new Mapping.Icons.Icon('poi_health',{
	width:16, height:28,
	sWidth:43, sHeight:28,
	anchor: {x:8, y:28},
	window: {x:8, y:0},
	imageMap: new Array(8,0, 16,5, 8,28, 0,5)
},{
	width:26, height:45,
	sWidth:60, sHeight:45,
	anchor: {x:13, y:45},
	window: {x:13, y:0},
	imageMap: new Array(13,0, 26,10, 13,45, 0,10)
},{
	width:33, height:57,
	sWidth:73, sHeight:57,
	anchor: {x:16.5, y:57},
	window: {x:16.5, y:0}, 
	imageMap: new Array(16.5,0, 33,13, 16.5,57, 0,13)
},{
	width:39, height:68,
	sWidth:73, sHeight:57,
	anchor: {x:20, y:68},
	window: {x:20, y:0}, 
	imageMap: new Array(20,0, 39,13, 20,68, 0,13)
});
Mapping.Icons.POI_Dining = Mapping.Icons.POI_Health.clone('poi_dining');
Mapping.Icons.POI_Shopping = Mapping.Icons.POI_Health.clone('poi_shopping');
Mapping.Icons.POI_Sports = Mapping.Icons.POI_Health.clone('poi_sports');
Mapping.Icons.POI_Government = Mapping.Icons.POI_Health.clone('poi_government');
Mapping.Icons.POI_Travel = Mapping.Icons.POI_Health.clone('poi_travel');
Mapping.Icons.POI_School = Mapping.Icons.POI_Health.clone('poi_school');
Mapping.Icons.POI_Entertainment = Mapping.Icons.POI_Health.clone('poi_entertainment');
Mapping.Icons.POI_General = Mapping.Icons.POI_Health.clone('poi_general');/**
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.Pushpin.js
*/

Mapping.Pushpin = {}
Mapping.Pushpin.Manager = Class.create({
	initialize: function(){
		this.markers = new Array();
		this.zoomLevel = null;
		
		this.map = Mapping.Map.I();
		this.zoomEvent = this.map.addEvent('zoomend', function(){this.mapZoom();}.bind(this));
	},
	mapZoom: function(){
		var zoom = Number(this.map.map.getZoom());
		
		if(this.zoomLevel == null){
			this.zoomLevel = zoom;
			this.updateZoom(zoom);
		} else if(zoom != this.zoomLevel){
			if(zoom >= 0 && zoom <= Mapping.Config.icons.zoomLevels.tier1 && this.zoomLevel >= 0 && this.zoomLevel <= Mapping.Config.icons.zoomLevels.tier1){
				//Do nothing Still in the same zone 1
			} else if(zoom > Mapping.Config.icons.zoomLevels.tier1 && zoom <= Mapping.Config.icons.zoomLevels.tier2 && this.zoomLevel > Mapping.Config.icons.zoomLevels.tier1 && this.zoomLevel <= Mapping.Config.icons.zoomLevels.tier2) {
				//Do nothing Still in the same zone 2
			} else if(zoom > Mapping.Config.icons.zoomLevels.tier2 && zoom <= Mapping.Config.icons.zoomLevels.tier3 && this.zoomLevel > Mapping.Config.icons.zoomLevels.tier2 && this.zoomLevel <= Mapping.Config.icons.zoomLevels.tier3) {
				//Do nothing Still in the same zone 3
			} else {
				this.updateZoom(zoom);
			}
			this.zoomLevel = zoom;
		}
	},
	updateZoom: function(zoom){
		this.markers.each(function(iter){
			iter.updateIcon(zoom);
		});
	},
	addMarker: function(marker){
		this.markers[this.markers.length] = marker;
	},
	removeMarker: function(marker){
		var index = this.markers.indexOf(marker);
		if (index != -1) {
			this.markers[index] = null;
			this.markers = this.markers.compact();
		}
	}
});
Mapping.Pushpin.Manager.Instance = null;
Mapping.Pushpin.Manager.I = function(){
	if(Mapping.Pushpin.Manager.Instance == null){Mapping.Pushpin.Manager.Instance = new Mapping.Pushpin.Manager();}
	return Mapping.Pushpin.Manager.Instance;
}

Mapping.Pushpin.Pushpin = Class.create({
	initialize: function(point, iconStr, html, iconSet, iconOptions){
		this.html = html; //HTML to display as Tabs
		this.iconStr = iconStr; //Text to overlay over the icon
		this.point = point; //Location to place the icon
		this.iconSet = iconSet; //What icon set to use. Instance of Mapping.Icons.Icon
		
		if(this.iconSet != null){
			this.icon = this.iconSet.getLevel3(this.iconStr);
		} else {
			this.icon = new google.maps.Icon(google.maps.DEFAULT_ICON);
		}
		
		this.iconOptions = iconOptions;
		MarkerOptions = {icon:this.icon}
		Object.extend(MarkerOptions, this.iconOptions || {});
		
		this.pushpin = new google.maps.Marker(this.point, MarkerOptions);
		this.map = Mapping.Map.I();
		this.extendedEvents = new Array();
		this.isHover = false;
		Mapping.Pushpin.Manager.I().addMarker(this);
		
		this.addEvent('click', function(latLng){
			this.iconClick();
		}.bind(this));
		
		this.addEvent('infowindowopen', function(){
			this._windowOpened();
		}.bind(this));
		
//		this.addEvent('mouseout', function(latLng){
//			console.debug('UnHover');
//			this.unhover();
//		}.bind(this));
//		
//		this.addEvent('mouseover', function(latLng){
//			console.debug('Hover');
//			this.hover();
//		}.bind(this));
		
	},
	changeIconSet: function(iconSet){
		this.iconSet = iconSet;
		if(this.iconSet != null){
			this.icon = this.iconSet.getLevel3(this.iconStr);
		} else {
			this.icon = new google.maps.Icon(google.maps.DEFAULT_ICON);
		}
		this.updateIcon(this.map.map.getZoom());
	},
	setPoint: function(point){
		this.pushpin.setLatLng(point);
		this.point = point;
	},
	setHTML: function(html){
		this.html = html;
	},
	showWindow: function(){
		if (this.html != null && this.html != '') {
			if ($E.isArray(this.html)) {
				if ($E.isString(this.html[0])) {
					this.pushpin.openInfoWindowTabsHtml(this.html);
				}
				else {
					this.pushpin.openInfoWindowTabs(this.html);
				}
			} else if($E.isString(this.html)){
				this.pushpin.openInfoWindowHtml(this.html);
			} else {
				this.pushpin.openInfoWindow(this.html);
			}
		}
	},
	hideWindow: function(){
		this.pushpin.closeInfoWindow();
	},
	_windowOpened: function(){
		$$('img.LazyLoadImg').each(function(image){
			image.src = image.attributes['imageSrc'].nodeValue;
		});
	},
	del: function(){
		this.extendedEvents.each(function(iter){google.maps.Event.removeListener(iter.event);});
		this.map.map.removeOverlay(this.pushpin);
		this.pushpin = null;
		Mapping.Pushpin.Manager.I().removeMarker(this);
	},
	add: function(){
		this.map.map.addOverlay(this.pushpin);
		this.updateIcon(this.map.map.getZoom());
	},
	/**
	 * Add() must be called before you can show/hide an icon.
	 */
	show: function(){
		this.pushpin.show();
		this.updateIcon(this.map.map.getZoom());
	},
	hide: function(){
		this.pushpin.hide();
	},
	isHidden: function(){
		return this.pushpin.isHidden();
	},
	updateIcon: function(zoom){
		if (!this.isHidden() && this.iconSet != null) {
			if(zoom <= Mapping.Config.icons.zoomLevels.tier1){
				if (!this.isHover) {
					this.icon = this.iconSet.getLevel1(this.iconStr);
				} else {
					this.icon = this.iconSet.getHover1(this.iconStr);
				}
			} else if(zoom <= Mapping.Config.icons.zoomLevels.tier2){
				if (!this.isHover) {
					this.icon = this.iconSet.getLevel2(this.iconStr);
				} else {
					this.icon = this.iconSet.getHover2(this.iconStr);
				}
			} else {
				if (!this.isHover) {
					this.icon = this.iconSet.getLevel3(this.iconStr);
				} else {
					this.icon = this.iconSet.getHover3(this.iconStr);
				}
			}
			try {
				this.extendedEvents.each(function(iter){google.maps.Event.removeListener(iter.event);});
				this.map.map.removeOverlay(this.pushpin);
				
				MarkerOptions = {icon:this.icon}
				Object.extend(MarkerOptions, this.iconOptions || {});
				this.pushpin = new google.maps.Marker(this.point, MarkerOptions);
				this.map.map.addOverlay(this.pushpin);
				this._rebuildEvents();
			} catch(e){}
		}
	},
	getResultIconURL: function(size){
		return this.iconSet.getResultURL(this.iconStr, size);
	},
	hover: function(){
		this.isHover = true;
		this.updateIcon(Number(this.map.map.getZoom()));
	},
	unhover: function(){
		this.isHover = false;
		this.updateIcon(Number(this.map.map.getZoom()));
	},
	
	/*
	 * Events
	 */
	
	iconClick: function(){
		this.showWindow();
	},
	addEvent: function(event, callback){
		var tEvent = google.maps.Event.addListener(this.pushpin, event, callback);
		this.extendedEvents[this.extendedEvents.length] = {
			event: tEvent,
			eventStr: event,
			callback: callback
		};
		return tEvent;
	},
	_rebuildEvents: function(){
		this.extendedEvents.each(function(event){
			var newEvent = google.maps.Event.addListener(this.pushpin, event.eventStr, event.callback);
			event.event = newEvent;
		}.bind(this));
	}
});/**
 * @author Nick Verbeck
 * @since 9/17/2009
 * @file Mapping.Signal.js
 * 
 * Yes, This is not a true Signal design but more an event manager. 
 * I just likes the name better and it emplied more what I was trying to do
 */

Mapping.Signal = Class.create({
	initialize: function(){
		this.signals = new Array();
	},
	observe: function(event, callback){
		return this.connect(event, callback);
	},
	connect: function(event, callback){
		if(this.signals[event] == null){
			this.signals[event] = new Array();
		}
		this.signals[event][this.signals[event].length] = callback;
		
		return this.signals[event].length-1;
	},
	emit: function(event, sEvent){
		Mapping.Console.info('Emit: '+ event);
		sEvent.event = event;
		if(this.signals[event] != null){
			this.signals[event].each(function(callback){
				callback(sEvent);
			});
		}
	},
	stopObserve: function(event, eventID){
		this.disconnect(event, eventID);
	},
	disconnect: function(event, eventID){
		if (this.signals[event] != null) {
			this.signals[event][eventID] = Prototype.emptyFunction;
		}
	}
});
Mapping.Signal.Instance = null;
Mapping.Signal.I = function(){
	if(Mapping.Signal.Instance == null){Mapping.Signal.Instance = new Mapping.Signal();}
	return Mapping.Signal.Instance;
}/**
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.Map.js
*/
Mapping.Map = Class.create({
	initialize: function(div, center, zoom, callback, autoLoadMap){
		if(center == null){center = {Latitude: Mapping.Config.map.failSafeLatLng.lat, Longitude:Mapping.Config.map.failSafeLatLng.lng}}
		if(zoom == null){zoom = Number(Mapping.Config.map.failSafeZoom);}
		if(autoLoadMap == null){autoLoadMap=true;}
		
		this.loadOptions = {
			div: div,
			center: center,
			zoom: zoom,
			callback: callback
		}
		
		google.load("maps", "2");
		google.load("search", "1");
		
		if (autoLoadMap) {
			google.setOnLoadCallback(function(){this.mapInitialize();}.bind(this));
		}
		
		Event.observe(window, 'unload', this.unLoadMap.bindAsEventListener(this));
	},
	mapInitialize: function(){
		if (google.maps.BrowserIsCompatible()) {
			Mapping.Map.Created = true;
			center = new google.maps.LatLng(this.loadOptions.center.Latitude, this.loadOptions.center.Longitude);
			this.map = new google.maps.Map2(this.loadOptions.div);
			this.map.setCenter(center, this.loadOptions.zoom);
			this.map.enableScrollWheelZoom();
			
			this.initCustomControls();
			
			Mapping.Signal.I().connect('hideinfowindow', function(sEvent){
				this.map.closeInfoWindow();
			}.bind(this));
			
			this.loadOptions.callback(true);
		} else {
			alert("We're sorry but your browser doesn't support maps.");
			this.loadOptions.callback(false);
		}
	},
	unLoadMap: function(pEvent){
		google.maps.Unload();
	},
	addEvent: function(event, callback){
		return GEvent.addListener(this.map, event, callback);
	}
});
Mapping.Map.Instance = null;
Mapping.Map.I = function(){return Mapping.Map.Instance;}
Mapping.Map.Created = false;
Mapping.Map.Create = function(div, center, zoom, callback, autoLoadMap){
	if(Mapping.Map.Instance == null){
		Mapping.Map.Instance = new Mapping.Map(div, center, zoom, callback, autoLoadMap);
	}
}
Mapping.Map.BuildStaticURL = function(points, zoom, size){
	var params = {format: 'png',maptype: 'roadmap',zoom: zoom, size:size}
	params.markers = "";
	points.each(function(point){
		params.markers += point.lat+","+point.lng+",red"+point.id+"|";
	});
	return Mapping.Config.urls.staticMapServer +'?'+ $H(params).toQueryString();
}

Mapping.Map.Controls = {
	Traffic: null,
	StreetView: null,
	applyContainerStyle: function(container){
		container.style.border = '1px solid black';
		container.style.backgroundColor = 'white';
	},
	applyButtonStyle: function(button){
		button.style.color = "#000";
		button.style.backgroundColor = "#fff";
		button.style.fontSize = "12px";
		button.style.border = "1px solid #fff";
		button.style.borderRight = '1px solid #ccc';
		button.style.borderBottom = '1px solid #ccc';
		button.style.textAlign = "center";
		button.style.cursor = "pointer";
		button.style.width = '70px';
	},
	applyButtonEventOn: function(button){
		button.style.border = "1px solid #345684";
		button.style.borderRight = '1px solid #6C9DDF';
		button.style.borderBottom = '1px solid #6C9DDF';
		button.style.fontWeight = 'bold';
	},
	applyButtonEventOff: function(button){
		button.style.border = "1px solid #fff";
		button.style.borderRight = '1px solid #ccc';
		button.style.borderBottom = '1px solid #ccc';
		button.style.fontWeight = 'normal';
	}
}


Mapping.Map.addMethods({
	initCustomControls: function(){
		Mapping.Map.Controls.Traffic = function(){}
		Mapping.Map.Controls.Traffic.prototype = new google.maps.Control();
		Mapping.Map.Controls.Traffic.prototype.isShowing = false;
		Mapping.Map.Controls.Traffic.prototype.overlay = null;
		Mapping.Map.Controls.Traffic.prototype.initialize = function(map){
			var container = document.createElement("div");
			Mapping.Map.Controls.applyContainerStyle(container);
			
			var traffic = document.createElement("div");
			traffic.appendChild(document.createTextNode("Traffic"));
			Mapping.Map.Controls.applyButtonStyle(traffic);
			traffic.onclick = function(){
				if (this.isShowing) {
					Mapping.Map.Controls.applyButtonEventOff(traffic);
					map.removeOverlay(this.overlay);
					this.isShowing = false;
				} else {
					Mapping.Map.Controls.applyButtonEventOn(traffic);
					if (this.overlay == null) {
						this.overlay = new google.maps.TrafficOverlay();
					}
					map.addOverlay(this.overlay);
					this.isShowing = true;
				}
			}
			container.appendChild(traffic);
			map.getContainer().appendChild(container);
			return container;
		}
		Mapping.Map.Controls.Traffic.prototype.getDefaultPosition = function(){
			return new google.maps.ControlPosition(google.maps.ANCHOR_TOP_RIGHT, new google.maps.Size(147, 7));
		}
		
		//If using StreetView Control make sure to include Mapping.StreetView.js in the app
		Mapping.Map.Controls.StreetView = function(){}
		Mapping.Map.Controls.StreetView.prototype = new google.maps.Control();
		Mapping.Map.Controls.StreetView.prototype.isShowing = false;
		Mapping.Map.Controls.StreetView.prototype.initialize = function(map){
			Mapping.StreetView.I();
			var container = document.createElement("div");
			Mapping.Map.Controls.applyContainerStyle(container);
			
			var streetView = document.createElement("div");
			streetView.appendChild(document.createTextNode("Street View"));
			Mapping.Map.Controls.applyButtonStyle(streetView);
			streetView.onclick = function(){
				if (this.isShowing) {
					Mapping.Map.Controls.applyButtonEventOff(streetView);
					Mapping.Signal.I().emit('streetview', {show:false});
					this.isShowing = false;
				} else {
					Mapping.Map.Controls.applyButtonEventOn(streetView);
					Mapping.Signal.I().emit('streetview', {show:true, location:Mapping.Map.I().map.getCenter()});
					this.isShowing = true;
				}
			}
			container.appendChild(streetView);
			map.getContainer().appendChild(container);
			return container;
		}
		Mapping.Map.Controls.StreetView.prototype.getDefaultPosition = function(){
			return new google.maps.ControlPosition(google.maps.ANCHOR_TOP_RIGHT, new google.maps.Size(217, 7));
		}
	}
});/**
 * @author Nick Verbeck
 * @since 6/25/2009
 * @file Mapping.App.js
*/
Mapping.App = {}
/**
 * @author Nick Verbeck
 * @since 7/7/2009
 * @file Mapping.Geocoder.js
*/
Mapping.Geocoder = Class.create({
	initialize: function(){
		if (Mapping.Map.Created) {
			this._geocoder = new google.maps.ClientGeocoder();
		} else {
			throw "An instance of Mapping.Map but be created before Mapping.Geocoder can be created.";
		}
	},
	getLatLng: function(searchStr, callback){
		this._geocoder.getLatLng(searchStr, callback);
	}
	
});
Mapping.Geocoder.Instance = null;
Mapping.Geocoder.I = function(){
	if (Mapping.Geocoder.Instance == null) {
		Mapping.Geocoder.Instance = new Mapping.Geocoder();
	}
	return Mapping.Geocoder.Instance;
}/**
 * @author Nick Verbeck
 * @since 7/8/2009
 * @file Mapping.LocalSearch.js
*/

Mapping.LocalSearch = Class.create({
	initialize: function(){
		if (Mapping.Map.Created) {
			this._localSearch = new google.search.LocalSearch();
			this._localSearch.setNoHtmlGeneration();
			this._localSearch.setCenterPoint(Mapping.Map.I().map);
			this._localSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);
			this._localSearch.setSearchCompleteCallback(this, this._searchReturn);
			
			this._searchQueue = new Array();
			this._isSearching = false;
			this._isSearchingPage2 = false;
			
			this.workingResults = null;
		} else {
			throw "An instance of Mapping.Map but be created before Mapping.LocalSearch can be created.";
		}
	},
	search: function(term, callback){
		this._searchQueue[this._searchQueue.length] = {term: term, callback: callback}
		if(!this._isSearching){
			this._search(term);
		}
	},
	_search: function(term){
		this._isSearching = true;
		this._localSearch.execute(term);
	},
	_searchReturn: function(){
		var results = new Array();
		this._localSearch.results.each(function(result){
			var temp = {
				streetAddress: result.addressLines[0],
				cityState: result.addressLines[1],
				title: result.titleNoFormatting,
				url: result.url,
				lat: result.lat,
				lng: result.lng,
				phones: result.phoneNumbers
			}
			results[results.length] = temp;
		});
		if(this._isSearchingPage2){
			results = {results:this.workingResults.concat(results), term: this._searchQueue[0].term}
			var callback = this._searchQueue[0].callback;
			this._searchQueue[0] = null;
			this._searchQueue = this._searchQueue.compact();
			this._isSearching = false;
			this.workingResults = null;
			this._isSearchingPage2 = false;
			
			callback(results);
			
			if(this._searchQueue.length > 0){
				this._search(this._searchQueue[0].term);
			}
		} else {
			this._isSearchingPage2 = true;
			this.workingResults = results;
			this._localSearch.gotoPage(2);
		}
	}
});

Mapping.LocalSearch.Instance = null;
Mapping.LocalSearch.I = function(){
	if(Mapping.LocalSearch.Instance == null){Mapping.LocalSearch.Instance = new Mapping.LocalSearch();}
	return Mapping.LocalSearch.Instance;
}/**
 * @author Nick Verbeck
 * @since 7/7/2009
 * @file Mapping.App.POI.js
*/
Mapping.App.POI = Class.create({
	initialize: function(div, lat, lng, zip, zoom, lazy, no_recenter){
		Event.observe(window, 'load', this._onLoad.bindAsEventListener(this));
		if(lazy == null || lazy == "") {
			lazy = true;
		} else {
			lazy = false;
		}
		if(lat == null || lat == "" || lng == null || lng == ""){
			this.center = {Latitude: 0, Longitude:0}
		} else {
			this.center = {Latitude: lat, Longitude:lng}
		}
		if(zoom == null || zoom == 0){this.zoom = Mapping.Config.map.failSafeZoom;}
		else {this.zoom = zoom;}
		
		this.zip = zip;
		this.isSearching = false;
		this.currentPOI = null;
		this.locationPushpin = null;
		this.pois = new Array();
		if( no_recenter == true ) {
			this._focusNextSearch = false;
		}
		else {
			this._focusNextSearch = true;
		}
		
		this._searchOnMapLoad = null;
		this.templates = {
			even: new Template("<tr pushpin=\"#{id}\" class=\"MapPOIEven\"><td>#{image}</td><td><a href=\"#{url}\" target=\"_blank\">#{title}</a></td></tr>"),
			odd: new Template("<tr pushpin=\"#{id}\" class=\"MapPOIOdd\"><td>#{image}</td><td><a href=\"#{url}\" target=\"_blank\">#{title}</a></td></tr>")
		}
		Mapping.Map.Create($(div), this.center, this.zoom, function(created){this._mapLoaded(created);}.bind(this),lazy);
	},
	_mapLoaded: function(created){
		if(created){
			Mapping.Map.I().map.addControl(new GSmallMapControl());
			
			if(this.center.Latitude == 0 && this.zip != ""){
				Mapping.Geocoder.I().getLatLng(this.zip, function(point){this._setCenterFromGeocode(point);}.bind(this));
			} else {
				this.center = Mapping.Map.I().map.getCenter();
			}
			this.locationPushpin = new Mapping.Pushpin.Pushpin(this.center, null, null, Mapping.Icons.NewProp);
			this.locationPushpin.add();
			
			if (this._searchOnMapLoad != null) {
				this.search(this._searchOnMapLoad);
				this._searchOnMapLoad = null;
			}
		}
	},
	_setCenterFromGeocode: function(point){
		this.center = point;
		Mapping.Map.I().map.setCenter(this.center, this.zoom);
	},
	_onLoad: function(pEvent){
		try {
			poiToSearch = null;
			$$('#MapPOITabs li a').each(function(iter){
				var attributes = iter.attributes['rel'].nodeValue.split(' ');
				var poi = new Mapping.App.POI.POI(iter, $(attributes[1]), attributes[0]);
				Event.observe(iter, 'click', function(pEvent){this.search(poi);}.bindAsEventListener(this));
				this.pois[this.pois.length] = poi;
				if (iter.up('li').hasClassName('active')) {poiToSearch = poi;}
			}.bind(this));
			if (Mapping.Map.Created && poiToSearch != null) {
				this.search(poiToSearch);
			} else if (!Mapping.Map.Created && poiToSearch != null){
				this._searchOnMapLoad = poiToSearch;
			}
		} catch(e){Mapping.Console.error(e);}
	},
	search: function(poi){
		if(!this.isSearching && poi != this.currentPOI){
			this.isSearching = true;
			if(this.currentPOI != null){
				this.currentPOI.setInactive();
			}
			this.currentPOI = poi;
			this.currentPOI.setActive();
			this.currentPOI.setHTML('Searching...');
			Mapping.LocalSearch.I().search(this.currentPOI.searchTerm, this._searchResults.bind(this));
		}
	},
	_searchResults: function(results){
		var icons = Mapping.Icons.GenericOrange;
		if (results.term.toLowerCase() == 'schools') {
			icons = Mapping.Icons.GenericOrange;
		} else if (results.term.toLowerCase() == 'restaurants') {
			icons = Mapping.Icons.GenericBlue;
		} else if (results.term.toLowerCase() == 'shopping') {
			icons = Mapping.Icons.GenericGreen;
		}
		var html = new StringBuilder('<table cellpadding="0" cellspacing="0" class="MapPOIResults">');
		var counter = 0;
		var pushpins = new Array();
		results.results.each(function(result){
			var pushpin = new Mapping.Pushpin.Pushpin(new google.maps.LatLng(result.lat, result.lng), counter+1, null, icons);
			pushpin.add();
			pushpins[pushpins.length] = pushpin;
			
			var temp = {
				url: result.url,
				title: result.title,
				image: '<img src="'+pushpin.getResultIconURL(Mapping.Icons.Sizes.Small)+'" />',
				id: counter+1
			}
			if (counter % 2 == 0) {
				html.append(this.templates.even.evaluate(temp));
			} else {
				html.append(this.templates.odd.evaluate(temp));
			}
			counter++;
		}.bind(this));
		html.append('</table>');
		this.currentPOI.setHTML(html.toString());
		this.currentPOI.setPins(pushpins);
		html.clear();
		this._bindEvents();
		this.isSearching = false;
		
		if(this._focusNextSearch){
			var bounds = new google.maps.LatLngBounds();
			results.results.each(function(result){
				bounds.extend(new google.maps.LatLng(result.lat, result.lng));
			});
			bounds.extend(this.center);
			Mapping.Map.I().map.setCenter(bounds.getCenter(), Mapping.Map.I().map.getBoundsZoomLevel(bounds));
			this._focusNextSearch = false;
		}
	},
	_bindEvents: function(){
		$$('table.MapPOIResults tr').each(function(element){
			element.onmouseover = function(){this._resultMouseOverEvent(element);}.bind(this);
			element.onmouseout = function(){this._resultMouseOutEvent(element);}.bind(this);
		}.bind(this));
	},
	_resultMouseOverEvent: function(element){
		var id = Number(element.attributes['pushpin'].nodeValue);
		var pin = this.getPushpinByID(id);
		pin.hover();
	},
	_resultMouseOutEvent: function(element){
		var id = Number(element.attributes['pushpin'].nodeValue);
		var pin = this.getPushpinByID(id);
		pin.unhover();
	},
	getPushpinByID: function(id){
		return this.currentPOI.pushpins[id-1];
	}
});

Mapping.App.POI.POI = Class.create({
	initialize: function(tab, container, searchTerm){
		this.tab = $(tab);
		this.container = $(container);
		this.searchTerm = searchTerm;
		this.pushpins = null;
	},
	setInactive: function(){
		this.tab.up('li').removeClassName('active');
		this.container.innerHTML = "";
		this.container.style.display = 'none';
		this.clearPins();
	},
	clearPins: function(){
		if (this.pushpins != null) {
			this.pushpins.each(function(pin){
				pin.del();
			});
			this.pushpins = null;
		}
	},
	setActive: function(){
		this.tab.up('li').addClassName("active");
		this.container.style.display = '';
	},
	setPins: function(pins){
		this.pushpins = pins;
	},
	setHTML: function(html){
		this.container.innerHTML = html;
	}
});

Mapping.Config.urls.mediaServer="http://media.wkre.com/maps/icon/";

Mapping.Config.map.failSafeLatLng.lat='40.02128825499438';

Mapping.Config.map.failSafeLatLng.lng='-105.24013996124269';

Mapping.Config.map.failSafeZoom='13';<!-- //0.18591499328613 --><!-- //10.10.98.70 -->