// JavaScript Document

// DropDownMenu by Miha Hribar
// http://hribar.info

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

function prepareMenu() {
    // first lets make sure the browser understands the DOM methods we will be using
  	if (!document.getElementsByTagName) return false;
  	if (!document.getElementById) return false;
  	
  	// lets make sure the element exists
  	if (!document.getElementById("jsddm")) return false;
  	var menu = document.getElementById("jsddm");
	
  	// for each of the li on the root level check if the element has any children
  	// if so append a function that makes the element appear when hovered over
  	var root_li = menu.getElementsByTagName("li");
  	for (var i = 0; i < root_li.length; i++) {
  	    var li = root_li[i];
  	    // search for children
  	    var child_ul = li.getElementsByTagName("ul");
  	    if (child_ul.length >= 1) {
  	        // we have children - append hover function to the parent
  	        li.onmouseover = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "block";
  	            return true;
  	        }
  	        li.onmouseout = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "none";
  	            return true;
  	        }
  	    }
  	}
  	
  	return true;
}

function setNaviMenu(){
	
	$('#menuArrow_'+currentPage).addClass('selected');
};


$(document).ready(function(){
	var menuStr = '<ul id="jsddm" style="display:block">';
	
	menuStr += '<li id="menuItem_2" class="menuItem2" style="width:89px; background: url(images/nav_menu/bb_home.gif) 50% 50% no-repeat"><a href="index.html" title="Home" id="menuArrow_2" class="menuArrow2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>';
	
	menuStr += '<li style="height:33px; width:5px;"></li>';
		
	menuStr += '<li id="menuItem_3" class="menuItem3" style="background:url(images/nav_menu/bb_packages.gif) 50% 50% no-repeat; width:124px"><a href="#" title="Packages" id="menuArrow_3" class="menuArrow3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a><ul style="width:124px;display:none;margin-top:-10px"><li><a href="packages_promo.html" title="Promos">Promos</a></li><li><a href="broadband_summary.html" title="Broadband Packages">Broadband Packages</a></li><li style="border:#000"><a href="broadband_summary_prepaid_internet.html" title="Prepaid Internet">Prepaid Internet</a></li><li class="no_divider"><div class="btm_rounded"><img src="images/nav_menu/corner_left.gif" width="12" height="12" style="vertical-align:text-top"></div><div class="btm_footer" style="width:100px; height:12px; font-size:0px; line-height:0px"></div><div class="btm_rounded"><img src="images/nav_menu/corner_right.gif" width="12" height="12" style="vertical-align:text-top"></div></li></ul></li>';
	
	menuStr += '<li style="height:33px; width:5px;"></li>';
	
	menuStr += '<li id="menuItem_4" class="menuItem4" style="background:url(images/nav_menu/bb_coverage.gif) 50% 50% no-repeat; width:124px"><a href="coverage.html" title="Coverage" id="menuArrow_4" class="menuArrow4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>';
	
	menuStr += '<li style="height:33px; width:5px;"></li>';
	
	menuStr += '<li id="menuItem_5" class="menuItem5" style="background:url(images/nav_menu/bb_planrec.gif) 50% 50% no-repeat; width:206px"><a href="recommend_v2.html" title="Plan Recommender" id="menuArrow_5" class="menuArrow5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>';
	
	menuStr += '<li style="height:33px; width:5px;"></li>';
	
	menuStr += '<li id="menuItem_6" class="menuItem6" style="background:url(images/nav_menu/bb_on9promo.gif) 50% 50% no-repeat; width:194px"><a href="online_promotion.html" title="Online Promotions" id="menuArrow_6" class="menuArrow6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>';
	
	menuStr += '<li style="height:33px; width:5px;"></li>';
	
	menuStr += '<li id="menuItem_7" class="menuItem7" style="background:url(images/nav_menu/bb_support.gif) 50% 50% no-repeat; width:124px"><a href="#" title="Support" id="menuArrow_7" class="menuArrow7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a><ul style="width:124px;display:none; margin-top:-10px"><li><a href="tnc.html" title="Terms &amp; Conditions">Terms &amp; Conditions</a></li><li><a href="userguide.html" title="Downloads">Downloads</a></li><li style="border:#000"><a href="contactus.html" title="Contact Us">Contact Us</a></li><li class="no_divider"><div class="btm_rounded"><img src="images/nav_menu/corner_left.gif" width="12" height="12" style="vertical-align:text-top"></div><div class="btm_footer" style="width:100px; height:12px; font-size:0px; line-height:0px"></div><div class="btm_rounded"><img src="images/nav_menu/corner_right.gif" width="12" height="12" style="vertical-align:text-top"></div></li></ul></li>';
	
	menuStr += '</ul>';

	$('#menuContainer').html(menuStr);
	
	prepareMenu();
	
	setNaviMenu();
});
