GMarker.prototype.getURI = function() {
	return "?x=" + this.point.x + "&y=" + this.point.y + "&z=4";
};

GMarker.prototype.updateLink = function(a) {
	a.href = this.getURI();
	this.map.savePos( this.getURI() );
};

GMarker.prototype.openLinkWindowHtml = function(a) {
	this.openInfoWindowHtml(
		"<div style='position:relative;min-width:200px;min-height:50px;'>" + 
		a + "<div class='gmaplink' style='position:absolute;bottom:0px;right:0px;'>" + 
		"<img src='http://maps.google.com/mapfiles/link_icon.gif'/> <a href='" + 
		this.getURI() + "'>Link to This</a></div>" );
};


GMap.prototype.getURI = function() {
	return "?x=" + this.getCenterLatLng().x + "&y=" +
		this.getCenterLatLng().y + "&z=" + this.getZoomLevel();
};

GMap.prototype.updateLink = function(a) {
	a.href = this.getURI();
	if ( this.links == null ) {
		this.links = new Array();
		GEvent.bind( this, "moveend", this, this.updateLinks );
		GEvent.bind( this, "zoom", this, this.updateLinks );
	}
	this.links.push(a);
	this.savePos( this.getURI() );
};

GMap.prototype.updateLinks = function() {
	for ( var i in this.links )
		this.links[i].href = this.getURI();
	this.savePos( this.getURI() );
};

GMap.prototype.savePos = function(a) {
	if ( this.cookieName != null ) {
		var date = new Date();
		date.setTime(date.getTime()+(1000*24*60*60*1000));
		document.cookie = "gMap" + this.cookieName + "=" + escape(a) + 
			"; expires="+date.toGMTString() + "; path=/";
	}
};

GMap.prototype.loadPos = function(a) {
	this.cookieName = a;
	if ( ! window.location.search ) {
		var nameEQ = "gMap" + a + "=";
		var ca = document.cookie.split(';');
		for ( var i=0; i < ca.length; i++ ) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) {
				var r = unescape(c.substring(nameEQ.length,c.length));
				this.gotoURI( r );
				return true;
			}
		}
	} else {
		this.gotoURI( window.location.search );
		return true;
	}
	return false;
};

GMap.prototype.gotoURI = function(a) {
	if ( a.indexOf('?') != -1 )
		a = a.substr( 1, a.length );
	var f = new Array();
	var p = a.split("&");
	for ( var i = 0; i < p.length; i++ ) {
		var k = p[i].split("=");
		f[ k[0] ] = k[1] - 0;
	}
	this.centerAndZoom( new GPoint( f.x, f.y ), f.z );
};

