﻿function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function prepDropDowns () {
	var mainLis = Array("whym","abou","spor","plan","stay","maps","pres","cont");
	var len = mainLis.length;
	for (i=0; i<mainLis.length; i++) {
		var l;
		if (l = document.getElementById(mainLis[i])) {
			l.style.zIndex = 20-i;
		}
	}
	var mm;
	if (mm = document.getElementById("mainMenu")) {
		var lis;
		if (lis = mm.getElementsByTagName("li")) {
			for (i=0; i<lis.length; i++) {
				lis[i].onmouseover = function () {
					drop(this);
				}
				lis[i].onmouseout = function () {
					hide(this);
				}
			}
		}
	}
}
function drop(targ) {
	var uls;
	if (uls = targ.getElementsByTagName("ul")) {
		if (uls.length > 0) {
			uls[0].style.display = "block";
			checkY(uls[0]);
		}
	}
}
function hide(targ) {
	var uls;
	if (uls = targ.getElementsByTagName("ul")) {
		for (i=0; i<uls.length; i++) {
			resetY(uls[i]);
			uls[i].style.display = "none";
			
		}
	}
}
function resetY (targ) {
	if (targ.style.marginLeft) targ.style.marginLeft = 0;
	if (parseInt(targ.style.top) < 0) {
		targ.style.top = "22px";
	}
}
function checkY(targ) {
	var h = targ.scrollHeight;
	if (navigator.userAgent.indexOf("MSIE") != -1) {	
		var t = targ.offsetParent.offsetTop;
		
		var s = document.documentElement.clientHeight||document.body.clientHeight;

	} else {
		try {
		var t = targ.offsetParent.offsetTop;
		} catch (e) {
			// waa, waa, waa, bad js!!
		}
		var s = window.innerHeight;
		
	}
	if (s < h) {
		targ.style.top = -t+"px";
		targ.style.marginLeft = "70px";
	} else if (s < t+h) {
		targ.style.top = (s-h-t)+"px";
		targ.style.marginLeft = "70px";
	}
}

addLoadEvent(prepDropDowns);