var actmenu = { // Namespace
	archive : [],
	init : function(id) {
		var menu, i, key;
		if (menu = document.getElementById(id)) {
			var lis = menu.getElementsByTagName('li');
			for (i = 0; i < lis.length; i++) {
				if (lis[i].getElementsByTagName('div').length) {
					key = this.archive.length;
					lis[i].lid = key;
					this.archive[key] = new this.create(key, lis[i], this.moveStep, id);
					if (lis[i].id && lis[i].id == 'openMe') {
						//this.archive[key].click(key); - animation opened
						var div = lis[i].getElementsByTagName('div')[0];
						var indiv = div.getElementsByTagName('ul')[0];
						this.archive[key].curHeight = indiv.offsetHeight;
						div.style.height = this.archive[key].curHeight + 'px';
						this.archive[key].opened = true;
					}
				}
				if (lis[i].parentNode.id && lis[i].parentNode.id == id) {
					lis[i].onmouseover = function() {
						this.className = 'hover';
					}
					/*lis[i].onmousemove = function() {
						this.className = 'hover';
					}*/
					lis[i].onmouseout = function() {
						this.className = '';
					}
				} else {
					lis[i].onclick = function(evt) {
						evt = evt || window.event;
						evt.cancelBubble = true;
					}
				}
			}
		}
	},
	create : function(id, li, step, parentId) {
		this.interval = 10; // ms
		this.id = id;
		this.parent = document.getElementById(parentId);
		this.li = li;
		this.step = step;
		this.div = this.li.getElementsByTagName('div')[0];
		this.indiv = this.div.getElementsByTagName('ul')[0];
		this.allHeight = this.indiv.offsetHeight;
		this.curHeight = 0;
		this.li.onclick = this.click;
		this.opened = false;
		this.inCloseProcess = false;
		this.timer = null;
	}
}
actmenu.create.prototype = {
	click : function(lid) {
		lid = typeof lid == "number" ? lid : this.lid;
		var o = actmenu.archive[lid];
		clearTimeout(o.timer);
		if (!o.opened) {
			for (var i = 0; i < actmenu.archive.length; i++) {
				if (i == this.lid) continue;
				if (actmenu.archive[i].opened && !actmenu.archive[i].inCloseProcess) 
					actmenu.archive[i].grow();
			}
		}
		actmenu.archive[lid].grow();
	},
	grow : function() {
		clearTimeout(this.timer);
		this.lock();
		if (!this.opened) {
			this.curHeight += 5;
			if (this.curHeight > this.allHeight) {
				this.curHeight = this.allHeight;
				this.div.style.height = this.curHeight + 'px';
				this.opened = true;
				this.lock(1);
			} else {
				this.timer = setTimeout("actmenu.archive["+this.id+"].grow()", this.interval);
				this.div.style.height = this.curHeight + 'px';
			}
		} else {
			this.inCloseProcess = true;
			this.curHeight -= 5;
			if (this.curHeight < 0) {
				this.curHeight = 0;
				this.div.style.height = '0px';
				this.opened = false;
				this.inCloseProcess = false;
				this.lock(1);
			} else {
				this.timer = setTimeout("actmenu.archive["+this.id+"].grow()", this.interval);
				this.div.style.height = this.curHeight + 'px';
			}
		}
	},
	absPosition : function(obj) { 
		var x = y = 0;
		while(obj) {
			x += obj.offsetLeft;
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		return {x:x, y:y};
	},
	lock : function(hide) {
		this.parent.className = hide ? '' : 'non-hovered';
		/*var div;
		if (hide) {
			document.getElementById('lockId').style.display = 'none';
			return;
		}
		if (!(div = document.getElementById('lockId'))) {
			div = document.createElement('div');
			div.id = 'lockId';
			div.style.position = 'absolute';
			div.style.background = 'url(\'/fileadmin/images/ru/0.gif\')';
			div.style.zIndex = 1000;
			document.body.appendChild(div);
		}
		div = document.getElementById('lockId');
		div.style.display = '';
		div.style.top = this.absPosition(this.parent).y + 'px';
		div.style.left = this.absPosition(this.parent).x + 'px';
		div.style.height = this.parent.offsetHeight + 'px';
		div.style.width = this.parent.offsetWidth + 'px';*/
	}
}
