
gekkoContextMenu = new Object();

gekkoContextMenu.objects = new Array();

gekkoContextMenu.create = function(object) {

	if (!object.contextmenu) {
		var contextmenu = false;
		for (var i = 0; i < object.childNodes.length; i++) {
			if (object.childNodes[i].className == 'gekkoContextMenu') {
				contextmenu = object.childNodes[i];
				break;
			}
		}
		if (!contextmenu) {
			contextmenu = document.createElement('DIV');
			contextmenu.className = 'gekkoContextMenu';
			contextmenu.style.display = 'none';
			contextmenu.style.cursor = 'pointer';
			object.appendChild(contextmenu);
		}
		object.contextmenu = contextmenu;
	}

	document.setEventListener(object, 'mousedown',
		function (e) {
			var target = document.getEventTarget(e);
			for (var i = 0; i < gekkoContextMenu.objects.length; i++)
				gekkoContextMenu.objects[i].contextmenu.style.display = 'none';
			if (target.nodeName.toLowerCase() == 'a') {
				if (object.stopDragging)
					object.stopDragging();
				document.location = target.href;
			}
		}
	);

	document.setEventListener(object, 'contextmenu',
		function (e) {
			var object = document.getEventTarget(e);

			while (object && !object.contextmenu)
				object = object.parentNode;

			object.contextmenu.style.position = 'absolute';
			object.contextmenu.style.top = document.mouseY+'px';
			object.contextmenu.style.left = document.mouseX+'px';
			object.contextmenu.style.display = 'block';
			object.contextmenu.style.zIndex = '1000';

			document.cancelEvent(e);
			return false;

		}
	);

	gekkoContextMenu.objects.push(object);

	return (gekkoContextMenu.objects.length-1);
}

gekkoContextMenu.addLink = function(menu, text, href) {
	var a = document.createElement('A');
	a.innerHTML = text;
	a.href = href;
	gekkoContextMenu.objects[menu].contextmenu.appendChild(a);
}

gekkoContextMenu.appendContent = function(menu, html) {
	gekkoContextMenu.objects[menu].contextmenu.innerHTML += html;
}