/*
Diverse menuscripts
*/

var mItemBorder 	= 0;
var mItemHeight 	= 18;
var mItemLevelWidth 	= 13;
var iconWidth 		= 11;
var iconHeight		= 11;

var CheckNumber = '';
var imgPath = '';

var status_images = new Array();
status_images.push(new String('menu_closed.gif'));
status_images.push(new String('menu_open.gif'));
status_images.push(new String('menu_no_child.gif'));
status_images.push(new String('transparent_dot.gif'));

function recMItem(level, status, closed_image, open_image, caption, href){
	this.level = level;
	this.status = status;
	this.closed_image = closed_image;
	this.open_image = open_image;
	this.caption = caption;
	this.href = href;
	return this;
}


function buildMenu(menu, mName, path){
	var S = new String('');
	imgPath = path;
	var levelStr = '';
	var statusStr = '';
	var workingLevel = 0;
	var workingHeight = 0;

	S += '<div id="main_' + mName + '" style="position: relative; left: 0px; top: 0px; visibility: hidden;">';
	S += '<table border="0" cellspacing="0" cellpadding="0" class="MenuItem" width="100%"><tr><td>';

	for (var i = 0; i < menu.length; i++){

		if (menu[i].level > 0) levelStr = '<td width="' + (menu[i].level * mItemLevelWidth) + '">&nbsp;</td>';
		else levelStr = '';

		statusStr = '<a href="#" onclick="adjustMenu(' + mName + ', \'' + mName + '\', ' + i + '); return false;">' +
		'<img name="' + mName + '_mItem_' + i + '_img" src="' + imgPath + 'link_image.gif" align="absmiddle" border="0" width="' + iconWidth + '"></a>&nbsp;';

		S += '<div id="' + mName + '_mItem_' + i + '" style="position: absolute; left: 0px; top: 0px;">';
		S += '<table border="' + mItemBorder + '" cellspacing="0" cellpadding="0" width="100%" class="MenuItem">' +
		     '<tr>' + levelStr +
		     '<td height="' + mItemHeight + '">' +
		     statusStr +
		     '<a href="' + menu[i].href + '" target="InetSaleInfo" class="MenuItem">' +
		     menu[i].caption + '</a></td></tr>' +
		     '</table>';
		S += '</div>';

	}

	S += '</td></tr></table></div>';
//alert(S);
	return S;
}



function adjustMenu(menu, mName, item){


	hideObj('main_' + mName);
	if (item != -1){
		if (menu[item].status == 0) menu[item].status = 1;
		else menu[item].status = 0;
	}

	var workingHeight = 0;
	var workingLevel = 0;
	var sameLevelCount = 0;

	//HIDE ALL MENUITEMS
	for (var i = 0; i < menu.length; i++){
		hideObj(mName + '_mItem_' + i);
	}

	//ADJUST MENUITEM IMAGES
	for (var i = 0; i < menu.length; i++){
		if (menu[i].status == 0) getObj(mName + '_mItem_' + i + '_img').src = imgPath + status_images[menu[i].closed_image];
		else getObj(mName + '_mItem_' + i + '_img').src = imgPath + status_images[menu[i].open_image];
	}

	//ADJUST MENULIST
	for (var i = 0; i < menu.length; i++){


		if (workingLevel == menu[i].level) sameLevelCount++;
		if (menu[i].level < workingLevel) workingLevel = menu[i].level;

		if (menu[i].level == 0 || menu[i].level <= workingLevel){
			moveObjY(mName + '_mItem_' + i, workingHeight);
			showObj(mName + '_mItem_' + i);
			workingHeight += mItemHeight;

			if (menu[i].status == 1) workingLevel++;
		}

	}
	setObjHeight('main_' + mName, workingHeight);
	showObj('main_' + mName);
}




