GIcon.prototype.type = "Icon";

GMarker.prototype.type = "Marker";
GMarker.prototype.sort = "";

GPolyline.prototype.type = "Polyline";
GPolyline.prototype.sort = "";

GPolygon.prototype.type = "Polygon";
GPolygon.prototype.sort = "";


GMarker.prototype.addtolist = false;
GPolyline.prototype.addtolist = false;
GPolygon.prototype.addtolist = false;

GMap2.prototype.GOverlays = [];

GMap2.prototype.Legend = {};
GMap2.prototype.Directions = {};

var useraddress_;
var useraddressstring_ = null;
var addressmarker_ = null;

GMap2.prototype.addAddress = function(map, address, callbackfunction) {
	var geocoder = new GClientGeocoder();
	geocoder.setViewport(map.getBounds());
	geocoder.getLatLng(address, function(point) {
		if (!point) {
			alert (address + " not found");
		} else {
			useraddress_ = point;
			if (addressmarker_ === null) {
				addressmarker_ = new GMarker(useraddress_); }
			else {
				map.removeOverlay(addressmarker_);
				addressmarker_ = new GMarker(useraddress_); }
			map.addOverlay(addressmarker_);
			useraddressstring_ = address;
			callbackfunction(point);
		}
	});
};

GMap2.prototype.getAddressString = function() {
	return useraddressstring_;
};

GMap2.prototype.getAddressMarker = function() {
	return addressmarker_;
};

GMap2.prototype.clearAddress = function() {
	if (addressmarker_ !== null)
	{
		this.removeOverlay(addressmarker_);
	}
	useraddressstring_ = null;
	addressmarker_ = null;
};

var cNO_ = "";
GMap2.prototype.addNameOverlay = function(marker, name) {
	if (cNO_ !== null)
	{
		this.removeOverlay(cNO_);
		cNO_ = null;
	}
	cNO_ = new NameOverlay(name, marker);
	this.addOverlay(cNO_);
};

GMap2.prototype.removeNameOverlay = function() {
	if (cNO_ !== null)
	{
		this.removeOverlay(cNO_);
		cNO_ = null;
	}
};

GMap2.prototype.List = "";
GMap2.prototype.SortList = function(descending, callbackfunction) {
	var j;
	if (descending) {
		this.List.listentries.sort(dlistsort);
	}
	else
	{
		this.List.listentries.sort(listsort);
	}
	for (j = 0; j < this.List.listentries.length; j++)
	{
		this.List.ListDiv_.removeChild(this.List.listentries[j].div);
	}
	for (j = 0; j < this.List.listentries.length; j++)
	{
		this.List.ListDiv_.appendChild(this.List.listentries[j].div);
		callbackfunction(j, this.List.listentries.length, this.List.listentries[j]);
	}
};

//SJPlacemark
function SJPlacemark(index, group, name, id, description, coordinates)
{
	if (group.color === undefined && group.color === null)
	{
		group.color = "#FF0000";
	}
	if (group.highlight === undefined && group.highlight === null)
	{
		group.highlight = group.color;
	}

	this.index = index;
	this.group = group.id;
	this.color = Color.FromHex(group.color);
	this.highlight = Color.FromHex(group.highlight);
	this.minzoom = group.minzoom;
	this.maxzoom = group.maxzoom;
	this.isonmap = false;
	this.isonlist = false;
	this.name_ = name;
	this.id_ = id;
	this.description_ = description;
	this.coordinates_ = coordinates;
	this.type = "SJPlacemark";

	this.events_ = [];
	this.eventhandlers_ = [];
}

SJPlacemark.prototype = new GOverlay();

SJPlacemark.prototype.Add = function(addtolist) {
	var me = this;
	var i;
	me.map_.removeOverlay(me.marker_);
	//me.map_.addOverlay(me.marker_);
	for (i = 0; i < me.events_.length; i++)
	{
		me.eventhandlers_.push(GEvent.addListener(me.marker_, me.events_[i].type, me.events_[i].handle));
	}
	window.setTimeout(function() {
		me.map_.addOverlay.call(me.map_, me.marker_);
	}, me.index);
	me.isonmap = true;
	if (addtolist) {
		me.map_.List.addEntry(me);
		me.isonlist = true;
	}
};

SJPlacemark.prototype.Remove = function() {
	var me = this;
	var i;
	me.map_.removeOverlay(me.marker_);
	for (i = 0; i < me.eventhandlers_.length; i++)
	{
		GEvent.removeListener(me.eventhandlers_[i]);
	}
	me.isonmap = false;
	if (me.isonlist) {
		me.map_.List.removeEntry(me);
		me.isonlist = false;
	}
};

SJPlacemark.prototype.setmarker = function() {
	var me = this;
	var i;

	if (me.markertype === "Point")
	{
		if (me.iconsize_.width !== me.oldiconsize_width || me.iconsize_.height !== me.oldiconsize_.height)
		{
			me.map_.removeOverlay(me.marker_);
			for (i = 0; i < me.eventhandlers_.length; i++)
			{
				GEvent.removeListener(me.eventhandlers_[i]);
			}
			me.eventhandlers_ = null;
			me.eventhandlers_ = [];
			me.icon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.color.getHex(), cornerColor: me.color.getHex(), strokeColor: "#000000"});
			me.hicon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.highlight.getHex(), cornerColor: me.highlight.getHex(), strokeColor: "#000000"});
			me.marker_ = new GMarker(me.point_[0], me.icon_);
			me.image_ = me.icon_.image;
			me.highlightimage_ = me.hicon_.image;
			//window.setTimeout(function() {
	    		//	me.map_.addOverlay.call(me.map_, me.marker_);
	  		//}, 10);
			//me.map_.addOverlay(me.marker_);
			//me.map_.addOverlay(me.marker_);
			for (i = 0; i < me.events_.length; i++)
			{
				me.eventhandlers_.push(GEvent.addListener(me.marker_, me.events_[i].type, me.events_[i].handle));
			}
			if (me.isonmap === true) {
				//me.map_.addOverlay(me.marker_);
				window.setTimeout(function() {
		    			me.map_.addOverlay.call(me.map_, me.marker_);
		  		}, me.index);
			}
			me.oldiconsize_ = me.iconsize_;
		}
		else
		{
			me.icon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.color.getHex(), cornerColor: me.color.getHex(), strokeColor: "#000000"});
			me.hicon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.highlight.getHex(), cornerColor: me.highlight.getHex(), strokeColor: "#000000"});
			me.marker_.image_ = me.icon_.image;
			me.marker_.highlightimage_ = me.hicon_.image;
			me.marker_.setImage(me.icon_.image);
		}
	}
	else if (me.markertype === "Polyline")
	{
		me.marker_.setStrokeStyle({color:me.color.getHex()});
	}
	else if (me.markertype === "Polygon")
	{
		me.marker_.setStrokeStyle({color:me.color.getHex()});
	}
};

SJPlacemark.prototype.Highlight = function() {
	var me = this;
	if (me.markertype === "Point")
	{
		me.marker_.setImage(me.highlightimage_);
	}
	else if (me.markertype === "Polyline")
	{
		me.marker_.setStrokeStyle({color:me.highlight.getHex()});
	}
	else if (me.markertype === "Polygon")
	{
		me.marker_.setStrokeStyle({color:me.highlight.getHex()});
		me.marker_.setFillStyle({color:me.highlight.getHex()});
	}
};

SJPlacemark.prototype.removeHighlight = function() {
	var me = this;
	if (me.markertype === "Point")
	{
		me.marker_.setImage(me.image_);
	}
	else if (me.markertype === "Polyline")
	{
		me.marker_.setStrokeStyle({color:me.color.getHex()});
	}
	else if (me.markertype === "Polygon")
	{
		me.marker_.setStrokeStyle({color:me.color.getHex()});
		me.marker_.setFillStyle({color:me.color.getHex()});
	}
};

SJPlacemark.prototype.addEvent = function(type, handle) {
	var me = this;
	me.events_.push({type: type, handle: handle});
	me.eventhandlers_.push(GEvent.addListener(me.marker_, type, handle));
};

SJPlacemark.prototype.SetColor = function(color, highlight) {
	var me = this;
	me.color = color;
	if (highlight !== undefined && highlight !== null)
	{
		me.highlight = highlight;
	}
	me.setmarker();
};

SJPlacemark.prototype.GetColor = function() {
	var me = this;
	return me.color;
};

SJPlacemark.prototype.initialize = function(map) {
	var me = this;
	var addcontainer = document.createElement("div");
	var adddiv = document.createElement("div");
	var addbar = document.createElement("div");
	var gobutton = document.createElement("div");
	var i;
	me.map_ = map;

	me.map_.addControl(new DirectionsControl());

	addcontainer.style.width = "200px";
	addcontainer.id = "addcontainer";

	adddiv.style.fontFamily = "Arial";
	adddiv.style.fontSize = "8pt";
	adddiv.style.color = "#0000FF";
	adddiv.style.textDecoration = "underline";
	adddiv.style.cursor = "pointer";
	adddiv.innerHTML = "Get directions to here";

	addbar.style.visibility = "hidden";
	addbar.style.fontFamily = "Arial";
	addbar.style.fontSize = "8pt";
	addbar.style.color = "#AAAAAA";
	addbar.innerHTML = "<input id='userlocationaddress2' type='text' style='width:200px;'" +
		"value='' title='Address' align='right' valign='top'><br />" +
		"(eg. 200 E Santa Clara, San Jose, CA)<br />";

	gobutton.innerHTML = "Find directions";
	gobutton.style.fontFamily = "Arial";
	gobutton.style.fontSize = "8pt";
	gobutton.style.color = "#2255DD";
	gobutton.style.textDecoration = "underline";
	gobutton.style.cursor = "pointer";
	gobutton.style.visibility = "hidden";

	GEvent.addDomListener(adddiv, "click", function() {
		addbar.style.visibility = "visible";
		gobutton.style.visibility = "visible";
	});

	GEvent.addDomListener(gobutton, "click", function() {
		var address_;
		var geocoder_;
		if (me.marker_.type === "Marker") {
			address_ = document.getElementById("userlocationaddress2").value;
			geocoder_ = new GClientGeocoder();
			geocoder_.setViewport(map.getBounds());
			geocoder_.getLatLng(address_, function(point) {
				if (!point) {
					alert (address_ + " not found");
				} else {
					me.map_.Directions.addDirections(me.marker_.getLatLng().toUrlValue() + " to " + point.toUrlValue());
				}
			});
			me.marker_.closeInfoWindow();
		}
		else
		{
			address_ = document.getElementById("userlocationaddress2").value;
			geocoder_ = new GClientGeocoder();
			geocoder_.setViewport(map.getBounds());
			geocoder_.getLatLng(address_, function(point) {
				if (!point) {
					alert (address_ + " not found");
				} else {
					me.map_.Directions.addDirections(pointclicked_.toUrlValue() + " to " + point.toUrlValue());
				}
			});
			map.closeInfoWindow();
		}
	});
	addcontainer.appendChild(adddiv);
	addcontainer.appendChild(addbar);
	addcontainer.appendChild(gobutton);
	if (document.getElementById(addcontainer.id) !== undefined && document.getElementById(addcontainer.id) !== null)
	{
		me.description_[0].description.removeChild(document.getElementById(addcontainer.id));
	}
	me.description_[0].description.appendChild(addcontainer);


	if (me.map_.getZoom() >= 12) {
		me.iconsize_ = new GSize(2 + 16, 12 + 16);
	}
	else {
		me.iconsize_ = new GSize(2 + 8, 12 + 8);
	}
	me.oldiconsize_ = me.iconsize_;
	me.oldzoom_ = me.map_.getZoom();

	me.markertype = me.coordinates_.type;
	me.point_ = [];
	for (i = 0; i < me.coordinates_.data.length; i++)
	{
		me.point_.push(new GLatLng(me.coordinates_.data[i].lat, me.coordinates_.data[i].lng));
	}

	me.events_.push({ type: 'click', handle: function(event) {
		pointclicked_ = new GLatLng(event.y, event.x);
		if (me.description_.length > 1)
		{
			var tabs = [];
			for (i = 0; i < me.description_.length; i++)
			{
				tabs[i] = new GInfoWindowTab(me.description_[i].label, me.description_[i].description);
			}
			if (me.markertype === "Point") {
				me.marker_.openInfoWindowTabs( tabs );
			} else {
				me.map_.openInfoWindowTabs(pointclicked_, tabs);
			}
		}
		else
		{
			if (me.markertype === "Point") {
				me.marker_.openInfoWindow(me.description_[0].description);
			} else {
				me.map_.openInfoWindow(pointclicked_, me.description_[0].description);
			}
		}
		if (map.getAddressString() !== null)
		{
			document.getElementById("userlocationaddress2").value = map.getAddressString();
		}
		else
		{
			document.getElementById("userlocationaddress2").value = "";
		}
	}});
	me.events_.push({ type: 'mouseover', handle: function() {
		map.addNameOverlay(me.marker_, me.name_);
		me.Highlight();
	}});
	me.events_.push({ type: 'mouseout', handle: function() {
		map.removeNameOverlay();
		me.removeHighlight();
	}});

	if (me.markertype === "Point")
	{
		me.icon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.color.getHex(), cornerColor: me.color.getHex(), strokeColor: "#000000"});
		me.hicon_ = MapIconMaker.createMarkerIcon({width:me.iconsize_.width, height:me.iconsize_.height, primaryColor: me.highlight.getHex(), cornerColor: me.highlight.getHex(), strokeColor: "#000000"});
		me.marker_ = new GMarker(me.point_[0], me.icon_);
		me.image_ = me.icon_.image;
		me.highlightimage_ = me.hicon_.image;
		//window.setTimeout(function() {
    		//	me.map_.addOverlay.call(me.map_, me.marker_);
  		//}, 10);
		//me.map_.addOverlay(me.marker_);
		//me.map_.addOverlay(me.marker_);
		for (i = 0; i < me.events_.length; i++)
		{
			me.eventhandlers_.push(GEvent.addListener(me.marker_, me.events_[i].type, me.events_[i].handle));
		}
	}
	else if (me.markertype === "Polyline")
	{
		me.marker_ = new GPolyline(me.point_, me.color.getHex(), 3, 1.0);
		//window.setTimeout(function() {
    		//	me.map_.addOverlay.call(me.map_, me.marker_);
  		//}, 10);
		//me.map_.addOverlay(me.marker_);
		for (i = 0; i < me.events_.length; i++)
		{
			me.eventhandlers_.push(GEvent.addListener(me.marker_, me.events_[i].type, me.events_[i].handle));
		}
	}
	else if (me.markertype === "Polygon")
	{
		me.marker_ = new GPolygon(me.point_, me.color.getHex(), 3, 1.0, me.color.getHex(), 0.5);
		//window.setTimeout(function() {
    		//	me.map_.addOverlay.call(me.map_, me.marker_);
  		//}, 10);
		//me.map_.addOverlay(me.marker_);
		for (i = 0; i < me.events_.length; i++)
		{
			me.eventhandlers_.push(GEvent.addListener(me.marker_, me.events_[i].type, me.events_[i].handle));
		}
	}

	if ((map.getZoom() <= me.minzoom && map.getZoom() >= me.maxzoom))
	{
		me.Add(true);
	}
	else
	{
		me.isonmap = false;
	}
};

SJPlacemark.prototype.remove = function() {
	this.Remove();
	this.marker_ = null;
	this.events_ = [];
	this.eventhandlers_ = [];
	this.map_ = null;
};

SJPlacemark.prototype.copy = function() {
	return new SJCityOverlay(this.url_, this.type);
};

SJPlacemark.prototype.redraw = function(force) {
	if (!force) {
		return;
	}
	var me = this;
	var oldLevel = me.oldzoom_;
	var newLevel = me.map_.getZoom();
	
	if ((newLevel > me.minzoom || newLevel < me.maxzoom) && me.isonmap === true)
	{
		me.Remove();
	}
	if ((newLevel <= me.minzoom && newLevel >= me.maxzoom) && me.isonmap === false)
	{
		me.isonmap = true;
		me.Add(true);
	}
	if (me.markertype === "Point")
	{	
		if ((oldLevel >= 12 && newLevel < 12) || (oldLevel < 12 && newLevel >= 12))
		{
			if (newLevel >= 12) {
				me.iconsize_ = new GSize(2 + 16, 12 + 16);
			}
			else {
				me.iconsize_ = new GSize(2 + 8, 12 + 8);
			}
			me.setmarker();
		}
	}
	me.oldzoom_ = me.map_.getZoom();
};

//SJCityOverlay provides a way to add city data to the map
function DescriptionInfo(label, description)
{
	this.label = label;
	this.description = description;
}

var SJCityOverlays = [];

function SJCityOverlay(url) {
	this.url_ = url;
	this.type = "SJCityOverlay";
	this.sjplacemarks_ = [];
	this.loadingamount = 100;
	this.currentamount = 0;
}

SJCityOverlay.prototype = new GOverlay();

SJCityOverlay.prototype.CreateLoadingBar = function(map) {
		this.loadingbarpane = document.createElement("div");
		this.loadingbarbg = document.createElement("div");
		this.loadingbarp = document.createElement("div");
		this.loadingbartxt = document.createElement("div");

		this.loadingbarwidth = 0;

		this.loadingbarpane.style.width = "100%";
		this.loadingbarpane.style.height = "100%";
		this.loadingbarpane.style.position = "absolute";
		this.loadingbarpane.style.zIndex = "7000";
		this.loadingbarpane.style.top = "0px";
		this.loadingbarpane.style.left = "0px";

		this.loadingbarbg.style.position = "absolute";
		this.loadingbarbg.style.left = "50%";
		this.loadingbarbg.style.top = "50%";
		this.loadingbarbg.style.width = "300px";
		this.loadingbarbg.style.height = "20px";
		this.loadingbarbg.style.border = "1px solid #000";
		this.loadingbarbg.style.backgroundImage = "url('http://www.sanjoseca.gov/images/leftnav_bg.gif')";
		this.loadingbarbg.style.marginLeft = "-150px";
		this.loadingbarbg.style.marginTop = "-10px";
		this.loadingbarbg.style.textAlign = "center";

		this.loadingbarp.style.position = "absolute";
		this.loadingbarp.style.zIndex = "7001";
		this.loadingbarp.style.left = "0";
		this.loadingbarp.style.top = "0";
		this.loadingbarp.style.width = "0px";
		this.loadingbarp.style.height = "100%";
		this.loadingbarp.style.border = "1px solid #000";
		this.loadingbarp.style.backgroundColor = "#003366";

		this.loadingbartxt.id = "loadingbartxt";
		this.loadingbartxt.style.zIndex = "7002";
		this.loadingbartxt.style.width = "100%";
		this.loadingbartxt.style.height = "100%";
		this.loadingbartxt.style.left = "0px";
		this.loadingbartxt.style.top = "3px";
		this.loadingbartxt.style.position = "absolute";
		this.loadingbartxt.style.fontFamily = "arial";
		this.loadingbartxt.style.fontSize = "8pt";
		this.loadingbartxt.style.color = "#3399BB";
		this.loadingbartxt.innerHTML = "Loading";

		this.loadingbarbg.appendChild(this.loadingbartxt);
		this.loadingbarbg.appendChild(this.loadingbarp);
		this.loadingbarpane.appendChild(this.loadingbarbg);
		map.getContainer().appendChild(this.loadingbarpane);
}

SJCityOverlay.prototype.ProgressLoadingBar = function(index) {
	var me = this;
	var x, indexaddition = 0, percentage;
	percentage = Math.ceil((index / me.sjplacemarks_.length)*100);
	while ((Math.ceil(((index + indexaddition) / me.sjplacemarks_.length) * 100) <= percentage) && (index + indexaddition < me.sjplacemarks_.length)) {
		//me.map_.addOverlay(me.sjplacemarks_[index + indexaddition]);
		me.objectSetTimeout_(me.map_, me.sjplacemarks_[index + indexaddition], me.map_.addOverlay, 0);
		indexaddition++;
	}
	//me.currentamount += amount;
	//me.map_.addOverlay(me.sjplacemarks_[index]);
	//me.objectSetTimeout_(me.map_, me.sjplacemarks_[index], me.map_.addOverlay, 0);
	me.loadingbartxt.innerHTML = "Loading " + percentage + "%";
	me.loadingbarwidth = Math.ceil(300 * (index / me.sjplacemarks_.length));
	me.loadingbarp.style.width = this.loadingbarwidth + "px";
	//this.loadingbartxt.innerHTML = this.currentamount + " / " + this.loadingamount + " = " + (this.currentamount / this.loadingamount);
	if (index + indexaddition > me.sjplacemarks_.length - 1) {
		me.loadingbarpane.style.zIndex = "-7000";
	} else {
		me.objectSetTimeout_(me, (index + indexaddition), me.ProgressLoadingBar, 0);
		//me.ProgressLoadingBar(index + 1);
	}
		
}

SJCityOverlay.prototype.AddPlacemark = function() {
}

SJCityOverlay.prototype.HideLoadingBar = function() {
	this.loadingbarpane.style.zIndex = "-7000";
}

SJCityOverlay.prototype.objectSetTimeout_ = function(object, argument1, command, milliseconds) {
  return window.setTimeout(function() {
    command.call(object, argument1);
  }, milliseconds);
};

SJCityOverlay.prototype.initialize = function(map) {
	var me = this;
	this.map_ = map;

	GDownloadUrl(this.url_, function(data, responseCode) {
		var micon_;
		var mcolor_;
		var mhighlighticon_;
		var mhighlightcolor_;
		var clength = 0;
		var index = 0;
		var i;
		var j;
		var x;

		me.objectSetTimeout_(me, map, me.CreateLoadingBar, 0);

		me.markers_ = [];
		var jdata = eval( '(' + data + ')' );
		me.loadingamount = jdata.data.length;

		me.groups_ = [];
		for (i = 0; i < jdata.groups.length; i++)
		{
			me.groups_[jdata.groups[i].id] = jdata.groups[i];
			if (me.groups_[jdata.groups[i].id].color === undefined && me.groups_[jdata.groups[i].id].color === null)
			{
				me.groups_[jdata.groups[i].id].color = "#FF0000";
			}
			if (me.groups_[jdata.groups[i].id].highlight === undefined && me.groups_[jdata.groups[i].id].highlight === null)
			{
				me.groups_[jdata.groups[i].id].highlight = me.groups_[jdata.groups[i].id].color;
			}
		}

		for (i = 0; i < jdata.data.length; i++) {
			var description = [];
			if (jdata.data[i].description !== null && jdata.data[i].description !== undefined)
			{
				for (j = 0; j < jdata.data[i].description.length; j++)
				{
					var label = jdata.data[i].description[j].label;
					var desc = document.createElement("div");
					desc.style.height = "100%";
					desc.display = "block";
					desc.style.overflow = "auto";
					desc.innerHTML = "<font style='font-family:Arial;font-size:9pt;'><b>" + jdata.data[i].name + "</b><br />" + jdata.data[i].description[j].data + "<br /></font>";
					description[j] = new DescriptionInfo(label, desc);
				}
			}

			var groupnumber;
			groupnumber = jdata.data[i].group;

			for (x = 0; x < jdata.data[i].coordinates.length; x++)
			{
				if (x > 0) {
					index++;
				}
				if (jdata.data[i].coordinates[x].type === "Point") {
					me.groups_[groupnumber].haspoint = true;
				}
				if (jdata.data[i].coordinates[x].type === "Polyline") {
					me.groups_[groupnumber].haspolyline = true;
				}
				me.sjplacemarks_.push(new SJPlacemark(index, me.groups_[groupnumber], jdata.data[i].name, jdata.data[i].id, description, jdata.data[i].coordinates[x]));
				//me.objectSetTimeout_(me.map_, me.sjplacemarks_[me.sjplacemarks_.length - 1], me.map_.addOverlay, 0);
				/*window.setTimeout(function() {
		    			me.map_.addOverlay.call(me.map_, new SJPlacemark(me.groups_[groupnumber], me.data_[i].name, me.data_[i].id, description, me.data_[i].coordinates[x]));
		  		}, i);*/
				//me.objectSetTimeout_(me.map_, me.sjplacemarks_[me.sjplacemarks_.length - 1], me.map_.addOverlay, i * 10);
				//me.map_.addOverlay(me.sjplacemarks_[me.sjplacemarks_.length - 1]);
				//me.map_.removeOverlay(me.sjplacemarks_[me.sjplacemarks_.length - 1]);
				//me.sjplacemarks_[me.sjplacemarks_.length - 1] = null;
				//me.objectSetTimeout_(me, me.sjplacemarks_.length - 1, me.ProgressLoadingBar, i * 10);
			}
			index++;
			/*window.setTimeout(function() {
				loadingbartxt.innerHTML = "Testing " + i;
			}, 0);*/
			//me.objectSetTimeout_(me, i, me.ProgressLoadingBar, i * 10);
		}

		if (me.map_.Legend.type === "LegendControl") {
			for (i in me.groups_)
			{
				var imagesarray = [];
				if (me.groups_[i].haspoint === true)
				{
					imagesarray.push(MapIconMaker.createMarkerIcon({width:14, height:24, primaryColor: me.groups_[i].color, cornerColor: me.groups_[i].color, strokeColor: "#000000"}).image);
				}
				if (me.groups_[i].haspolyline === true)
				{
					imagesarray.push("http://chart.apis.google.com/chart?chs=14x24&cht=ls&chco=" + me.groups_[i].color.replace("#", "") + "&chls=4,0,0&chd=t:0,65,45,100");
				}
				me.map_.Legend.AddEntry(new LegendEntry(imagesarray, me.groups_[i].id));
			}
		}
		
		//window.setTimeout(function() {me.loadingbarpane.style.zIndex = "-7000";}, jdata.data.length * 10);
		me.objectSetTimeout_(me, 0, me.ProgressLoadingBar, 0);
		//me.objectSetTimeout_(me, null, me.HideLoadingBar, (jdata.data.length * 10) + 700);
	});

	SJCityOverlays.push(me);
};

SJCityOverlay.prototype.remove = function() {
	var i;
	for (i = 0; i < this.sjplacemarks_.length; i++)
	{
		this.map_.removeOverlay(this.sjplacemarks_[i]);
		this.sjplacemarks_[i] = null;
	}
	this.sjplacemarks_ = null;
};

SJCityOverlay.prototype.copy = function() {
	return new SJCityOverlay(this.url_, this.type);
};

SJCityOverlay.prototype.redraw = function(force) {
	if (!force) {
		return;
	}
};

//GList provides a list of markers added to the map
function listsort(l,r) {
	if (l.sort < r.sort) {
		return -1;
	}
	if (l.sort === r.sort) {
		return 0;
	}
	return 1;
}

function dlistsort(l,r) {
	if (l.sort > r.sort) {
		return -1;
	}
	if (l.sort === r.sort) {
		return 0;
	}
	return 1;
}

function MarkerListEntry(id, marker, div) {
	this.id = id;
	this.markers = [];
	this.markers.push(marker);
	this.div = div;
	this.sort = "";
}

function GList(groupbyname) {
	this.groupbyname = groupbyname;
}

GList.prototype = new GControl();

GList.prototype.ListDiv_ = "";

GList.prototype.initialize = function(map) {
	var me = this;
	var Width = "203px";
	var container = document.createElement("div");
	var button = document.createElement("div");
	var listdiv = document.createElement("div");
	var listhtml = "";

	this.listentries = [];
	me.map_ = map;
	button.innerHTML = "Show List";
	button.style.width = Width;
	button.style.fontFamily = "Arial";
	button.style.fontSize = "8pt";
	button.style.backgroundColor = "#FFFFFF";
	button.style.border = "1px solid black";
	button.style.textAlign = "center";
	button.style.cursor = "pointer";

	GEvent.addDomListener(button, "click", function() {
		if (button.innerHTML === "Hide List") {
			listdiv.style.visibility = "hidden";
			listdiv.style.zIndex = "-7";
			button.innerHTML = "Show List";
		}
		else {
			listdiv.style.visibility = "visible";
			listdiv.style.zIndex = "100";
			button.innerHTML = "Hide List";
		}
	});

	container.appendChild(button);

	listdiv.style.width = Width;
	listdiv.style.height = parseInt(map.getContainer().style.height.replace("px", ""), 10) - 60 + "px";
	listdiv.style.fontFamily = "Arial";
	listdiv.style.fontSize = "8pt";
	listdiv.style.zIndex = "-70";
	listdiv.style.backgroundColor = "#FFFFFF";
	listdiv.style.border = "1px solid black";
	listdiv.style.textAlign = "left";
	listdiv.style.cursor = "pointer";
	listdiv.style.visibility = "hidden";
	listdiv.style.overflow = "auto";

	listdiv.innerHTML = listhtml;

	container.appendChild(listdiv);

	map.getContainer().appendChild(container);

	GEvent.addDomListener(map.getContainer(), "resize", function() {
		var oldheight_ = parseInt(this.style.height.replace("px", ""), 10);
		listdiv.style.height = oldheight_ - 60 + "px";
	});
	this.ListDiv_ = listdiv;
	map.List = this;
	return container;
};

GList.prototype.addEntry = function (overlay) {
	var me = this;
	var i, isfound, foundindex, foundentry;
	var bounds, bzoom_;
	if (me.groupbyname === false)
	{
		var newmarkerlist = document.createElement("div");
		newmarkerlist.innerHTML = overlay.name_;
		newmarkerlist.style.borderBottom = "1px solid #EEEEEE";
		newmarkerlist.style.padding = "0px 0px 0px 4px";
		me.listentries.push(new MarkerListEntry(overlay.id_, overlay, newmarkerlist));
		GEvent.addDomListener(newmarkerlist, "click", function() { 
			if (overlay.markertype === "Point") {
				me.map_.setCenter(overlay.marker_.getLatLng(), 14);
			}
			else if (overlay.markertype === "Polyline" || overlay.markertype === "Polygon") {
				bounds = overlay.marker_.getBounds();
				bzoom_ = me.map_.getBoundsZoomLevel(bounds);
				if (bzoom_ > 14) 
				{
					bzoom_ = 14;
				}
				me.map_.setCenter(bounds.getCenter(), bzoom_);
			}
		});
		GEvent.addDomListener(newmarkerlist, "mouseover", function() {
			//newmarkerlist.innerHTML = overlay.name_;
			//alert(overlay.marker_.getLatLng());
			overlay.Highlight();
			newmarkerlist.style.backgroundColor = overlay.highlight.getHex();
		});
		GEvent.addDomListener(newmarkerlist, "mouseout", function() {
			overlay.removeHighlight();
			newmarkerlist.style.backgroundColor = "#FFFFFF";
		});
		overlay.addEvent("mouseover", function() {
			newmarkerlist.style.backgroundColor = overlay.highlight.getHex();
		});
		overlay.addEvent("mouseout", function() {
			newmarkerlist.style.backgroundColor = "#FFFFFF";
		});
		me.ListDiv_.appendChild(newmarkerlist);
	}
	else
	{
		isfound = false;
		for (i = 0; i < me.listentries.length; i++)
		{
			if (me.listentries[i].id === overlay.name_)
			{
				isfound = true;
				foundentry = me.listentries[i];
			}
		}
		if (isfound)
		{
			foundentry.markers.push(overlay);
			overlay.addEvent("mouseover", function() {
				foundentry.div.style.backgroundColor = overlay.highlight.getHex();
			});
			overlay.addEvent("mouseout", function() {
				foundentry.div.style.backgroundColor = "#FFFFFF";
			});
		}
		else
		{
			var newmarkerlist = document.createElement("div");
			newmarkerlist.innerHTML = overlay.name_;
			newmarkerlist.style.borderBottom = "1px solid #EEEEEE";
			newmarkerlist.style.padding = "0px 0px 0px 4px";
			var newlistentry = new MarkerListEntry(overlay.name_, overlay, newmarkerlist);
			me.listentries.push(newlistentry);
			var listentryindex = me.listentries.length - 1;
			GEvent.addDomListener(newmarkerlist, "click", function() { 
				bounds = new GLatLngBounds();
				for (i = 0; i < newlistentry.markers.length; i++)
				{
					if (newlistentry.markers[i].markertype === "Point") {
						bounds.extend(newlistentry.markers[i].marker_.getLatLng());
					}
					else if (newlistentry.markers[i].markertype === "Polyline" || newlistentry.markers[i].markertype === "Polygon") {
						bounds.extend(newlistentry.markers[i].marker_.getBounds().getNorthEast());
						bounds.extend(newlistentry.markers[i].marker_.getBounds().getSouthWest());
					}
				}
				bzoom_ = me.map_.getBoundsZoomLevel(bounds);
				if (bzoom_ > 14) 
				{
					bzoom_ = 14;
				}
				me.map_.setCenter(bounds.getCenter(), bzoom_);
			});
			GEvent.addDomListener(newmarkerlist, "mouseover", function() {
				for (i = 0; i < newlistentry.markers.length; i++)
				{
					newlistentry.markers[i].Highlight();
				}
				newlistentry.div.style.backgroundColor = overlay.highlight.getHex();
			});
			GEvent.addDomListener(newmarkerlist, "mouseout", function() {
				for (i = 0; i < newlistentry.markers.length; i++)
				{
					newlistentry.markers[i].removeHighlight();
				}
				newlistentry.div.style.backgroundColor = "#FFFFFF";
			});
			overlay.addEvent("mouseover", function() {
				newlistentry.div.style.backgroundColor = overlay.highlight.getHex();
			});
			overlay.addEvent("mouseout", function() {
				newlistentry.div.style.backgroundColor = "#FFFFFF";
			});
			me.ListDiv_.appendChild(newlistentry.div);
		}
	}
};

GList.prototype.removeEntry = function (overlay) {
	var me = this;
	var notfound = true;
	var x;

	if (me.listentries.length > 0) {
		for(x = 0; notfound === true; x++)
		{
			if (overlay.id_ === me.listentries[x].id || overlay.name_ === me.listentries[x].id)
			{
				me.ListDiv_.removeChild(me.listentries[x].div);
				//map.removeOverlay(overlay);
				me.listentries.splice(x, 1);
				notfound = false;
			}
			if (x >= me.listentries.length - 1) {
				notfound = false;
			}
		}
	}
};

GList.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 27));
};

//Legend provides a legend for the map
var legendoverlays_ = [];

function LegendEntry(iconhtml, name, hascheck)
{
	this.iconhtml = iconhtml;
	this.name = name;
	if (hascheck !== undefined && hascheck !== null) {
		this.hascheck = hascheck;
	} else {
		this.hascheck = true;
	}
}

function LegendControl() {
	this.type = "LegendControl";
}

LegendControl.prototype = new GControl();

LegendControl.prototype.LegendEntries_ = [];

LegendControl.prototype.AddEntry = function(entry)
{
	var me = this;
	var newrow_ = document.createElement("tr");
	var newselectcol_ = document.createElement("td");
	var x, xx;
	var newimagecol_ = document.createElement("td");
	var newnamecol_ = document.createElement("td");

	newrow_.style.width = "100%";
	if (entry.hascheck) {
		var newcheck_ = document.createElement("input");
		newcheck_.id = entry.name + "check";
		newcheck_.type = "checkbox";
		newcheck_.checked = true;
		GEvent.addDomListener(newcheck_, "click", function() {
			if (newcheck_.checked === false)
			{
				for (x = 0; x < SJCityOverlays.length; x++)
				{
					for (xx = 0; xx < SJCityOverlays[x].sjplacemarks_.length; xx++)
					{
						if (SJCityOverlays[x].sjplacemarks_[xx].group === entry.name) {
							SJCityOverlays[x].sjplacemarks_[xx].Remove();
						}
					}
				}
			}
			else
			{
				for (x = 0; x < SJCityOverlays.length; x++)
				{
					for (xx = 0; xx < SJCityOverlays[x].sjplacemarks_.length; xx++)
					{
						if (SJCityOverlays[x].sjplacemarks_[xx].group === entry.name) {
							SJCityOverlays[x].sjplacemarks_[xx].Add(true);
						}
					}
				}
			}
		});
		newselectcol_.appendChild(newcheck_);
	}
	newimagecol_.innerHTML = "";
	for (x = 0; x < entry.iconhtml.length; x++)
	{
		newimagecol_.innerHTML += "<img src='" + entry.iconhtml[x] + "' />";
	}

	newnamecol_.style.textAlign = "left";
	newnamecol_.innerHTML += entry.name;
	newrow_.appendChild(newselectcol_);
	newrow_.appendChild(newimagecol_);
	newrow_.appendChild(newnamecol_);
	document.getElementById("legendtbody").appendChild(newrow_);
	if (entry.hascheck) {
		document.getElementById(entry.name + "check").checked = true;
	}
	this.LegendEntries_.push(entry);
};

LegendControl.prototype.setVisibility = function (isvisible)
{
	if (isvisible === false)
	{
		legendbutton.innerHTML = "Hide Legend";
		legenddiv.style.visibility = "visible";
	}
	else
	{
		legendbutton.innerHTML = "Show Legend";
		legenddiv.style.visibility = "hidden";
	}
};

LegendControl.prototype.initialize = function(map) {
	var me = this;
	me.map_ = map;
	me.map_.Legend = this;
	var container = document.createElement("div");
	var legenddiv = document.createElement("div");
	var legendbutton = document.createElement("div");
	var newtable_ = document.createElement("table");
	var newtablebody_ = document.createElement("tbody");
	var i;

	legenddiv.style.width = "200px";
	legenddiv.style.backgroundColor = "#FFFFFF";
	legenddiv.style.textAlign = "center";
	legenddiv.style.fontFamily = "Arial";
	legenddiv.style.fontSize = "9pt";
	legenddiv.style.border = "1px solid black";
	legenddiv.style.padding = "2px 5px 2px 5px";
	legenddiv.innerHTML = "<span style='color:#CD9B1D;text-align:center;width:100%;'>Legend</span><br /><hr />";

	newtablebody_.id = "legendtbody";
	newtable_.style.width = "100%";
	newtable_.appendChild(newtablebody_);
	legenddiv.appendChild(newtable_);
	for (i = 0; i < this.LegendEntries_.length; i++)
	{
		legenddiv.innerHTML += "<div style='height:27px;'><div style='float:left;'>" + this.LegendEntries_[i].iconhtml + "</div> <div style='float:right;'>" + this.LegendEntries_[i].name + "</div></div>";
	}

	container.appendChild(legenddiv);

	legendbutton.style.fontFamily = "Arial";
	legendbutton.style.fontSize = "8pt";
	legendbutton.style.backgroundColor = "#FFFFFF";
	legendbutton.style.border = "1px solid black";
	legendbutton.style.textAlign = "center";
	legendbutton.style.cursor = "pointer";
	legendbutton.innerHTML = "Hide Legend";
	container.appendChild(legendbutton);
	GEvent.addDomListener(legendbutton, "click", function() {
		if (legenddiv.style.visibility === "hidden")
		{
			legendbutton.innerHTML = "Hide Legend";
			legenddiv.style.visibility = "visible";
		}
		else
		{
			legendbutton.innerHTML = "Show Legend";
			legenddiv.style.visibility = "hidden";
		}
	});
	map.getContainer().appendChild(container);
	return container;
};

LegendControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(2, 32));
};

//Color class, provides various functionality for creating and manipulating colors

function d2h(d) {
	var h2r = d.toString(16).toUpperCase();
	if (h2r.length === 1) {
		h2r = "0" + h2r;
	}
	return h2r;
}
function h2d(h) {return parseInt(h,16);} 

function FromRGB(r, g, b)
{
	var _returncolor = new COLOR();
	_returncolor._r = r;
	_returncolor._g = g;
	_returncolor._b = b;

	_returncolor._RGBToHex();
	_returncolor._RGBToHSL();

	return _returncolor;
}

function FromHex(hex)
{
	var returncolor = new COLOR();
	returncolor._hex = hex;

	returncolor._HexToRGB();
	returncolor._RGBToHSL();

	return returncolor;
}

function FromHSL(h, s, l)
{
	var _returncolor = new COLOR();
	_returncolor._h = h;
	_returncolor._s = s;
	_returncolor._l = l;

	_returncolor._HSLToRGB();
	_returncolor._RGBToHex();

	return _returncolor;
}

function setR(r)
{
	this._r = r;

	this._RGBToHex();
	this._RGBToHSL();
}

function getR()
{
	return this._r;
}

function setG(g)
{
	this._g = g;

	this._RGBToHex();
	this._RGBToHSL();
}

function getG()
{
	return this._g;
}

function setB(b)
{
	this._b = b;

	this._RGBToHex();
	this._RGBToHSL();
}

function getB()
{
	return this._b;
}

function setHex(hex)
{
	this._hex = hex;

	this._HexToRGB();
	this._RGBToHSL();
}

function getHex()
{
	return this._hex;
}

function setH(h)
{
	this._h = h;

	this._HSLToRGB();
	this._RGBToHex();
}

function getH()
{
 	return this._h;
}

function setS(s)
{
	this._s = s;

	this._HSLToRGB();
	this._RGBToHex();
}

function getS()
{
	return this._s;
}

function setL(l)
{
	this._l = l;

	this._HSLToRGB();
	this._RGBToHex();
}

function getL()
{
	return this._l;
}

function RGBToHex()
{
	var hr = d2h(this._r);
	var hg = d2h(this._g);
	var hb = d2h(this._b);

	if (hr.length === 0) {
		hr = "0" + hr;
	}
	if (hg.length === 0) {
		hg = "0" + hg;
	}
	if (hb.length === 0) {
		hb = "0" + hb;
	}

	this._hex = "#" + hr + hg + hb;
}

function RGBToHSL()
{
	var r = this._r / 255;
	var g = this._g / 255;
	var b = this._b / 255;

	var min, max;
	if (r <= g && r <= b) {
		min = r;
	}
	if (g <= r && g <= b) {
		min = g;
	}
	if (b <= r && b <= g) {
		min = b;
	}
	if (r >= g && r >= b) {
		max = r;
	}
	if (g >= r && g >= b) {
		max = g;
	}
	if (b >= r && b >= g) {
		max = b;
	}

	if (max === min)
	{
		this._h = 0;
	}
	else if (max === r && g >= b)
	{
		this._h = 60 * ((g - b) / (max - min)) + 0;
	}
	else if (max === r && g < b)
	{
		this._h = 60 * ((g - b) / (max - min)) + 360;
	}
	else if (max === g)
	{
		this._h = 60 * ((b - r) / (max - min)) + 120;
	}
	else if (max === b)
	{
		this._h = 60 * ((r - g) / (max - min)) + 240;
	}

	this._l = (1/2) * (max + min);

	if (max === min) {
		this._s = 0.0;
	}
	else if (this._l <= (1/2)) {
		this._s = (max - min) / (2 * this._l);
	}
	else if (this._l > (1/2)) {
		this._s = (max - min) / (2 - (2 * this._l));
	}

	if (this._h > 360) {
		this._h = 360;
	}
	if (this._h < 0) {
		this._h = 0;
	}
	if (this._s > 1.0) {
		this._s = 1.0;
	}
	if (this._s < 0) {
		this._s = 0;
	}
	if (this._l > 1.0) {
		this._l = 1.0;
	}
	if (this._l < 0) {
		this._l = 0;
	}
}

function HexToRGB()
{
	var hexparse = this._hex.replace(/#/, "");
	var hr = hexparse.substr(0, 2);
	var hg = hexparse.substr(2, 2);
	var hb = hexparse.substr(4, 2);

	this._r = h2d("0x" + hr);
	this._g = h2d("0x" + hg);
	this._b = h2d("0x" + hb);
}

function HSLToRGB()
{
	var q;
	if (this._l < 0.5)
	{
		q = this._l * (1 + this._s);
	}
	if (this._l >= 0.5)
	{
		q = this._l + this._s - (this._l * this._s);
	}

	var p = 2 * this._l - q;

	var hk = this._h / 360;

	var colors = [];
	colors[0] = hk + (1/3);
	colors[1] = hk;
	colors[2] = hk - (1/3);

	for (var i = 0; i < colors.length; i++)
	{
		if (colors[i] < 0.0) {
			colors[i] += 1.0;
		}
		if (colors[i] > 1.0) {
			colors[i] -= 1.0;
		}

		if (colors[i] < (1/6))
		{
			colors[i] = p + ((q - p) * 6 * colors[i]);
		}
		else if (colors[i] <= (1/6) || colors[i] < (1/2))
		{
			colors[i] = q;
		}
		else if (colors[i] <= (1/2) || colors[i] < (2/3))
		{
			colors[i] = p + ((q - p) * 6 * ((2/3) - colors[i]));
		}
		else
		{
			colors[i] = p;
		}
	}

	this._r = Math.ceil(colors[0] * 255);
	this._g = Math.ceil(colors[1] * 255);
	this._b = Math.ceil(colors[2] * 255);
}

function COLOR()
{
	this._r = 0;
	this._g = 0;
	this._b = 0;
	this._hex = 0;
	this._h = 0;
	this._s = 0;
	this._b = 0;

	this.FromRGB = FromRGB;
	this.FromHex = FromHex;
	this.FromHSL = FromHSL;

	this._RGBToHex = RGBToHex;
	this._RGBToHSL = RGBToHSL;
	this._HexToRGB = HexToRGB;
	this._HSLToRGB = HSLToRGB;

	this.setR = setR;
	this.setG = setG;
	this.setB = setB;
	this.setHex = setHex;
	this.setH = setH;
	this.setS = setS;
	this.setL = setL;
	this.getR = getR;
	this.getG = getG;
	this.getB = getB;
	this.getHex = getHex;
	this.getH = getH;
	this.getS = getS;
	this.getL = getL;
}

var Color = new COLOR();

//GButton control provides a way to add buttons to the map

var numberofbuttons = 0;

function GButton(name, functioncall) {
	this.name = name;
	this.functioncall = functioncall;
}

GButton.prototype = new GControl();

GButton.prototype.initialize = function(map) {
	numberofbuttons++;
	var container = document.createElement("div");
	var button = document.createElement("div");

	button.style.width = "100px";
	button.style.fontFamily = "Arial";
	button.style.fontSize = "10pt";
	button.style.backgroundColor = "#FFFFFF";
	button.style.border = "1px solid black";
	button.style.textAlign = "center";
	button.style.cursor = "pointer";
	button.innerHTML = this.name;

	container.appendChild(button);
	GEvent.addDomListener(button, "click", this.functioncall);

	map.getContainer().appendChild(container);
	return container;
};

GButton.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(85 + ((numberofbuttons - 1) * 105), 7));
};

//NameOverlay class provides a way to display the name of the marker when hovered over
function NameOverlay(name, marker) {
	this.name_ = name;
	this.marker_ = marker;
}

NameOverlay.prototype = new GOverlay();

NameOverlay.prototype.initialize = function(map) {
	var div = document.createElement("div");
	div.style.border = "1px solid black";
	div.style.position = "absolute";
	div.style.height = "50px";
	div.style.width = "150px";
	div.style.color = "#003366";
	div.style.fontFamily = "Arial";
	div.style.fontSize = "7pt";
	div.style.textAlign = "center";
	//div.style.top = map.fromLatLngToDivPixel(this.marker_.getLatLng().lat());
	//div.style.top = map.fromLatLngToDivPixel(this.marker_.getLatLng().lng());
	div.style.backgroundImage = "url('http://www.sanjoseca.gov/images/leftnav_bg.gif')";
	div.innerHTML = "<table style='width:100%;height:100%;'><tr><td valign='center' align='center'><span style='font-size:9pt;'>" + this.name_ + "</span></td></tr></table>";

	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
};

NameOverlay.prototype.remove = function() {
	this.div_.parentNode.removeChild(this.div_);
};

NameOverlay.prototype.copy = function() {
	return new NameOverlay(this.name_, this.marker_);
};

NameOverlay.prototype.redraw = function(force) {
	if (!force) {
		return;
	}
	var mLatLng;

	if (this.marker_.type === "Marker") {
		mLatLng = this.marker_.getLatLng();
	}
	if (this.marker_.type === "Polyline" | this.marker_.type === "Polygon") {
		mLatLng = this.marker_.getVertex(0);
	}
	this.div_.style.left = (this.map_.fromLatLngToDivPixel(mLatLng).x + 7) + "px";
	this.div_.style.top = (this.map_.fromLatLngToDivPixel(mLatLng).y - 80) + "px";
};

//DirectionsControl provides a way to find a display driving directions
var pointclicked_;

function DirectionsControl() {
	this.type = "DirectionsControl";
}

DirectionsControl.prototype = new GControl();

DirectionsControl.prototype.addDirections = function(addressstring) {
	this.Button_.style.visibility = "visible";
	this.ListDiv_.style.visibility = "visible";
	this.Container_.style.zIndex = "100";
	this.gdirections_.clear();
	this.gdirections_.load(addressstring);
};

DirectionsControl.prototype.ListDiv_ = "";

DirectionsControl.prototype.initialize = function(map) {
	var me = this;
	me.map_ = map;
	me.map_.Directions = me;
	var Width = "300px";
	var container = document.createElement("div");
	container.style.zIndex = "-7";

	var button = document.createElement("div");
	button.innerHTML = "Clear Directions";
	button.style.width = Width;
	button.style.fontFamily = "Arial";
	button.style.fontSize = "8pt";
	button.style.backgroundColor = "#FFFFFF";
	button.style.border = "1px solid black";
	button.style.textAlign = "center";
	button.style.cursor = "pointer";
	button.style.visibility = "hidden";

	var listdiv = document.createElement("div");
	listdiv.style.width = Width;
	listdiv.style.height = parseInt(map.getContainer().style.height.replace("px", ""), 10) - 60 + "px";
	listdiv.style.fontFamily = "Arial";
	listdiv.style.fontSize = "8pt";
	listdiv.style.backgroundColor = "#FFFFFF";
	listdiv.style.border = "1px solid black";
	listdiv.style.textAlign = "left";
	listdiv.style.cursor = "pointer";
	listdiv.style.overflow = "auto";
	listdiv.style.visibility = "hidden";

	GEvent.addDomListener(button, "click", function() {
		me.gdirections_.clear();
		me.Button_.style.visibility = "hidden";
		me.ListDiv_.style.visibility = "hidden";
		me.Container_.style.zIndex = "-7";
	});

	container.appendChild(button);
	container.appendChild(listdiv);

	map.getContainer().appendChild(container);

	GEvent.addDomListener(map.getContainer(), "resize", function() {
		listdiv.style.height = parseInt(this.style.height.replace("px", ""), 10) - 60 + "px";
	});
	this.Button_ = button;
	this.ListDiv_ = listdiv;
	this.Container_ = container;

	this.gdirections_ = new GDirections(map, listdiv);
	return container;
};

DirectionsControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 27));
};