var isMenuOpen = 0;

function doInit () {
	if (window.innerHeight) {
		//cross("outer").style.height = window.innerHeight + -10 + "px";
		//cross("top").style.width = "860px";
	}
	 
	if (document.all) var a= document.all.tags("a");
	else if (document.getElementById) var a= document.getElementsByTagName("a");
	else return;

	for (i=0; i<a.length; i++) {
	    a[i].onfocus = function() { if (this.blur) this.blur(); }
	    
	    if (a[i].name != "") doMail(a[i], a[i].name);
	    if (a[i].id == "office_email") doMail(a[i], "6F666669636540737366702D6C61772E6174");
    }
}

function doMail(obj, strg) {
    var strg = decodeEmail(strg);

    obj.innerHTML = strg;
    
    strg = "mailto:" + strg;
    
    obj.href = strg;
    obj.onmouseover = function () { window.status = strg; }
    obj.onmouseout = function () { window.status = ""; }
}

function openMenu(that, tabid) {
	if (isMenuOpen != tabid) {
		if (isMenuOpen != 0) closeMenu();

		moveMenu(that, tabid);

		//cross("menu_" + tabid).style.display = "";
		FadeIn(0, tabid);

		t = setTimeout("menuHelper(" + tabid + ")", 250);
	}
}

function menuHelper(tabid) {
	isMenuOpen = tabid;
	
	document.onclick = function() { closeMenu() }

	cross("menu_" + tabid).onmouseout = function() { c = setTimeout("closeMenu()", 250); }
	cross("menu_" + tabid).onmouseover = function() { if (window.c) clearTimeout(c) }
}

function closeMenu() {
	document.onclick = "";
	
	cross("menu_" + isMenuOpen ).onmouseover = "";
	cross("menu_" + isMenuOpen ).onmouseout = "";
	//cross("menu_" + isMenuOpen ).style.display = "none";
	FadeOut(100, isMenuOpen);

	isMenuOpen = 0;
}

function moveMenu(that, tabid) {
	var offset = 0;
	if (!document.all) offset = -4;

	cross("menu_" + tabid).style.left = getRealLeft(that) - 18;
	cross("menu_" + tabid).style.top = getRealTop(that) - 18 + offset;
}

function FadeIn(opac, tabid) {
	var newOpac = opac + 15;

	if (newOpac < 100) {
		cross("menu_" + tabid).style.opacity = "." + newOpac;
		cross("menu_" + tabid).style.filter = "alpha(opacity:" + newOpac + ")";

		if (newOpac == 15) cross("menu_" + tabid).style.display = "";

		o = window.setTimeout("FadeIn(" + newOpac + ", " + tabid + ")", 15);
	}
	else {
		cross("menu_" + tabid).style.opacity = "";
		cross("menu_" + tabid).style.filter = "";

		if (window.o) clearTimeout(o);
	}
}

function FadeOut(opac, tabid) {
	var newOpac = opac - 20;

	if (newOpac > 0) {
		cross("menu_" + tabid).style.opacity = "." + newOpac;
		cross("menu_" + tabid).style.filter = "alpha(opacity:" + newOpac + ")";

		o = window.setTimeout("FadeOut(" + newOpac + ", "+ tabid + ")", 15);
	}
	else {
		cross("menu_" + tabid).style.display = "none";
		cross("menu_" + tabid).style.opacity = "";
		cross("menu_" + tabid).style.filter = "";

		if (window.o) clearTimeout(o);
	}
}

function cross(objectID) { return document.getElementById ? document.getElementById(objectID) : document.all[objectID]; }
function getRealLeft(element) { xPos = element.offsetLeft; tempElement = element.offsetParent; while (tempElement != null) { xPos += tempElement.offsetLeft; tempElement = tempElement.offsetParent; } return xPos; }
function getRealTop(element) { yPos = element.offsetTop; tempElement = element.offsetParent; while (tempElement != null) { yPos += tempElement.offsetTop; tempElement = tempElement.offsetParent; } return yPos; } 

// return the decoded email address

function decodeEmail(encodedEmail) {
  var mailStrg = "";

  for (j=0; j<encodedEmail.length; j+=2) {
    var l = encodedEmail.charAt(j) + encodedEmail.charAt(j + 1);
    mailStrg += String.fromCharCode(parseInt(l, 16));
  }

  return mailStrg;
}
