//
//Diverse menuscripts som bruges i hjælpe-systemet
//

var mItemBorder 	= 0;
var mItemHeight 	= 18;
var mItemLevelWidth 	= 13;


var status_images = new Array();
status_images.push(new String('link_image.gif'));
status_images.push(new String('arrow_down_grey.gif'));
status_images.push(new String('menu_item_1.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;
}

var hMenu = new Array();
//hMenu.push(new recMItem(0, 0, 2, 2, 'Forside', 'html/mtpstudio_start.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Nyheder', 'html/nyheder_start.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Aktuelle tilbud', 'html/tilbud.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Gear-parken', 'html/udstyr.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Referencer', 'html/referencer.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Links', 'html/links.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Kontakt/priser', 'html/kontakt.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Om MTP Studio', 'html/om_mtpstudio.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Lydbidder', 'html/lydbidder_start.html'));
hMenu.push(new recMItem(0, 0, 2, 2, 'Galleri', 'html/galleri_1.html'));
//hMenu.push(new recMItem(0, 0, 2, 2, 'Legepladsen', 'html/test_start.html'));



function buildMenu(menu){

	var S = new String('');
	var levelStr = '';
	var statusStr = '';
	var workingLevel = 0;
	var workingHeight = 0;

	S += '<div id="mainMenu" style="position: relative; left: 0px; top: 0px;">';
	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 = '' +
		'<img name="mItem_' + i + '_img" src="images/link_image.gif" align="absmiddle" border="0">&nbsp;';

		S += '<div id="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="info" class="MenuItem">' +
		     menu[i].caption + '</a></td></tr>' +
		     '</table>';
		S += '</div>';

	}

	S += '</td></tr></table></div>';
	return S;
}


function buildMenu2(menu){

	var S = new String('');
	var levelStr = '';
	var statusStr = '';
	var workingLevel = 0;
	var workingHeight = 0;

	S += '<div id="mainMenu" style="position: relative; left: 0px; top: 0px;">';
	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(hMenu, ' + i + '); return false;">' +
		'<img name="mItem_' + i + '_img" src="images/link_image.gif" align="absmiddle" border="0"></a>&nbsp;';

		S += '<div id="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="info" class="MenuItem">' +
		     menu[i].caption + '</a></td></tr>' +
		     '</table>';
		S += '</div>';

	}

	S += '</td></tr></table></div>';
	return S;
}



function adjustMenu(menu, item){

	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('mItem_' + i);
	}

	//ADJUST MENUITEM IMAGES
	for (var i = 0; i < menu.length; i++){
		if (menu[i].status == 0) getObj('mItem_' + i + '_img').src = 'images/' + status_images[menu[i].closed_image];
		else getObj('mItem_' + i + '_img').src = 'images/' + 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('mItem_' + i, workingHeight);
			showObj('mItem_' + i);
			workingHeight += mItemHeight;

			if (menu[i].status == 1) workingLevel++;
		}

	}
	setObjHeight('mainMenu', workingHeight);

}




