var SCALEBAR_WIDTH = 200;
var SCALEBAR_HEIGHT = 20;

function Scalebar(EventManager, sbMap, sbWidth, sbHeight) {
	var MySelf = this;
	
	var imgObj;
	
	function buildURL(sbCenterPoint, sbScale, mapWidth,mapHeight) {
		var url = SCALEBAR_CALL;
		var gisW = mapWidth / 2 * sbScale;
		var gisH = mapHeight / 2 * sbScale;
		var minCoords = new Point(sbCenterPoint.x - gisW, sbCenterPoint.y - gisH);
		var maxCoords = new Point(sbCenterPoint.x + gisW, sbCenterPoint.y + gisH);

		var sizeString = mapWidth+'+'+mapHeight;
		var coordsString = minCoords.toString('+')+'+'+maxCoords.toString('+');
		url = url.replace('[SIZE]',sizeString);
		url = url.replace('[EXTENTS]',coordsString);
		return url;
	}

	this.update = function(circ) {
		var cp = circ.Center;
		var scale = circ.Radius;
		var mapSize = sbMap.getMapSize();
		imgObj.src = buildURL(cp, scale, mapSize.x, mapSize.y);
	}

	this.setParent = function(p) {
		imgObj = document.createElement('img');
		/*imgObj.style.width = sbWidth+'px';
		imgObj.style.height = sbHeight+'px';*/
		p.appendChild(imgObj);
	}

}
