var ROOTURL = ".";
var latestVersion = "latest";

// The X offset
// (The number of pixels that were trimmed from the left of the thumbnail
//   image, when it was created to start at 0,0 , but after it was halved
//   in size)
var xOffset = 38;

function gotoLocation(easting, northing, zoom) {
	gotoLocationFor(latestVersion, easting, northing, zoom);
}
function gotoLocationFor(version, easting, northing, zoom) {
    location.href = urlFor(version, easting, northing, zoom);
}


function click(e) {
	clickFor(latestVersion, e);
}
function buildClick(version) {
	return function(e) {
		return clickFor(version, e);
	}
}
function clickFor(version, e) {
	e = YAHOO.util.Event.getEvent(e);
	var img = YAHOO.util.Event.getTarget(e);
	var imgPos = YAHOO.util.Dom.getXY(img);

	var x = (xOffset + YAHOO.util.Event.getPageX(e) - imgPos[0]) * 2;
	var y = (img.height-(YAHOO.util.Event.getPageY(e) - imgPos[1])) * 2;

	location.href=(urlFor(version, x, y, 3));

	YAHOO.util.Event.stopEvent(e);
}

var zooms = new Array(1);
zooms[1] = 1;
zooms[2] = 3;
zooms[3] = 6;

function urlFor(version, easting, northing, zoom) {
  var x= Math.round(easting / zooms[zoom]); 
  var y= Math.round(northing/ zooms[zoom]); 
  if(version == latestVersion) {
     return ROOTURL + "/tiles/map.html#" + x + "," + y +","+zoom;
  } else {
     return ROOTURL + "/tiles/" + version +"s/map.html#"+x+","+y+","+zoom;
  }
}

