function LanguageSelection()
{
	this.oAjax				= new sack('index.php');
	this.resetAjax();

	this.oLanguageSelection = _gel('languageselection');
	this.oLanguageLink = _gel('languageswitch');
	this.visible = false;
}

LanguageSelection.prototype = {

	init : function()
	{
		if (this.oLanguageSelection && this.oLanguageLink) {
			this.oLanguageLink.onclick = this.showSelection;
			this.oLanguageLink.onmouseout = this.delayedHideLanguages;
			this.oLanguageSelection.onmouseover = this.clearHideLanguages;
			this.oLanguageSelection.onmouseout = this.delayedHideLanguages;
			this.oLanguageSelection.onclick = this.delayedHideLanguages;
		}
	},

	resetAjax : function()
	{
		this.oAjax.reset();
		this.oAjax.requestFile	= "index.php";
		this.oAjax.method		= "POST";
		this.oAjax.setVar('module', 'LanguageSelection');
	},

	showSelection : function()
	{
		if (oLanguageSelection.oLanguageLink) {
			oLanguageSelection.oLanguageLink.blur();
		}

		var leftBorder = Position.cumulativeOffset(oLanguageSelection.oLanguageLink)[0] + oLanguageSelection.oLanguageLink.offsetWidth;
		oLanguageSelection.oLanguageSelection.style.left = (leftBorder - 110) + 'px';
		oLanguageSelection.oLanguageSelection.style.top  = '18px';
		oLanguageSelection.oLanguageSelection.style.display = "block";
		oLanguageSelection.visible = true;
	},

	hideSelection : function()
	{
		oLanguageSelection.oLanguageSelection.style.display = "none";
	},

	delayedHideLanguages: function() {
		if (oLanguageSelection.visible){
			oLanguageSelection.clearHideLanguages();
			oLanguageSelection.delayID = setTimeout("oLanguageSelection.hideSelection()", 250);
		}
	},

	clearHideLanguages: function(){
		if (oLanguageSelection.delayID) {
			clearTimeout(oLanguageSelection.delayID);
			oLanguageSelection.delayID = null;
		}
	},

	send : function(iLanuageID, iMenuID)
	{
		this.resetAjax();

		if (iLanuageID > 0) {
			this.oAjax.setVar('event', 'on_LanguageSwitch');
			this.oAjax.setVar('language', iLanuageID);
			this.oAjax.setVar('menuid', iMenuID);
			this.oAjax.runAJAX();

			oThis = this;
			onCompletionAJAX = function () {
				oThis.writeOutput(oAJAX.responseText);
			};

		}
	},

	writeOutput : function(sResponse)
	{
		var oResponse = eval(sResponse);

		try {
			if (oResponse.sErrors != "" && oResponse.sErrors != undefined) {
				if (document.popup == null) document.popup = new isPopup();
				document.popup.show("OK", oResponse.sHeadline, 600, 200, oResponse.sErrors);
			}
		} catch (e) {
		}

		try {
			if (oResponse.sContent != "" && oResponse.sContent != undefined) {
				if (oResponse.sContent.indexOf("==") != -1) {
					var aResponse = oResponse.sContent.split("==");
					var sCommand = aResponse[0];
					var sValue = aResponse[1];
					if (sCommand == 'location') {
						window.location.href = sValue;
					}
				}
			}
		} catch (e) {
		}
	}
}

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
}