"use strict";

// will not be obfuscated

var g_objCrossBrowserModel,
	TTAPI,
	GLOBAL,
	g_sActiveID;

onload = function () {
	if (typeof GLOBAL === "undefined") {
		return;
	}
	// lokale Anpassungen an HTML-Dokumenten
	if (GLOBAL["dir"]) {
		document.body.dir = GLOBAL["dir"];
	}
	if (GLOBAL["title"]) {
		try {
			top.document.title = GLOBAL["title"];
		} catch (e) {
			// Intentionally left blank
		}
	}
	if (window.location.search) {
		var sLocSearch = window.location.search,
			nPos = sLocSearch.indexOf("active=");
		if (nPos !== -1) {
			try {
				var nLinkID = sLocSearch.substring(nPos + "active=".length, sLocSearch.lastIndexOf("&")),
					objElem = document.getElementById(nLinkID);
				if (objElem) {
					ButtonOnMouseDown(objElem);
				}
			} catch (objError) {
			}
		}
	}
	if (typeof (TTAPI) === "object" && TTAPI != null) {
		g_objCrossBrowserModel = TTAPI.objCrossBrowserModel;

		// load customied css file?
		var sHelpCSS = TTAPI.GetProperty("helpcssfile2.all");
		if (sHelpCSS) {
			g_objCrossBrowserModel.LoadCSSFile(TTAPI.GetPathByProperty("helpcssfile2") + sHelpCSS, window, Continue_01);
		} else {
			Continue_01();
		}
	}
};

function Continue_01() {
	g_objCrossBrowserModel.AddEventListener(document, "keydown", OnHelp2KeyDown);

	var sLangDepHelpCSS = TTAPI.GetProperty("helpcssfile2." + GLOBAL["language"].replace("-", "_"));
	if (sLangDepHelpCSS) {
		g_objCrossBrowserModel.LoadCSSFile(TTAPI.GetPathByProperty("helpcssfile2") + sLangDepHelpCSS, window, null);
	}
	// In jedes IMG mit controlButton die entsprechende Grafik laden:
	var objImgs = document.getElementsByTagName("img"),
		sImgFolder = TTAPI.objCBTControl.sImgFolder,
		i = 0,
		nImgsLen = objImgs.length;
	for (; i < nImgsLen; i++) {
		if (objImgs[i].className.indexOf("controlButton") !== -1) {
			if (!objImgs[i].id) {
				continue;
			}
			g_objCrossBrowserModel.LoadAlphaImage(objImgs[i], sImgFolder + objImgs[i].id + ".png");
		}
	}
}

if (typeof parent.TTAPI === "object") {
	TTAPI = parent.TTAPI;
}

if (typeof parent.GLOBAL === "object") {
	GLOBAL = parent.GLOBAL;
	var sLanguage = GLOBAL["language"],
		playerPath = TTAPI.GetProperty("playerpath");
	if (sLanguage) {
		// TODO: als Property?
		document.write("<li" + "nk href=\"" + playerPath + sLanguage + "/player.help2." + sLanguage + ".css\" rel=\"stylesheet\" type=\"text/css\" />");
	}
}

function ButtonOnMouseDown(objButton) {
	if (g_sActiveID) {
		var objPrevItem = document.getElementById(g_sActiveID);
		if (objPrevItem) {
			g_objCrossBrowserModel.ReplaceCSSClass(objPrevItem, "ttwebtndown", "ttwebtnup");
		}
	}
	g_sActiveID = objButton.id;
	g_objCrossBrowserModel.ReplaceCSSClass(objButton, "ttwebtnup", "ttwebtndown");

	try {
		if (parent.frames && parent.frames[objButton.target] && objButton.href) {
			parent.frames[objButton.target].location.href = objButton.href;
		}
	} catch (objError) {
	}
}

function OnHelp2KeyDown(e) {
	try {
		// => an Sequence weitergeben:
		return TTAPI.objSequenceControl.onkeydown(e);
	} catch (objError) {
	}
	return true;
}
