
var umGame = "ob";
	// File and path names
var umOorMapTile = "images/"+umGame+"outofrange.jpg";
var umZoomIcon   = "images/zoomicon.gif";
var umBasePath   = "/maps/";
var umGameDir   =  umGame+"map";
var umGamePath   = umBasePath+umGameDir+"/";

	// For testing purposes only
//var umImagePath  = "";
//var umMapURL     = umGame+"map.shtml";

	// Live paths
var umImagePath  = "http://content1.uesp.net:81"+umBasePath;
var umMapURL     = "http://www.uesp.net"+umGamePath+umGame+"map.shtml";

var umGetMapURL  = "getmaplocs.php";
var umSetMapURL  = "setmaplocs.php";

	// Current request state
var umWaitingForReponse = 0;

	// Currently displayed map locations/labels
var umLocations = [];

	// Map properties and constants
var umMapDefaultCenter   = new GLatLng(89.85, -179.63);
var umMapBounds          = new GLatLngBounds(new GLatLng(89.62, -179.9999), new GLatLng(89.9999, -179.25));
var umMapDefaultZoom     = 11;
var umMapLinkZoomedValue = 15;
var umMinMapZoom         = 9;
var umMaxMapZoom         = 16;
var umBaseMapZoom        = 16;  // this is the zoom level at which one tile = one game cell
var umObCellSize         = 4096.0;
var umNumMapTilesX       = 133;
var umNumMapTilesY       = 129;
var umObCellOffsetX      = 64.0; // offset at BaseMapZoom
var umObCellOffsetY      = 60.0; // offset at BaseMapZoom
var umLocationIDCounter  = 0;
var umNoInitialGetMarkers = false;
var umWikiNameSpace       = "Oblivion";
var umGamePrefix          = "tamriel";

	// Main map objects
var umMap;
var umCustomMapType;
var umMapTileLayer;

	// Location class constructor
function CMapLocation(LocData) {
	if (LocData) {
		this.ID = parseInt(LocData.getAttribute("id"));
		this.X = Math.round(parseFloat(LocData.getAttribute("X")));
		this.Y = Math.round(parseFloat(LocData.getAttribute("Y")));
		this.Z = Math.round(parseFloat(LocData.getAttribute("Z")));
		this.Name = unescape(LocData.getAttribute("name"));
		this.Type = parseInt(LocData.getAttribute("type"));
		this.Worldspace = unescape(LocData.getAttribute("ws"));
		this.DisplayLevel = parseInt(LocData.getAttribute("level"));
		this.LabelPosition = parseInt(LocData.getAttribute("labpos"));
		this.WikiPage = unescape(LocData.getAttribute("page"));
		this.Tags = unescape(LocData.getAttribute("tags"));
		this.Namespace = umWikiNameSpace;
	}
	else {
		this.ID = this.X = this.Y = this.Z = 0;
		this.Name = '';
		this.Worldspace = "Tamriel";
		this.Namespace = umWikiNameSpace;
		this.Type = 0;
		this.LabelPosition = 8;
		this.DisplayLevel = 16;
	}

	this.MapPoint = umConvertLocToLatLng(this.X, this.Y);
	this.Label = null;
	this.LabelListener = null;
	this.Show = true;
	this.ResultElement = null;
}

	// Get map marker icon image file
function umGetMapMarkerIcon(MarkerType) {
	var Icon = "Other"
	switch (MarkerType) {
		case  0: Icon = "None"; break;
		case  1: Icon = "Camp"; break;
		case  2: Icon = "Cave"; break;
		case  3: Icon = "City"; break;
		case  4: Icon = "Ayleid"; break;	
		case  5: Icon = "Fort"; break;
		case  6: Icon = "Mine"; break;
		case  7: Icon = "Landmark"; break;
		case  9: Icon = "Town"; break;
		case 10: Icon = "Daedric"; break;
		case 11: Icon = "Oblivion"; break;
		case 30: Icon = "Nirnroot"; break;	
		case 40: Icon = "Door"; break;	
		case 41: Icon = "House"; break;	
		case 42: Icon = "Shop"; break;	
		case 44: Icon = "Tavern"; break;	
		case 100:
		default: Icon = "Other";
	}

	return umImagePath + "icons/icon" + Icon + ".gif";
}

	// Get a map marker description text
function umGetMapMarkerType(MarkerType) {

	switch(MarkerType) {
		case  0: return "None";
		case  1: return "Camp";
		case  2: return "Cave";
		case  3: return "City";
		case  4: return "Elven Ruin";
		case  5: return "Fort Ruin";
		case  6: return "Mine";
		case  7: return "Landmark";
		case  9: return "Settlement";
		case 10: return "Daedric Shrine";
		case 11: return "Oblivion Gate";
// 12 missing because it used to be unknown
		case 20: return "Ayleid Well";
		case 21: return "Doom Stone";
		case 22: return "Rune Stone";
		case 23: return "Wayshrine";
		case 30: return "Nirnroot";
		case 31: return "Treasure";
                case 40: return "Door";
                case 41: return "House";
		case 42: return "Shop";
		case 43: return "Chapel";
		case 44: return "Tavern";
		case 45: return "Guild";
		case 46: return "Castle";
		case 100:
		default: return "Other";
	}

	return "Other";
}

	// Add a location record to the end of the search results
function umAddSearchResult(Location) {
	var TypeText = umGetMapMarkerType(Location.Type);
	var NewLink  = umCreateLink(Location.MapPoint);

	var NewText = "<div id='umResult'><div id='umResultLink'><nobr><img id='umResultIcon' src='" + umGetMapMarkerIcon(Location.Type) + "' alt='[" + TypeText +"]' border=0> ";
	NewText += "<a href='" + NewLink + "' onClick='umShowLocation(" + Location.X + "," + Location.Y + "); return(false);'>" + Location.Name + "</A>";
	if (Location.Type) {
		NewText += " (" + TypeText + ")";
	}

	//if (umMap.getZoom() < umMapLinkZoomedValue || umMapState.HasSearch()) {
		var NewLinkZoom = umCreateLinkZoom(Location.MapPoint, umMapLinkZoomedValue);
		NewText += " <a href='" + NewLinkZoom + "' id='umResultZoom' onClick='umShowLocationZoom(" + Location.X + "," + Location.Y + ", " + umMapLinkZoomedValue + "); return(false);'>";
		NewText += "<img id='umZoomIcon' src='" + umImagePath + umZoomIcon + "' alt='[zoomto]' border='0'></a>";
	//}

	NewText += umCreateLocationEditLink(Location);

	NewText += "</nobr>";
	NewText += "</div>";
	NewText += "<div id='umResultLoc'>" + Location.Worldspace + " (" + Location.X + ", " + Location.Y + ")";

	if (Location.WikiPage) {
		NewText += "<a id='umResultWikiLink' href='http://www.uesp.net/wiki/" + Location.Namespace + ":" + escape(Location.WikiPage) + "' onclick='umTestClick();'>Wiki Page</a>";
	}

	NewText += "</div></div>";
	Location.ResultElement = umAddSearchResultText(NewText, Location.Name);
}

	// Makes a location content for a popup info window
function umMakeLocationInfoContent(Location) {
	var Content;

	Content  = "<div id='umLocationInfo'>";
	Content += "<div id='umLocationInfoName'>" + Location.Name + "</div>";
	if (Location.Type) {
		Content += "<div id='umLocationInfoType'>" + umGetMapMarkerType(Location.Type) + "</div>";
	}
	Content += "<div id='umLocationInfoPos'>Location: " + Location.Worldspace + " (" + Location.X + ", " + Location.Y + ", " + Location.Z + ")</div>";

	if (Location.WikiPage) {
		Content += "<div id='umLocationInfoLink'><a href='http://www.uesp.net/wiki/" + Location.Namespace + ":" + escape(Location.WikiPage) + "'>" + Location.Namespace + ":" + Location.WikiPage + "</a></div>";
	}

	Content += "</div>";
	return Content;
}

