function preview(prev_path) {
	window.open("/preview.php?prev_path=" + prev_path, "prev_wnd", "toolbar=0,statusbar=0,menubar=0,resizable=1,scrollbars=0,width=800,height=600");
}

function hover_element(ref) {
	this.element_ref = ref;
	this.opacity = 0;
	this.flag = 1;
	this.child = true;
	
	this.speed_in = 15;
	this.speed_out = 6;
	
	this.update = function() {
		var chRef = this.child ? this.element_ref.childNodes[0] : this.element_ref;
	
		if (chRef.style.opacity != null) chRef.style.opacity = this.opacity / 100;
		if (chRef.style.filter != null) chRef.style.filter = "alpha(opacity=" + this.opacity + ")";
	}
	
	this.process = function() {
		switch (this.flag) {
			case 0 :
				if (this.opacity > 0) {
					this.opacity += - this.speed_out;
					if (this.opacity < 0) this.opacity = 0;
					this.update();
				}
				break;
				
			case 1 :
				if (this.opacity < 100) {
					this.opacity += this.speed_in;
					if (this.opacity > 100) this.opacity = 100;
					this.update();
				}
				break;
		}
	}
}

function hover_handler() {
	this.stack = new Array();
	
	this.find = function(ref) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.stack.length) {
			if (this.stack[pos].element_ref == ref) founded = true;
			else pos++;
		}
		
		return founded ? this.stack[pos] : null;
	}
	
	this.add = function(ref, opacity, flag, child) {
		var el = this.find(ref);
		if (el == null) {
			el = new hover_element(ref);
			el.opacity = opacity;
			el.flag = flag;			
			el.child = child;
			el.speed_in = 5;
			this.stack[this.stack.length] = el;
		}
	}
	
	this.over = function(ref) {
		var el = this.find(ref);
		if (el == null) {
			el = new hover_element(ref);
			this.stack[this.stack.length] = el;
		}
		el.flag = 1;
	}
	
	this.over_href = function(ref, ident) {
		this.over(document.getElementById("menu" + ident + "no"));
	}
		
	this.out = function(ref, trgEvent) {
		var el = this.find(ref);
		
		if (el != null) {
			var target = (trgEvent.toElement == null) ? trgEvent.relatedTarget : trgEvent.toElement;
			
			if (target.parentNode.className == "menu_sub" && target.tagName.toLowerCase() == "a") {
				var childA = -1;
				var childB = -1;
				
				var pA = target.parentNode.parentNode;
				var pB = el.element_ref.parentNode;
				
				var pos = 0;
				while (childA == -1 && pos < pA.childNodes.length) {
					if (pA.childNodes[pos] == target.parentNode) childA = pos;
					else pos++;
				}
				
				pos = 0;
				while (childB == -1 && pos < pB.childNodes.length) {
					if (pB.childNodes[pos] == el.element_ref) childB = pos;
					else pos++;
				}
				
				if (childA != childB) {
					el.flag = 0;
				}
			} else if (target != el.element_ref && target != el.element_ref.childNodes[0]) {
				el.flag = 0;
			}
		}
	}
	
	this.out_href = function(ref, ident, trgEvent) {
		var el = this.find(document.getElementById("menu" + ident + "no"));
		
		if (el != null) {
			var target = (trgEvent.toElement == null) ? trgEvent.relatedTarget : trgEvent.toElement;
			
			if (target != el.element_ref && target != el.element_ref.childNodes[0]) {
				el.flag = 0;
			}
		}
	}
	
	this.loop = function() {
		var pos = 0;
		for (pos = 0; pos < this.stack.length; pos++) {
			this.stack[pos].process();
		}
	}
}

var h_handle;
h_handle = new hover_handler();

function handle_loop() {
	h_handle.loop();
	setTimeout("handle_loop()", 60);
}

handle_loop();
