var timer = new Array(10);

function highlightTMenu() {
 pth = document.location.pathname.toString();
if (pth.search(/^\/bewerbung-englisch/) > -1) document.getElementById("tn1").firstChild.className = "menuButtonActive_w";
else if (pth.search(/^\/zeugnisse-uebersetzen/) > -1) document.getElementById("tn2").firstChild.className = "menuButtonActive_w";
else if (pth.search(/^\/bewerbung-tipps/) > -1) document.getElementById("tn3").firstChild.className = "menuButtonActive_w";
else if (pth.search(/^\/bewerbungstraining/) > -1) document.getElementById("tn4").firstChild.className = "menuButtonActive_w";
else if (pth.search(/^\/preise/) > -1) document.getElementById("tn5").firstChild.className = "menuButtonActive";
else if (pth.search(/^\/team/) > -1) document.getElementById("tn6").firstChild.className = "menuButtonActive";
else if (pth.search(/^\/kontakt/) > -1) document.getElementById("tn7").firstChild.className = "menuButtonActive";
}

function activateMenu() {
  if (!document.getElementById("sn1")) document.write("<div id='sn1' onmouseover=\"clearTimeout(timer[1]);\" onmouseout=\"setSnTimer('1');\"><a href='/bewerbung-englisch/bewerbung-uebersetzen.html'>Bewerbungen &Uuml;bersetzen</a></div>");
  if (!document.getElementById("sn2")) document.write("<div id='sn2' onmouseover=\"clearTimeout(timer[2]);\" onmouseout=\"setSnTimer('2');\"><a href='/zeugnisse-uebersetzen/schreibservice.html'>Schreibservice</a><a href='/zeugnisse-uebersetzen/englischer-zeugniscode.html'>Englischer Zeugniscode</a></div>");
  if (!document.getElementById("sn3")) document.write("<div id='sn3' onmouseover=\"clearTimeout(timer[3]);\" onmouseout=\"setSnTimer('3');\"><a href='/bewerbung-tipps/unterlagen.html'>Schriftliche Unterlagen</a><a href='/bewerbung-tipps/personalfragebogen.html'>Personalfragebogen</a><a href='/bewerbung-tipps/fehler-vermeiden.html'>Do's and Dont's</a><a href='/bewerbung-tipps/assessment-center.html'>Assessment Center</a></div>");
  if (!document.getElementById("sn4")) document.write("<div id='sn4' onmouseover=\"clearTimeout(timer[4]);\" onmouseout=\"setSnTimer('4');\"><a href='/bewerbungstraining/bewerbungstraining-in-hamburg.html'>Bewerbungstraining in Hamburg</a><a href='/bewerbungstraining/studienbewerbung-und-training.html'>Studienbewerbung und Training</a></div>");


addMouseHandlers(document.getElementById("tn1"), "1");
addMouseHandlers(document.getElementById("tn2"), "2");
addMouseHandlers(document.getElementById("tn3"), "3");
addMouseHandlers(document.getElementById("tn4"), "4");
addMouseHandlers(document.getElementById("tn5"), "5");
addMouseHandlers(document.getElementById("tn6"), "6");
addMouseHandlers(document.getElementById("tn7"), "7");

} 

function clearTimer(ID) {
  tim = timer[ID];
  if (tim) clearTimeout(tim);
}

function closeAllSn() {
  for (c =0; c < 8; c++) {
    closeSubMenu(c);
  }
}



function showSubMenu(mID) {
  sn = document.getElementById("sn" + mID);
  tn = document.getElementById("tn" + mID);
  if (tn && sn) {
    sn.style.visibility = "visible";
    sn.style.zIndex = "400";
	otop = tn.offsetTop;
	olft = tn.offsetLeft;
	opar = tn.offsetParent;
	while(opar) {
		otop += opar.offsetTop;
		olft += opar.offsetLeft;
		opar = opar.offsetParent;
	}
    sn.style.top = (otop +22) + "px";
    sn.style.left = olft + "px";
  }
}


function closeSubMenu(mID) {
  tn = document.getElementById("sn" + mID);
  if (tn) {
    tn.style.visibility = "hidden";
    tn.style.zIndex = "0";
  }
}

function addMouseHandlers(tn, ID) {
tn.setAttribute("onmouseover", "clearTimer('" + ID + "');closeAllSn();showSubMenu('" + ID + "');");
tn.setAttribute("onmouseout", "setSnTimer('" + ID + "');");
}

function setSnTimer(ID) {
  timer[ID] = setTimeout("closeSubMenu('" + ID + "');", 250);
}

/*
function appendSubMenuLink(trgt, txt, par, clName) {
  if (par) {
    lnk = document.createElement("a");
    lnk.href= trgt;
    if (clName) lnk.className = clName;
    lnk.appendChild(document.createTextNode(txt));
    par.appendChild(lnk);
  }
}
*/



function decryptCharcode(n,start,end,offset) {
	n = n + offset;
	if (offset > 0 && n > end)	{
		n = start + (n - end - 1);
	} else if (offset < 0 && n < start)	{
		n = end - (start - n - 1);
	}
	return String.fromCharCode(n);
}
  // decrypt string
function decryptString(enc,offset) {
	var dec = "";
	var len = enc.length;
	for(var i=0; i < len; i++)	{
		var n = enc.charCodeAt(i);
		if (n >= 0x2B && n <= 0x3A)	{
			dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :
		} else if (n >= 0x40 && n <= 0x5A)	{
			dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @
		} else if (n >= 0x61 && n <= 0x7A)	{
			dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z
		} else {
			dec += enc.charAt(i);
		}
	}
	return dec;
}
  // decrypt spam-protected emails
function linkTo_UnCryptMailto(s)	{
	location.href = decryptString(s,-1);
}
