/**
 * The language selector static class.
 * 
 * @version 2010-08-13
 * @author <a href="mailto:r.tennapel@griponservice.nl?SUBJECT=LanguageSelector script.js">R. ten Napel, ing.</a>
 **/
function LanguageSelector() {}

/**
 * This function shows the options.
 * 
 * @param e			The event that is triggered.
 * @param element	The widget element that holds everything.
 **/
LanguageSelector.show = function(e, element) {
	// Ensure the event:
	var e = e ? e : window.event;
	
	// Retrieve the chain wrapper:
	var chain = $(element.children[1]);
	
	// Retrieve the mouse position & alter for the options box:
	var pos = GlobalKit.mousePos(e);
	pos.x -= 4;
	pos.y -= 4;
	
	// Retrieve box bounds:
	var old = chain.getStyle("position");
	var box = chain.setStyle("position", "absolute").show().getBox();
	chain.setStyle("position", old);
	
	// Alter if out of screen:
	if (pos.x < 0) {
		pos.x = 20;
	} else if ((pos.x + box.w) > GlobalKit.screenWidth()) {
		pos.x = GlobalKit.screenWidth() - box.w - 20;
	}
	if (pos.y < 0) {
		pos.y = 20;
	} else if ((pos.y + box.h) > GlobalKit.screenHeight()) {
		pos.y = GlobalKit.screenHeight() - box.h - 20;
	}
	
	// Set the position:
	chain.setPos(pos);
};

//Store the LanguageSelector static JS class:
Widget.addClass("LanguageSelector", LanguageSelector);
