
function MenuRoller (varname, timeout, className, aClassName, aImgSuffix) {
	this.varname = varname;
	this.timeout = timeout;
	this.className = className;
	this.aClassName = aClassName;
	this.aImgSuffix = aImgSuffix;

	this.menuItems = new Array();
	this.timeout_h = null;
	this.defItem = null;

	this.addItem = mnrl_m_addItem;
	this.off = mnrl_m_off;
	this.on = mnrl_m_on;
	this.onDefault = mnrl_m_onDefault;
	this.show = mnrl_m_show;
	this.hide = mnrl_m_hide;
	this.preloadImage = mnrl_m_preloadImage;
}

function mnrl_m_addItem (name, itemsName, active) {
	var itemInfo = new Array(name, itemsName, active);
	var i = this.menuItems.length;

	this.menuItems[i] = itemInfo;
	if (active) this.defItem = i;

	if (this.aImgSuffix)
		this.preloadImage (i);
}

function mnrl_m_preloadImage (i) {
	if (document.getElementById) {
		var itemInfo = this.menuItems[i];

		var item = document.getElementById (itemInfo[0]);
		this.menuItems[i][3] = new Image ();
		this.menuItems[i][3].src = item.src;
		this.menuItems[i][4] = new Image ();
		this.menuItems[i][4].src = item.src.substring (0, item.src.lastIndexOf('.')) + this.aImgSuffix;
	}
}

function mnrl_m_on (itemName) {
	if (this.timeout_h) {
		clearTimeout (this.timeout_h);
		this.timeout_h = null;
	}

	for (i = 0; i < this.menuItems.length; i++) {
		var itemInfo = this.menuItems[i];

		if (itemInfo[0] == itemName) {
			this.show (itemInfo);
		} else {
			this.hide (itemInfo);
		}
	}
}

function mnrl_m_off (itemName) {
	if (this.timeout)
		this.timeout_h = setTimeout (this.varname+".onDefault();", this.timeout);
}

function mnrl_m_onDefault () {
	for (i = 0; i < this.menuItems.length; i++) {
		var itemInfo = this.menuItems[i];

		if (this.defItem == i) {
			this.show (itemInfo, true);
		} else {
			this.hide (itemInfo);
		}
	}
}


function mnrl_m_show (itemInfo, justclass) {
	if (document.getElementById) {
		var item = document.getElementById (itemInfo[0]);
		var menuItems = document.getElementById (itemInfo[1]);

		if (this.aClassName && item)
			item.className = this.aClassName;

		if (this.aImgSuffix) 
			item.src = itemInfo[4].src;

		if (menuItems) {
			if (! justclass && menuItems)
				menuItems.style.display = 'block';
			else if (justclass)
				menuItems.style.display = 'none';
		}
	}
}

function mnrl_m_hide (itemInfo) {
	if (document.getElementById) {
		var item = document.getElementById (itemInfo[0]);
		var menuItems = document.getElementById (itemInfo[1]);

		if (this.aClassName && item)
			item.className = this.className;

		if (this.aImgSuffix) 
			item.src = itemInfo[3].src;

		if (menuItems)
			menuItems.style.display = 'none';
	}
}

function changeClass (item, className) {
	item.className = className;
}