function HWClickShowHideMenu(id) {
	this.init = function() {
		if (!document.getElementById(this.id)) {
			alert("Element '"+this.id+"' does not exist in this document. HWClickShowHideMenu cannot be initialized");
			return;
		}
		this.hw_ns4 = (document.layers) ? true : false;
		this.hw_ie4 = (document.all) ? true : false;
		this.hw_ng5 = (document.getElementById) ? true : false;
		this.hw_opa = (navigator.userAgent.indexOf("Opera") >= 0);
		this.parse(document.getElementById(this.id).childNodes, "0");
		this.shrink(document.getElementById(this.id).childNodes);
		this.load();
		this.ignore_toggle = 0;
		if (window.attachEvent) {
			window.attachEvent("onunload", function(e) { self.save(); });
		} else if (window.addEventListener) {
			window.addEventListener("unload", function(e) { self.save(); }, false);
		}
	}

	this.parse = function(nodes, tag) {
		var last_li = tag;
		for (var i = 0; i < nodes.length; i++) {
			if (nodes[i].nodeType != 1) {
				continue;
			}
			if (nodes[i].nodeName) {
				if ("LI" == nodes[i].nodeName) {
					last_li = tag + '.' + i;
					nodes[i].id = last_li;
					eval('nodes[i].onclick = function() { self.toggle("'+last_li+'u"); }');
				}
				if ("SPAN" == nodes[i].nodeName) {
				}
				if ("A" == nodes[i].nodeName) {
				    /*nodes[i].id = last_li + 'a';*/
				}
				if ("UL" == nodes[i].nodeName) {
					nodes[i].id = last_li + 'u';
				}
			}
			if (nodes[i].childNodes) {
				this.parse(nodes[i].childNodes, nodes[i].id);
			}
		}
	}

	this.shrink = function(nodes) {
		for (var i = 0; i < nodes.length; i++) {
			if (nodes[i].nodeType != 1) {
				continue;
			}
			if (nodes[i].childNodes) {
				this.shrink(nodes[i].childNodes, nodes[i].id);
			}
			if (nodes[i].nodeName) {
				if ("UL" == nodes[i].nodeName) {
					if (nodes[i].id.length > 2) {
						this.hide(nodes[i].id);
					}
				}
			}
		}
	}
	this.toggleMenu = function() {
		var menu = document.getElementById("navbar");
		var page = document.getElementById("pagebar");
		var ppad = document.getElementById("pagepad");
		this.isvisible = !this.isvisible;

		if (this.isvisible) {
			if (menu != null) menu.className = "nav";
			if (ppad != null) ppad.className = "contentpad";
			if (page != null) page.className = "content";
		} else {
			if (menu != null) menu.className = "nonav";
			if (ppad != null) ppad.className = "nocontentpad";
			if (page != null) page.className = "nocontent";
		}
	}
	
	this.toggle = function(tag) {
		/*IE seems to fire events for each parent node too, so we
		 *calculate the number of events to expect and igore them
		 *...*/
		if (this.hw_ie4 && !this.hw_opa) {
			if (this.ignore_toggle > 0) {
				this.ignore_toggle--;
				return;
			}
			for (var n = 0; n < tag.length; n++) {
				if ('.' == tag.charAt(n))
					this.ignore_toggle++;
			}
			if (this.ignore_toggle > 0)
				this.ignore_toggle--;
		}
		/*IE hack ends here*/
		if (this.id_openbox
			  && this.id_openbox.length >= tag.length
			  && this.id_openbox.substr(0, tag.length) == tag) {
			var idx = tag.lastIndexOf('.');
			if (idx > 0) {
				var tmp = tag.substr(0, idx);
				tag = tmp;
			}
		}
		if (this.id_openbox) {
			this.hideTree(this.id_openbox);
			this.id_openbox = "";
		}
		this.showTree(tag);
		this.id_openbox = tag;
		return 0;
	}

	this.hideTree = function(tag) {
		var arr = new Array();
		arr = tag.split('.');
		var id = arr[0];
		for (var n = 0; n < arr.length; n++) {
			if (n > 0) {
				id = id + '.' + arr[n];
			}
			if (document.getElementById(id)) {
				this.hide(id);
			}
		}
	}
	
	this.hide = function(tag) {
		if (this.hw_ng5) {
			if (!document.getElementById(tag))
				return;
			document.getElementById(tag).style.display = "none";
		}
		else if (this.hw_ie4) {
			if (!document.all[tag])
				return;
			document.all[tag].style.display = "none";
		}
	}

	this.showTree = function(tag) {
		var arr = new Array();
		arr = tag.split('.');
		var id = arr[0];
		for (var n = 0; n < arr.length; n++) {
			if (n > 0) {
				id = id + '.' + arr[n];
			}
			if (document.getElementById(id)) {
				this.show(id);
			}
		}
	}
	
	this.show = function(tag) {
		if (this.hw_ng5) {
			if (!document.getElementById(tag))
				return 0;
			document.getElementById(tag).style.display = "block";
		}
		else if (this.hw_ie4) {
			if (!document.all[tag])
				return 0;
			document.all[tag].style.display = "block";
		}
		return 1;
	}

	this.save = function() {
		if (this.id_openbox) {
			this.cookie.set(this.id, this.id_openbox);
		} else {
			this.cookie.del(this.id);
		}
		if (!this.isvisible) {
			this.cookie.set(this.id + 'v', '1');
		} else {
			this.cookie.del(this.id + 'v');
		}
	}

	this.load = function() {
		var id = this.cookie.get(this.id);
		if (id) {
			this.toggle(id);
		}
		if (this.cookie.get(this.id + 'v'))
			this.toggleMenu();
	}

	function Cookie() {
		this.get = function(name) {
			var cookies = document.cookie.split(";");
			for (var i = 0; i < cookies.length; i++) {
				var a = cookies[i].split("=");
				if (a.length == 2) {
					a[0] = a[0].trim();
					a[1] = a[1].trim();
					if (a[0] == name) {
						return unescape(a[1]);
					}
				}
			}
			return "";
		}
		this.set = function(name, value) {
			document.cookie = name + "=" + escape(value) + "; path=/;";
		}
		this.del = function(name) {
			document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;";
		}
	}

	var self = this;
	this.id = id;
	this.cookie = new Cookie();
	this.id_openbox = "";
	this.ignore_toggle = 0;
	this.hw_ns4 = false;
	this.hw_ie4 = false;
	this.hw_ng5 = false;
	this.hw_opa = false;
	this.isvisible = true;
}

if (typeof String.prototype.trim == "undefined") {
	String.prototype.trim = function() {
		var s = this.replace(/^\s*/, "");
		return s.replace(/\s*$/, "");
	}
}
