// JavaScript Document

// DropDownMenu by Miha Hribar
// http://hribar.info

/////////////////////////////////////////////////////////////////////////////////////////
/// Add ons by s.klimis
/// open/close drop down menu to allow use of underlying links in main page

///////
//call this to change the position of the drop down dynamically
///////
resize(3)
function drd(action) {
//action: 1 open, 0 close iframe
//this must be included in parent window, i.e. index.html
	  	if (!document.getElementById) return false;
	  	var drdown = document.getElementById("drdown");
		if (drdown == null) return false;
/////
//change the drop down width dynamically		
////
	   drdown.style.width = "850px";
//////////////////////////////////////////////////////////////////////////////////////////////
///////READJUST DROP DOWN POSITION (LEFT-TOP)   ///
/////////////////////////////////////////////////////////////////////////////////////////////
		if (action==3) {
		drdownname=drdown.name
		if (drdownname=="drdownshort") {drdown.style.left="270px"; drdown.style.top="74px";}
		else {drdown.style.left="270px"; drdown.style.top="178px";}
		return;
		}
///////////////////////////////////////////////////////////////////////////////////////////////        

if (action==1) {
		   drdown.style.height="240px";
		}
		else {
				   drdown.style.height="20px";
		}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// all below must be included in drop down iframe (where the actual drop down is), i.e drdown.asp or drdowngr.asp	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function resize(action) {
//this must be included in drop down iframe (where the actual drop down is), i.e drdown.asp or drdowngr.asp	
//action: 1 open, 0 close iframe
	if (parent.drd){
        parent.drd(action);
        }
}

//////////////////////////////////////////////////////////////////////////////////////////

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");
	
	/////////////////////////////////////////////////////////////////////////////
	///USE THIS CALL TO READJUST THE DROP DOWN POSITION(LEFT-TOP) IF REQUIRED ///
	///INACTIVE FOR THE TIME BEING    s.klimis add on              
    ///resize(3); 
	/////////////////////////////////////////////////////////////////////////////
	
  	// 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 () {
				//alert.(li.id);
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "block";
				resize(1);  // open drop down s.klimis
  	            return true;
  	        }
  	        li.onmouseout = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "none";
				resize(0);  // close drop down s.klimis
  	            return true;
  	        }
			li.onmouseup = function () {
  	            if (!this.getElementsByTagName("ul")) return false;
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "none";
				resize(0);  // close drop down s.klimis
  	            return true;
			}
			
  	    }
  	}
  	
  	return true;
}

addLoadEvent(prepareMenu);
