/**
 *
 * @copyright 2004 iWorks Marcin Pietrzak
 * @link http://www.iworks.pl/
 * @author Marcin Pietrzak <marcin.pietrzak@iworks.pl>
 *
 * @version $Revision: 1.1.1.1 $
 * @file $RCSfile: dyn.js,v $
 * @date $Date: 2005/05/10 20:11:52 $
 *
 */

function dynamicMenuRoot() {

	this.names = new Array();

	this.declare = function (id) {
		eval('this.' + id + ' = true');
		this.names[this.names.length] = id;
	}

	this.isset = function (id) {
		if (eval('this.' + id)) {
			return true;
		}
		else {
			return false
		}
	}

	this.reset = function () {
		for (i=0; i<this.names.length; i++) {
			eval(this.names[i] + '.off');
		}
	}
}

var divNamePrefix = 'section';
var objectPrefix  = 's';

function dynamicMenu(id, parent_id) {

	this.delay     = 200;
	this.show_m    = false;
	this.show_d    = false;
	this.divName   = divNamePrefix + id;
	this.parent_id = objectPrefix + parent_id;
	this.id        = objectPrefix + id;
	this.type      = 'weboxDynamicMenu';
	this.children  = new Array();

	if (parent_id > 1) {
		if (menuroot.isset(this.parent_id)) {
			p = eval(this.parent_id);
			i = p.children.length;
			p.children[i] = this;
		}
	}

	menuroot.declare(this.id);

	if ( document.getElementById ) this.css = document.getElementById(this.divName).style;
	else this.css = eval( this.divName + ".css" );

	this.show = function (type) {
		menuroot.reset();
		if (menuroot.isset(this.parent_id)) {
			p = eval(this.parent_id);
			if (p.children.length) {
				for (i=0; i<p.children.length; i++) {
					if (this.id != p.children[i].id) {
						p.children[i].off();
					}
				}
			}
		}

		eval('this.show_' + type + '= true');
		this.css.display = "block";
		if (menuroot.isset(this.parent_id)) {
			eval(this.parent_id + '.show("m")');
		}
	}

	this.off = function () {
		this.css.display = "none";
	}

	this.hide = function (type) {
		if (this.show_m || this.show_d) {
			setTimeout(this.id+'.hide()', this.delay.hide);
		}
		else {
			this.css.display = "none";
			if (menuroot.isset(this.parent_id)) {
				eval(this.parent_id + '.hideMenu()');
			}
		}
	}

	this.hideMenu = function () {
		this.show_m = false;
		setTimeout("eval('" + this.id + ".hide()')", this.delay);
	}

	this.hideDiv = function () {
		this.show_d = false;
		setTimeout("eval('" + this.id + ".hide()')", this.delay);
	}
}

var menuroot = new dynamicMenuRoot();

