// JavaScript Document

function Stack() {
	this.stack = new Array();	
	this.currentRelation = null;
}

Stack.prototype.addRelation = function(rel) {
	this.stack.push(rel);
	if (rel.parent != null) {
		if (rel.parent.className != "menuSelected") {
			rel.parent.childNodes[0].src = "images/menu/"+rel.parentValue+"_over.gif";
		}
	}
	if (rel.child != null) {
		rel.child.style.display="block";
	}	
	
	this.currentRelation = rel;
}


Stack.prototype.removeRelation = function(index) {
	var rel = this.stack[index];
	if (rel.parent != null) {
		if (rel.parent.className != "menuSelected") {
			rel.parent.childNodes[0].src = "images/menu/"+rel.parentValue+"_out.gif";
		}
	}
	if (rel.child != null) {
		rel.child.style.display="none";
	}
	this.stack.splice(index, 1);
}

Stack.prototype.getRelationByValue = function(val) {
	var rel;
	for (var i=0; i < this.stack.length; i++) {
		if (this.stack[i].parentValue == val) {
			rel = this.stack[i];
		}
	}
	
	return rel;
}

Stack.prototype.getIndexByValue = function(val) {
	var index;
	for (var i=0; i < this.stack.length; i++) {
		if (this.stack[i].parentValue == val) {
			index = i;
		}
	}
	
	return index;
}

Stack.prototype.timeOut = function(parentVal) {
	var index = this.getIndexByValue(parentVal);
	if (index != null) {
		this.removeRelation(index);
	}
	
}

Stack.prototype.startTimeout = function(parentValue) {
	var rel = this.getRelationByValue(parentValue);
	if (rel != undefined) {
		rel.timerID = setTimeout("menuStack.timeOut('"+parentValue+"')", 5);
	}
}

Stack.prototype.stopTimeout = function(parentValue) {
	
	var rel = this.getRelationByValue(parentValue);
	if (rel != undefined) {
		clearTimeout(rel.timerID);
	}
}




function Relation() {
	this.child = null;
	this.parent = null;
	this.childValue = "";
	this.parentValue = "";
	this.remove = false;
	this.timerID = 0;
	
}



var menuStack = new Stack();
var timerID = 0;
var timming = false;
var childOver;



function mouseOver(ref, childRef, val) {
	menuStack.stopTimeout(val);
	var rel = new Relation();
	rel.parent = ref;
	rel.parentValue = val;
	rel.child = document.getElementById(childRef)
	menuStack.addRelation(rel);
	
	
}


function mouseOut(ref, childRef, val) {
	menuStack.startTimeout(val);
	
}


function subMouseOver(ref, childVal, parentVal) {
	var rel = menuStack.getRelationByValue(parentVal);
	menuStack.stopTimeout(parentVal);
	
	if (ref.className != "subMenuOver") {
		ref.childNodes[0].src = "images/menu/"+childVal+"_over.png";
	}
	
}

function subMouseOut(ref, childVal, parentVal) {
	menuStack.startTimeout(parentVal);
	if (ref.className != "subMenuOver") {
		ref.childNodes[0].src = "images/menu/"+childVal+"_out.png";
	}
}


