/**
menu.js

Copyright (c) 2008 Florian Dietrich <dev@flodi.net>

This script provides support for a dynamic menu incl. popupmenu. 
Usefull for navigationmenus.
 
*/


/*
This class adds the functionality to the html menu. The menu
must consist of:
	1. div tag  (wrapping the menu)
	2. the menu as an unsorted list (ul, li)
	
Sample:
	<div id="yourmenuid">
		<ul>
			<li>Menuitem 1
				<ul>
					<li>Menuitem 1.1</li>
					<li>Menuitem 1.2</li>
				</ul>
			</li>
			<li>Menuitem 2
				<ul>
					<li>Menuitem 2.1</li>
					<li>Menuitem 2.2</li>
				</ul>
			</li>
		</ul>
	</div>
*/
function Navigation_Menu(divid) {
	
	//this.menudiv: Contains the menudiv dom element after initialization

	this._onmouseover = function (menu) {
		return (function () {
			if (this) {
				for (i=0; i<this.getElementsByTagName('ul').length;i++) {
					this.getElementsByTagName('ul')[i].style.display = "block";
				}
			}
		});		
	}
	
	this._onmouseout = function (menu) {
		return (function () {
			if (this) {
				for (i=0; i<this.getElementsByTagName('ul').length;i++) {
					this.getElementsByTagName('ul')[i].style.display = "none";
				}
			}
		});
	};
	
	this._initializeli = function (li) {
		li.onmouseover = this._onmouseover(this);
		li.onmouseout = this._onmouseout(this);
	};	
	
	this._initialize = function () {
		for (i=0; i<this.menudiv.getElementsByTagName('li').length; i++) {
			this._initializeli(this.menudiv.getElementsByTagName('li')[i]);
		}
	}; 	
		

	if (!divid) {
		throw "No divid found. Could not create menuobjekt";
		return false;
	}
	
	this.menudiv = document.getElementById(divid);
	
	if (!this.menudiv) {
		throw "Element " + divid + " not found!";
		return false;
	}
	
	this._initialize();
		
}

