
function drawShape(shape, context) {
	shapes[shape.type].draw(shape, context);
}

function drawSelected(shape, context) {
	shapes[shape.type].drawSelected(shape, context);
}

function containsPoint(shape, point) {
	return shapes[shape.type].containsPoint(shape, point);
}

function moveShapeMagnet(shape, oldMagnet, newMagnet) {
	return shapes[shape.type].moveMagnet(shape, oldMagnet, newMagnet);
}

function isSelected(shape) {
	return shape.selected;
}

function showEditorPanel(shape) {
	var panel = document.getElementById("propertyEditor");
	while (panel.hasChildNodes()) {
		panel.removeChild(panel.firstChild);
	}
	panel.appendChild(document.createTextNode("Property Editor"));
	panel.appendChild(document.createElement("p"));
	if (shape) {
		if (shapes[shape.type].showEditorPanel) {
			shapes[shape.type].showEditorPanel(shape, panel);
		}
	}
}

function selectShape(shape) {
	selectNone();
	shape.selected = true;
	showEditorPanel(shape);
}

function shapeToSource(shape) {
	return shapes[shape.type].toSource(shape);
}

shapes = {
	"line" : line,
	"rectangle" : rectangle,
	"oval" : oval,
	"circle" : circle,
	"image" : image,
	"text" : text,
	"group" : group
}

