function newMenu(bgColor1, bgColor2, textColor1, textColor2, style, type) {
	this.cssClass = style;
	this.bgColor1 = bgColor1;
	this.bgColor2 = bgColor2;
	this.textColor1 = textColor1;
	this.textColor2 = textColor2;

	this.openLayer = openLayer;
	this.newElement = newElement;
	this.closeLayer = closeLayer;
	
	this.type = (type == 'h')?('h'):('v');
}

function openLayer(id, parentID) {
	if (parentID == null) 
		affected = id;
	else 
		affected = id + ',' + parentID;
	document.write('<div id="' + id + '" style="position: absolute; visibility: hidden" onMouseOver="showMenu(\'' + affected + '\')" onMouseOut="hideMenu(\'' + affected + '\')">\n');
	document.write('<table border=0 cellspacing=0 class="' + this.cssClass + '">\n');
	document.write('<tr>');
}

function newElement(text, link, target, childID) {
	if (target == null) target = 'document';
	document.write('<td class="' + this.cssClass + '" style="color: ' + this.textColor1 + '; background-color: ' + this.bgColor1 + '; cursor: hand; z-index: 999;" onMouseOver="this.style.backgroundColor=\'' + this.bgColor2 + '\'; this.style.color=\'' + this.textColor2 + '\'');
	if (childID != null) document.write('; showMenu(\'' + childID + '\')');
	document.write('" onMouseOut="this.style.backgroundColor=\'' + this.bgColor1 + '\'; this.style.color=\'' + this.textColor1 + '\'');
	if (childID != null) document.write('; hideMenu(\'' + childID + '\')');
	document.write('" onClick="' + target + '.location.href=\'' + link + '\'"><a class="' + this.cssClass + '" href="' + link + '">' + text + '</a></td>');
	if (this.type == 'v') document.write('</tr><tr>');
}

function closeLayer() {
	document.write('</tr>');
	document.write('</table>\n</div>');
}

function showMenu(layer_id) {
	layers = layer_id.split(',');
	for (i = 0; i < layers.length; i++) {
		layer = layers[i].trim();
		menu = getLayer(layers[i]);
		if (menu.style) menu.style.visibility = 'visible';
	//	if (menu.visibility) menu.visibility = 'visible';
	}
}

function hideMenu(layer_id) {
	layers = layer_id.split(',');
	for (i = 0; i < layers.length; i++) {
		menu = getLayer(layers[i]);
		if (menu.style) menu.style.visibility = 'hidden';
		if (menu.visibility) menu.visibility = 'hidden';
	}
}

function getLayer(strLayer) {
	if (document.all) {
		obj = document.all[strLayer];
	} else if (document.getElementById) {
		obj = document.getElementById(strLayer);
	} else if (document.layers) {
		obj = document.layers[strLayer];
	} else {
		obj = strLayer;
	}
	return obj;
}

function trim() {
	return this.replace(/^\s*/gi, '').replace(/\s+$/gi, '');
}

String.prototype.trim = trim;

function setPosition(menu_id, img_id, hOffset, vOffset) {
	menu = getLayer(menu_id);
	img = getLayer(img_id);

	menuPosX = findPosX(img) + hOffset;
	menuPosY = findPosY(img) + vOffset;

	if (menu.style) {
		menu.style.left = menuPosX + 'px';
		menu.style.top = menuPosY + 'px';
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
