function HorizontalMenu(id,activeClass,unactiveClass)
{
	this.root = document.getElementById(id);
	this.unactiveClass = unactiveClass;
	this.activeClass = activeClass;
	this.active = null;
	this.hidder = null; 

	var pointer = this;
	
	/* Zwraca elementy podrzedne */
	this.childrens = function(el)
	{
		var result = [];

		for (var i=0;i < el.childNodes.length;i++) {
			result.push(el.childNodes[i]);
			result = result.concat(pointer.childrens(el.childNodes[i]));
		}
		return result;
	}
	/* Sprawdza czy dany element jes podrzedny */
	this.child = function(el,parent)
	{
		var tmp = el.parentNode;
		
		while (tmp) {
			if (tmp == parent) {
				return true;
			}
			tmp = tmp.parentNode;
		}
		return false;
	}
	/* Wyswietlenie menu */
	this.showSubmenu = function()
	{
		var tag = '';
		
		pointer.clearInterval();
		pointer.hideSubmenu(this);
		
		this.className = pointer.activeClass;
		
		for (var i = 0;i < this.childNodes.length;i++) {
			
			if (this.childNodes[i].tagName) {
				
				tag = this.childNodes[i].tagName.toString();
				
				if (tag.toLowerCase() == 'ul') {
					
					this.childNodes[i].style.display = 'block';
					pointer.active = this.parentNode;
					
					break;
				}
			}	
		
		}
	}
	/* Chowanie podrzednego menu */
	this.hideSubmenu = function(el)
	{	
		if (pointer.active && pointer.child(el,pointer.active)) {
			
			var childrens = pointer.childrens(pointer.active);
			
			for (var i = 0;i<childrens.length;i++) {
				pointer.hideUlElement(childrens[i]);
			}
		}
		
	}
	/* Chowa pojedynczy element */
	this.hideUlElement = function(el)
	{
		if (el.tagName) {
					
			var tag = el.tagName.toString();
					
			if (tag.toLowerCase() == 'ul') {
				el.style.display = 'none';
			}
		}
	}
	/* Chowanie calego menu */
	this.hideAll = function()
	{
		var submenus = pointer.childrens(pointer.root);
		
		for (var i = 0;i < submenus.length;i++) {
			pointer.hideUlElement(submenus[i]);
		}
	}
	
	this.clearInterval = function()
	{
		if (pointer.hidder != null) {
			window.clearTimeout(pointer.hidder);
		}
	}
	
	this.startInterval = function()
	{
		this.className = pointer.unactiveClass;
		pointer.clearInterval();
		pointer.hidder = window.setTimeout(function() {pointer.hideAll()},1000);
	}
	
	/* Konstruktor :) */
	
	var tag = '';
	var submenus = this.childrens(pointer.root);//this.root.descendants();
	
	for (var i = 0;i < submenus.length;i++) {
		
		if (submenus[i].tagName) {
			
			tag = submenus[i].tagName.toString();
			
			if (tag.toLowerCase() == 'li') {
				submenus[i].onmouseover = this.showSubmenu;
				submenus[i].onmouseout = this.startInterval;
			}
		}
	}
}
