function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(init);

function init() {
	setMenuItemHighlight();
	hideLanguageDropdown();
}

function setMenuItemHighlight() {
	var loc = location.href;
	if (document.getElementById) {
		var m_poker = "";
		var m_poker_deals = "";
		var m_poker_tips = "";
		var m_poker_links = "";
		var m_poker_forum = "";
		var m_casino = "";
		var m_casino_deals = "";
		var m_casino_links = "";
		var m_games = "";
		var m_games_deals = "";
		var m_games_links = "";
		var m_banking = "";
		m_poker = document.getElementById("poker");
		m_poker_deals = document.getElementById("poker_deals");
		m_poker_tips = document.getElementById("poker_tips");
		m_poker_links = document.getElementById("poker_links");
		m_poker_forum = document.getElementById("poker_forum");
		m_casino = document.getElementById("casino");
		m_casino_deals = document.getElementById("casino_deals");
		m_casino_links = document.getElementById("casino_links");
		m_games = document.getElementById("games");
		m_games_deals = document.getElementById("games_deals");
		m_games_links = document.getElementById("games_links");
		m_banking = document.getElementById("banking");
		if (0 < loc.indexOf("/poker-tips/")) {
			m_poker.className = "selected";
			m_poker_tips.className = "selected";
		} else if (0 < loc.indexOf("/poker-links/")) {
			m_poker.className = "selected";
			m_poker_links.className = "selected";
		} else if (0 < loc.indexOf("/poker-forum/")) {
			m_poker.className = "selected";
			m_poker_forum.className = "selected";
		} else if (0 < loc.indexOf("/online-casino/")) {
			m_casino.className = "selected";
			m_casino_deals.className = "selected";
		} else if (0 < loc.indexOf("/casino-links/")) {
			m_casino.className = "selected";
			m_casino_links.className = "selected";
		} else if (0 < loc.indexOf("/casino-games/")) {
			m_games.className = "selected";
			m_games_deals.className = "selected";
		} else if (0 < loc.indexOf("/games-links/")) {
			m_games.className = "selected";
			m_games_links.className = "selected";
		} else if (0 < loc.indexOf("/banking/")) {
			m_banking.className = "selected";
		} else {
			m_poker.className = "selected";
			m_poker_deals.className = "selected";
		}
	}
}

function hideLanguageDropdown() {
	if (document.getElementById("sub_1")) {
		var sb = document.getElementById("sub_1");
		sb.style.display = "none";
	}
}

// DropDownMenus
var dropDownStatus = 0;
function showDropDown(el) {
	var dropDownId;
	if(-1<el.id.indexOf("m_"))el.id = el.id.substring(2,el.id.length);
	if (0<el.id.indexOf("_")) {
	    dropDownId = el.id.substring(0,parseInt(el.id.indexOf("_")));
	} else {
	    dropDownId = el.id;
	}
	dropDownStatus = dropDownId;
	// show active dropDown
	if (document.getElementById("sub_" + dropDownId)) {
		var dropDown = document.getElementById("sub_" + dropDownId);
		
        //Kijk of het een hoofd of subitem is en bepaal juiste actie
		var arrElId;
		arrElId = el.id.split("_");
		if(2<arrElId.length) {
		    dropDown.style.display = "block";
		} else {
		    if (document.getElementById("sub_" + dropDownId).style.display != 'block') {
		        dropDown.style.display = "block";
		    }
		}
		
	}
	// hide all others
	var uls = document.getElementsByTagName("ul");
	for (var i=0; i<uls.length; i++) {
		//alert(uls[i].id + " = sub_" + dropDownId);
		if (-1<uls[i].id.indexOf("sub") && uls[i].id != "sub_" + dropDownId) {
			uls[i].style.display = "none";
			//hideBox(uls[i]);
		}
	}
}
function hideDropDown(el) {
	var dropDownId;
	if(-1<el.id.indexOf("m_"))el.id = el.id.substring(2,el.id.length);
	if (0<el.id.indexOf("_")) {
	    dropDownId = el.id.substring(0,parseInt(el.id.indexOf("_")));
	} else {
	    dropDownId = el.id;
	}
	dropDownStatus = 0;
	if (document.getElementById("sub_" + dropDownId)) {
		var dropDown = document.getElementById("sub_" + dropDownId);
		if (dropDownStatus == 0) {
			setTimeout(function() {
				if (dropDownStatus == 0) {
					setTimeout(function() { if (dropDownStatus == 0) dropDown.style.display = "none"; }, 350);
					//setTimeout(function() { if (dropDownStatus == 0) hideBox(dropDownId); }, 200);
				}
			}, 350);
		}
	}
}

