
function AddDefectButtonSelect()
{
	Mapping.Toolbar.Buttons.Utility._updateDrawingSymbol(this.toolbar.target, Mapping.SymbolType.Circle);
	Tools.ToolBox.use("AddDefect", this.toolbar.target);
	return true;
}

function AddDefectButtonDeselect()
{
	if (Tools.ToolBox.current)
		Tools.ToolBox.current.stop();
	
	return true;
}

Tools.AddDefectTool = Class.inherit(Tools.ToolBase, 
{
	initialize: function()
	{
		this.base("AddDefect");
		this.onadd = null;
		this.oncancel = null;
		
		Tools.ToolBox.add(this);
	},
	
	// start the tool for the specified map
	start: function(map)
	{
		if (this.running)
			return false;
		
		this._onmousedown = map.image.onmousedown;
		map.image.onmousedown = this.onmousedown.bindAsEventListener(this);
		
		Drawing.Window.setCursor("crosshair", map.image);
		map.showInformation("Click on the map to report a defect at that location", this.id);
		
		return this.activate(map);
	},
	
	// stop the tool
	stop: function()
	{
		Drawing.Window.setCursor("auto", this.map.image);
		this.map.hideInformation(this.id);
		
		this.map.image.onmousedown = this._onmousedown;
		this.deactivate();
	},
	
	// onmousedown
	onmousedown: function(e)
	{
		if (!this.running)
			return;
		
		this.onevent(e);
		
		var symbolId = this.map.drawSymbol(new Mapping.IntegerPoint(this.map.mouseX(), this.map.mouseY()), 
			Mapping.SymbolType.Circle, 16, Drawing.Colors.Red, Drawing.Colors.Transparent, Drawing.Colors.White, true);
		
		if (this.onadd != null)
			this.onadd(this.map, symbolId);
	}
});

