// 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("menu")) return false;
  	var menu = document.getElementById("menu");
  	
  	// 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;
}

addLoadEvent(prepareMenu);


$('document').ready(function(){
	var menuStr = '<div class="wrapper" style="border-left:1px #BBB solid; height:39px;"><ul id="menu">';
	menuStr += '<li id="menuItem_3" class="menuItem"><a href="smartplan.html" title="DG Smart Plan" id="menuArrow_3" class="menuArrow2">DG Smart Plan&trade;</a></li>';
	
	menuStr += '<li id="menuItem_1" class="menuItem"><a href="#" title="BlackBerry" id="menuArrow_1" class="menuArrow2">BlackBerry</a><ul style="width:170px"><li><a href="#" title="Devices">Devices&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:200px"><li><a href="blackberry_bold9900.html" title="BlackBerry Bold 9900">BlackBerry Bold 9900</a></li><li><a href="blackberry_bold9780.html" title="BlackBerry Bold 9780">BlackBerry Bold 9780</a></li><li><a href="blackberry_torch9810.html" title="BlackBerry Torch 9810">BlackBerry Torch 9810</a></li><li><a href="blackberry_torch9800.html" title="BlackBerry Torch 9800">BlackBerry Torch 9800</a></li><li><a href="blackberry_curve9360.html" title="BlackBerry Curve 9360">BlackBerry Curve 9360</a></li><li><a href="blackberry_curve9300.html" title="BlackBerry Curve 9300">BlackBerry Curve 9300</a></li></ul></li><li><a href="blackberry.html" title="BlackBerry App World">BlackBerry App World</a></li></ul></li>';
	
	menuStr += '<li id="menuItem_2" class="menuItem"><a href="#" title="Android" id="menuArrow_2" class="menuArrow2">Android</a><ul style="width:170px"><li><a href="#" title="HTC">HTC&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="htc_chacha.html" title="HTC ChaCha">HTC ChaCha</a></li><li><a href="htc_desire_hd.html" title="HTC Desire HD">HTC Desire HD</a></li><li><a href="htc_evo3d.html" title="HTC EVO 3D">HTC EVO 3D</a></li><li><a href="htc_sensation.html" title="HTC Sensation ">HTC Sensation </a></li></ul></li><li><a href="#" title="LG">LG&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="lg_optimusone.html" title="LG Optimus">LG Optimus One</a></li><li><a href="lg_optimus_black.html" title="LG Optimus Black">LG Optimus Black</a></li></ul></li><li><a href="#" title="Samsung">Samsung&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="samsung_galaxys2.html" title="Samsung GALAXY S II">Samsung GALAXY S II</a></li><li><a href="samsung_galaxygio.html" title="Samsung GALAXY Gio">Samsung GALAXY Gio</a></li></ul></li><li><a href="#" title="Sony Ericsson">Sony Ericsson&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="sony_w8.html" title="Sony Ericsson W8">Sony Ericsson W8</a></li></ul></li><li><a href="htc_android.html" title="Android Market">Android Market</a></li><li><a href="android_apps_review.html" title="Android Apps Review">Android Apps Review</a></li></ul></li>';
	
	
	menuStr += '<li id="menuItem_4" class="menuItem"><a href="#" title="Nokia" id="menuArrow_4" class="menuArrow2">Nokia</a><ul style="width:170px"><li><a href="nokia_n9.html" title="Nokia N9">Nokia N9&nbsp;&nbsp;</a></li><li><a href="nokia_x7.html" title="Nokia X7">Nokia X7&nbsp;&nbsp;</a></li></ul></li>';
	
	menuStr += '<li id="menuItem_5" class="menuItem"><a href="#" title="BlackBerry" id="menuArrow_5" class="menuArrow2">Compare Us</a><ul style="width:170px"><li><a href="#" title="BlackBerry">BlackBerry&nbsp;&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="compare_device.html" title="Device Bundles">Device Bundles</a></li><li><a href="compare_bb_data.html" title="Data Plans">Data Plans</a></li></ul></li><li><a href="#" title="Non-BlackBerry">Non-BlackBerry&nbsp;&nbsp;<img src="images/header/img_menu_arrowRight_black.png" align="texttop" border="0" /></a><ul style="width:170px"><li><a href="compare_non_bb_data.html" title="Device Bundles">Data Plans</a></li></ul></li></ul></li>';
	
	menuStr += '<li id="menuItem_6" class="menuItem"><a href="buy.html" title="Store Locator" id="menuArrow_6" class="menuArrow2">Store Locator&nbsp;</a></li>';
	
	menuStr += '<li id="menuItem_7" class="menuItem"><a href="support.html" title="Contact Us" id="menuArrow_7" class="menuArrow2">Contact Us&nbsp;</a></li>';
	
	menuStr += '</ul></div>';
	

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