var tk_castellini_dynamicMenu__openDuration = 0.2;
var tk_castellini_dynamicMenu__closeDuration = 0.5;

function tk_castellini_dynamicMenu(action) {
	this.elements = Array();
	this.buttons = Array();
	this.action = action;
	this.addElement = function(referID,buttonReferIdD,isOpen) {
		var auxElement = new tk_castellini_dynamicMenu__element(this.action);
		auxElement.referID = referID;
		auxElement.buttonReferID = buttonReferIdD;
		auxElement.openState = isOpen;
		if (!(isOpen)) auxElement.hide();
		else auxElement.activate();
		auxElement.init(this);
		this.elements.push(auxElement);
	}
}
function tk_castellini_dynamicMenu__element(action) {
	this.referID = null;
	this.openState = false;
	this.buttonReferID = null;
	this.menu = null;
	this.action = action;
	this.linkToPage = null;
	this.init = function(menu) {
	 	var obj = document.getElementById(this.buttonReferID);
		this.linkToPage = obj.href;
		
	 	var referID = this.referID;
	 	var walkaround = this;
	 	this.menu = menu;
	 	if (this.action=="CLICK") {
	 	obj.onclick = function() {
			walkaround.openOrClose();
		}}
		if (this.action=="OPENORGO") {
	 	obj.onclick = function() {
			walkaround.openOrGo();
		}}
		if (this.action=="OVER") {
	 	obj.onmouseover = function() {
			walkaround.openOrOpen();
		}}
	}
	this.open = function() {
		
		for (i=0;i<this.menu.elements.length;i++) {
		 	el=this.menu.elements[i]; 
			if (el.openState) el.close();
		}
		var obj = document.getElementById(this.buttonReferID);
		//obj.className="active";
		this.openState = true;
		Effect.SlideDown(this.referID,{ duration: tk_castellini_dynamicMenu__openDuration }); 
	}
	this.close = function() {
	 	this.openState = false;
	 	var obj = document.getElementById(this.buttonReferID);
	 	//obj.className="noUnderline";
		Effect.SlideUp(this.referID,{ duration: tk_castellini_dynamicMenu__closeDuration }); 
	}
	this.openOrClose = function() {
		if (this.openState) this.close();
		else this.open();
	}
	this.openOrGo = function() {
		if (this.openState) document.location.href = this.linkToPage;
		else this.open();
	}
	this.openOrOpen = function() {
		if (!(this.openState)) this.open();
	}
	this.hide = function() {
		$(this.referID).hide(); 
	}
	this.activate = function() {
		var obj = document.getElementById(this.buttonReferID);
		//obj.className="active";
	}
}