/*########################################################################
#                                                                        #
#                            ContEd                                      #
#                                                                        #
#               Autor: Matthias Will, Aviconet GmbH                      #
#                  Bahnstraße 8, 65205 Wiesbaden                         #
#                 0611 / 135890-0, www.aviconet.de                       #
#                                                                        #
#                           (c) 2009                                     #
#                                                                        #
#                     Alle Rechte vorbehalten.                           #
#                                                                        #
########################################################################*/

function SitemapMenu(delay, factor){
	this.name = 'sitemapmenu';
	this.delay = delay * 1000;
	this.factor = factor;
	this.timeout = false;
	this.submenu = new Array();

	this.initHeights = function(){
		menuentries = document.getElementById(this.name).childNodes;
		for(var i = 0; i < menuentries.length; i += 1){
			if(menuentries[i].className == "sm_main_sub"){
				this.submenu[menuentries[i].id] = menuentries[i].offsetHeight;
			}
		}
	}

	this.initSubMenus = function(){
		menuentries = document.getElementById(this.name).childNodes;
		for(var i = 0; i < menuentries.length; i += 1){
			if(menuentries[i].className == "sm_main_sub"){
				menuentries[i].style.height = "0px";
				menuentries[i].style.display = "none";
			}
		}
	}

	this.showSub = function(id){
		id = "sitemap_" + id;
		if(!this.isVisible(id)){
			this.timeout = window.setTimeout("mysitemap.displaySub('" + id + "', 1)", this.delay);
		}
	}
	
	this.hideOtherSubs = function(id){
		for(var el in this.submenu){
			if(el != id && this.isVisible(el)){
				document.getElementById(el).style.height = "0px";
				document.getElementById(el).style.display = "none";
				
			}
		}
	}

	this.displaySub = function(id, x){
		submenuentry = document.getElementById(id);
		if(x == 1){
			this.hideOtherSubs(id);
			submenuentry.style.display = "block";
		}

		height = x * x * this.factor;
		submenuentry.style.height = height + "px";
		
		if(this.submenu[id] > height){
			x += 1;
			window.setTimeout("mysitemap.displaySub('" + id + "', " + x + ")", 25);
		}else{
			submenuentry.style.height = null;
		}
	}

	this.clearSub = function(){
		window.clearTimeout(this.timeout);
	}
	
	this.isVisible = function(id){
		return document.getElementById(id).style.display == "block";
	}

	this.initHeights();
	this.initSubMenus();
}
