// MENU BAR OBJECT //
function menuBar(oWINDOW, sNAME, iHeadOff, iHeadH, iX, iY, iMaxY, iW, iH, iZ) {
	this.window = oWINDOW;
	this.name = sNAME;
	this.groupOffset = iHeadOff;
	this.headHeight = iHeadH;
	this.x = iX;
	this.y = iY;
	this.maxY = iMaxY;
	this.w = iW;
	this.h = iH;
	this.z = iZ;
	this.groups = new Array();
}
menuBar.prototype.addGroup = function(oMENUGROUP) {
	var index = this.groups.length;
	this.groups[index] = new aniLayer(this.window, (this.name + ".groups[" + index + "]"), this.x, this.y + (this.groupOffset * index), this.w, this.headHeight, this.z + index);
	this.groups[index].custCSS = "overflow: hidden;";
	this.groups[index].outputStyle();
	this.groups[index].group = oMENUGROUP;
	this.groups[index].group.parent = this;
	this.groups[index].group.index = index;
	this.groups[index].group.onToggle = function() { 
		this.parent.draw(this.index);
		return false;
	}
	this.groups[index].parent = this;
	this.groups[index].index = index;
	if (index > 0) {
		this.groups[index].onUpdate = function() {
			this.parent.groups[this.index - 1].setTo(this.getX(), this.getY() - this.parent.groupOffset);
		}
	}
};
menuBar.prototype.hide = function() {
	for (var i = 0; i < this.groups.length; i++) {
		this.groups[i].hide();
	}
};
menuBar.prototype.show = function() {
	for (var i = 0; i < this.groups.length; i++) {
		this.groups[i].show();
	}
};
menuBar.prototype.init = function() {
	for (var i = 0; i < this.groups.length; i++) {
		this.groups[i].init();
	}
};
menuBar.prototype.output = function() {
	for (var i = 0; i < this.groups.length; i++) {
		this.groups[i].outputLayer();
	}
};
menuBar.prototype.draw = function(iINDEX) {
	this.h = (this.groupOffset * this.groups.length);
	this.y = this.maxY - this.h;
	var indexIsOpen = (iINDEX != undefined && this.groups[iINDEX].group.head.isOpen) ? true : false;
	var offset = (iINDEX != undefined && this.groups.length == 1 && !indexIsOpen) ? 0 : 1;
	var lastOne = this.groups[this.groups.length - 1];
	lastOne.setTo(this.x, this.y + this.h - this.groupOffset + offset);
	for (var i = 0; i < this.groups.length; i++) {
		this.groups[i].group.close();
		this.groups[i].setHeight(this.headHeight);
		if (i == iINDEX && !indexIsOpen) { 
			this.groups[i].slideTo(-100, 12, this.x, this.groups[i].getY() - this.groups[i].group.getHeight() + this.headHeight, this.groups[i].getWidth(), this.groups[i].group.getHeight());
			this.groups[i].group.open();
			this.groups[i].setBody(this.groups[i].group.draw());
		}
		this.groups[i].setBody(this.groups[i].group.draw());
		this.groups[i].show();
	}
};
// MENU GROUP OBJECT //
function menuGroup(sNAME, sLABEL, sSPACER, sALIGN, sCLASS, sCOLOUR, sItemColour, iItemW, iItemH, iItemPAD) {
	this.name = sNAME;
	this.head = new menuItem(sLABEL, "javascript:" + this.name + ".toggle();", sCLASS);
	this.head.hasDislosure = true;
	this.spacer = sSPACER;
	this.colour = sCOLOUR
	this.itemAlign = sALIGN;
	this.itemColour = sItemColour;
	this.itemWidth = iItemW;
	this.itemHeight = iItemH;
	this.itemPad = iItemPAD;
	this.items = new Array();
}
menuGroup.prototype.open = function() {
	this.head.isOpen = true;
	if (!this.onOpen || this.onOpen()) {
		this.draw();
	}
};
menuGroup.prototype.close = function() {
	this.head.isOpen = false;
	if (!this.onClose || this.onClose()) {
		this.draw();
	}
};
menuGroup.prototype.toggle = function() {
	if (!this.onToggle || this.onToggle()) {
		if (this.head.isOpen) { this.close(); }
		else { this.open(); }
	}
};
menuGroup.prototype.getHeight = function() {
	return (this.itemHeight + 1) * (this.items.length + 1);
}
menuGroup.prototype.draw = function() {
	var tempHTML = '<table border="0" cellpadding="0" cellspacing="1" bgcolor="' + this.colour + '">';
		tempHTML += '<tr>\n';
		tempHTML += '<td>';
		tempHTML += this.head.genHTML(this.spacer, this.itemAlign, this.itemWidth, this.itemHeight, this.itemPad);
		tempHTML += '</td>\n';
		tempHTML += '</tr>\n';
	if (this.head.isOpen) {
		for (var i = 0; i < this.items.length; i++) {
			tempHTML += '<tr bgcolor="' + this.itemColour + '">\n';
			tempHTML += '<td>';
			tempHTML += this.items[i].genHTML(this.spacer, this.itemAlign, this.itemWidth, this.itemHeight, this.itemPad);
			tempHTML += '</td>\n';
			tempHTML += '</tr>\n';
		}
	}
		tempHTML += '</table>';
	return tempHTML;
};
menuGroup.prototype.addItem = function(sLABEL, sURL, sCLASS, sTARGET) {
	this.items[this.items.length] = new menuItem(sLABEL, sURL, sCLASS, sTARGET);
};
// MENU ITEM OBJECT //
function menuItem(sLABEL, sURL, sCLASS, sTARGET) {
	this.label = sLABEL;
	this.url = sURL;
	this.htmlClass = sCLASS;
	this.target = sTARGET;
}
menuItem.prototype.hasDislosure = false;
menuItem.prototype.isOpen = false;
menuItem.prototype.genHTML = function(sSPACER, sALIGN, iW, iH, iPAD) {
	var target = (this.target) ? this.target : "_top";
	var tempHTML = '<table border="0" cellpadding="0" cellspacing="0" width="' + iW + '">\n';
		tempHTML += '<tr>\n';
		tempHTML += '<td width="' + iPAD + '"><img src="' + sSPACER + '" width="' + iPAD + '" height="' + iH + '"></td>\n';	
		tempHTML += '<td align="' + sALIGN + '">\n';
		if (this.hasDislosure) { 
			var sSymbol = (this.isOpen) ? "6" : "4"; 
			tempHTML += '<a href="' + this.url + '" class="' + this.htmlClass + '"><span class="symbol">' + sSymbol + '</span></a>';
			tempHTML += ' <span class="' + this.htmlClass + '">' + this.label + '</span>';
		} else if (this.url) { 
			tempHTML += '<a href="' + this.url + '" target="' + target + '" class="' + this.htmlClass + '">' + this.label + '</a>'; 
		} else {
			tempHTML += '<span class="' + this.htmlClass + '">' + this.name + '</span>';
		}
		tempHTML += '</td>\n';	
		tempHTML += '</tr>\n';
		tempHTML += '</table>';
	return tempHTML;
};
