
function UfTileLayer(name, tileMap, copyright) {
	this.name = name;
	this.tileMap = tileMap;
	GTileLayer.call(this, copyright, 2, 4);
}

UfTileLayer.prototype = new GTileLayer(null);

UfTileLayer.prototype.getTileUrl = function(tile,  zoom)
{
	if (zoom <= this.maxResolution())
	{
		var baseUrl = "http://wcg.userfriendly.org/overlays/";
		var tileIndex = tile.x + tile.y * (Math.pow(2, zoom));
		var server = (tile.x + tile.y) % 2;
		var serverUrl = "http://wcg" + server + ".userfriendly.org/";
		
		var tileExists = false;
		
		var characterIndex = Math.floor(tileIndex / 4);
		if (characterIndex < this.tileMap[zoom - 2].length)
		{
			var character = this.tileMap[zoom - 2].charAt(characterIndex);
			var c = parseInt(character, 16);
			tileExists = ((c & Math.pow(2, 3 - (tileIndex % 4))) != 0);
		}
		
		if (tileExists)
		{
			return serverUrl + this.name + "/" + this.name + "." + zoom + "." + tile.x + "." + tile.y + ".png";
		}
	}
	return baseUrl + "blank.png";
}
//UfTileLayer.prototype.minResolution = function() { return 2;}
//UfTileLayer.prototype.maxResolution = function() { return 4;}
UfTileLayer.prototype.isPng = function() { return true;}
UfTileLayer.prototype.getOpacity = function() { return 1.0; }
//UfTileLayer.prototype.getCopyright = function() { return this.copyright; }