/*
 * CIM Electronics Menu script.
 * Version 1.0
 * 23.03.2003
 * mtt@cim-electronics.com
 *
 * =====================
 * startMenu() 		Starts the menu and should be called at first.
 * stopMenu()		Shows the menu on the screen and no further items can be added. 
 * addMenuItem()	Add a point the the current menu.
 * 		title	- the menu item text
 *		url		- the link to follow onClick
 *		newWindow - display the link in a new window ( optional ).
 * addSubmenu()		Adds a sub menu to the menu bar. All subsequent calls to addMenuItem() will add items to this submenu
 * 		title	- the title of the submenu.
 * endSubMenu()		Closes the submenu. After this the addMenuItem() adds items to the previous menu.
 */

timegap=2000			// The time delay for menus to remain visible
followspeed=5			// Follow Scrolling speed
followrate=40			// Follow Scrolling Rate
menuTopOffset=7;
menuLeftOffset=4;
suboffset_top=10;		// Sub menu offset Top position 
suboffset_left=10;	// Sub menu offset Left position

menuStyle=[				
"white",					// Mouse Off Font Color
"transparent",			// Mouse Off Background Color
"silver",				// Mouse On Font Color
"transparent",			// Mouse On Background Color
"transparent",			// Menu Border Color 
10,						// Font Size in pixels
"normal",				// Font Style (italic or normal)
"bold",					// Font Weight (bold or normal)
"verdana,arial,sans-serif",		// Font Name
2,							// Menu Item Padding
"",						// Sub Menu Image (Leave this blank if not needed)
,							// 3D Border & Separator bar
"",						// 3D High Color
"",						// 3D Low Color
"",						// Current Page Item Font Color (leave this blank to disable)
"",						// Current Page Item Background Color (leave this blank to disable)
"",						// Top Bar image (Leave this blank to disable)
"",						// Menu Header Font Color (Leave blank if headers are not needed)
"",						// Menu Header Background Color (Leave blank if headers are not needed)
]

menuStyle2=[				
"white",					// Mouse Off Font Color
"8aa8c4",				// Mouse Off Background Color
"8aa8c4", 				// Mouse On Font Color
"white",					// Mouse On Background Color
"8aa8c4",		  		// Menu Border Color 
10,						// Font Size in pixels
"normal",				// Font Style (italic or normal)
"bold",					// Font Weight (bold or normal)
"verdana,arial,sans-serif",				// Font Name
3,							// Menu Item Padding
"",						// Sub Menu Image (Leave this blank if not needed)
,							// 3D Border & Separator bar
"",						// 3D High Color
"",						// 3D Low Color
"",						// Current Page Item Font Color (leave this blank to disable)
"",						// Current Page Item Background Color (leave this blank to disable)
"",						// Top Bar image (Leave this blank to disable)
"",						// Menu Header Font Color (Leave blank if headers are not needed)
"",						// Menu Header Background Color (Leave blank if headers are not needed)
]

_d=document;

var menuStack = new Stack();
/*
 * The menu list pointer
 */
var mp = 1;
/*
 * The list of menu's
 */
var ml = new Array();
var udf;

function startMenu() {
	mp = 1;
	menuItemPointer = 0;
	ml[mp] = new Array();
		
	ml[mp][ ml[mp].length ] = "main_menu";
	ml[mp][ ml[mp].length ] = 2;
	ml[mp][ ml[mp].length ] = 0;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = 0;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = menuStyle;
	ml[mp][ ml[mp].length ] = 1;
	ml[mp][ ml[mp].length ] = "left";
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = 1;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;

}

function stopMenu() {
	menus = ml;
	mt="<script language=javascript>";
	for(a=1;a<menus.length;a++){
		mt+=" menu"+a+"=ml["+a+"];"
	}
	mt+="<\/script>";
	_d.write(mt);
}

function addMenuItem( title, url, newWindow ) {

	ml[mp][ ml[mp].length ] = getSpacer() + title + getSpacer();
	ml[mp][ ml[mp].length ] = url + " " + ( newWindow == true ? "target=new" : "" );
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = title;
	ml[mp][ ml[mp].length ] = ( mp == 0 ? 1 : 0 );
} 

function addSubMenu( title, width ) {

	menuIdentifier = title.replace( " ", "_") + ml.length
	menuIdentifier = "sub_menu" + ml.length
	
	ml[mp][ ml[mp].length ] = getSpacer() + title + getSpacer();
	ml[mp][ ml[mp].length ] = "show-menu="+menuIdentifier;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;		
	ml[mp][ ml[mp].length ] = 0;
	
	menuStack.Push( mp );
	mp = ml.length;

	ml[mp] = new Array();
		
	ml[mp][ ml[mp].length ] = menuIdentifier;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = width;
	ml[mp][ ml[mp].length ] = 2;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = menuStyle2;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = "left";
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
	ml[mp][ ml[mp].length ] = udf;
}

function endSubMenu() {
	mp = menuStack.Pop( );
}

function getSpacer() {
	if (mp == 1) {
		return "&nbsp;&nbsp;";
	} else {
		return "";
	}
}

function dumpArray ( a1 ) {
	for ( var i=0 ; i < a1.length ; i++ ){
		document.write( i + " : " + a1[i] + '<br>' );
	}
}

function Stack () {
	stack = new Array();
	pointer = -1;
	
	function Push( elm ) {
		stack[++pointer] = elm;
	}
	
	function Pop() {
		elm = stack[pointer];
		pointer--;
		return elm;
	}
	
	this.Pop = Pop; 
 	this.Push = Push; 
}