if (typeof Prototype == 'undefined' || !(Prototype.Version.match("1.6") || Prototype.Version.match("1.7")))
	throw ("GlobalEagle-GUI library requires Prototype library >= 1.6.0");
if (typeof jQuery == 'undefined')
	throw ("GlobalEagle-GUI library requires jQuery library");

// 04.02.2010 Ossig GUI Available in EVERY window.

Object.extend(GUI, {
	ContextMenu: Class.create({
		initialize: function(contextButtonID, contextMenuID, callbackMap, opt) {
			if (!window.jQuery.fn.contextMenu)
				throw ("GlobalEagle-GUI library requires jQuery contextMenu");
			function callback(actionMap, actionID, contextButtonElement, pos) {
				if (!actionMap) return;
				var action = actionMap[actionID];
				if (!Object.isFunction(action)) return;
				action();
			}
			this._jContextMenu = $j("#" + contextButtonID).contextMenu(Object.extend({ menu: contextMenuID, leftButton: true }, opt || {}), callback.curry(callbackMap));
		},
		dispose: function() {
			var jContextMenu = this._jContextMenu;
			if (!jContextMenu) return;
			jContextMenu.destroyContextMenu();
			this._jContextMenu = undefined;
		}
	})
});

Object.extend(GUI, {
	ContextMenuDyn: Class.create(GUI.ContextMenu, {
		initialize: function($super, contextButtonID, menuEntryList, opt) {
			var contextMenuElement = new Element("ul", { "class": "contextMenu ui-corner-all" });
			// document.body.insert(contextMenuElement);
			$(contextButtonID).insert({ after: contextMenuElement });
			var contextDivElement = new Element("div");
			contextMenuElement.insert(contextDivElement);

			if (!Object.isArray(menuEntryList)) menuEntryList = [menuEntryList];
			var callbackMap = {};
			menuEntryList.each(function(contextButton) {
				var element = new GUI.GESymbolLink({ symbolClassName: contextButton.symbol, value: contextButton.name, classArr: contextButton.className, bgSymbol: false }).element;
				var id = element.identify();
				element.writeAttribute("href", "#" + id);
				callbackMap[id] = contextButton.callback;
				contextDivElement.insert(new Element("li").insert(element));
			});
			$super(contextButtonID, contextMenuElement.identify(), callbackMap, opt);
			this.element = contextMenuElement;
		},
		dispose: function($super) {
			$super();
			if (this.element) {
				this.element.remove();
				this.element = undefined;
			}
		}
	}),
	goToByScroll: function(id) {
		// $j("html,body").animate({ scrollTop: $j("#" + id).offset().top }, "slow");
		$j("html,body").animate({ scrollTop: $j("#" + id).offset().top }, "fast");
	}
});