/*

	GENERATING VARS FOR DYNAMIC MENU FROM CMS OUTPUT
	================================================
	A call for the appropiate CMS output 
	MUST proceed this script...!
	
	var menuList 	: menu-objects (array)
	var menuWidth	: width of top-menus (array)
	
	================================================
								by M.Fog, Tribal DDB
								
	version 1	: August 22nd/2002
	version 2	: October 22nd/2002 (in progress)



	Based on Milonic DHTML Menu
	Written by Andy Woolley
	Copyright 2002 (c) Milonic Solutions. All Rights Reserved.
	Plase vist http://www.milonic.co.uk/menu or e-mail menu3@milonic.com

*/

//The following line is critical for menu operation, and MUST APPEAR ONLY ONCE.
menunum=0;menus=new Array();_d=document;function addmenu(){menunum++;menus[menunum]=menu;}function dumpmenus(){mt="<script language=javascript>";for(a=1;a<menus.length;a++){mt+=" menu"+a+"=menus["+a+"];"}mt+="<\/script>";_d.write(mt)}
//Please leave the above line intact. The above also needs to be enabled if it not already enabled unless you have more than one _array.js file

//=========================================
timegap=500;								// The time delay for menus to remain visible
followspeed=5;								// Follow Scrolling speed
followrate=40;								// Follow Scrolling Rate
suboffset_top=18;							// Sub menu offset Top position 
suboffset_left=150;							// Sub menu offset Left position
//=========================================
var default_menu_style = buildStyle({});
var default_menu_effect = ""; 				// Special effect string for IE5.5 or above please visit http://www.milonic.co.uk/menu/filters_sample.php for more filters
//=========================================
function buildStyle(styleObj){
	var arr_param = new Array(19);
	var obj_default = {
		fontcolor1: "FFFFFF",				// Mouse Off Font Color
		bgrcolor1: "FFE5AB",				// Mouse Off Background Color (use zero for transparent in Netscape 6)
		fontcolor2: "EDCA89",				// Mouse On Font Color
		bgrcolor2: "EDCA89",				// Mouse On Background Color
		bordercolor: "630003",				// Menu Border Color 
		fontsize: 10,						// Font Size (default is px but you can specify mm, pt or a percentage)
		fontstyle: "normal",				// Font Style (italic or normal)
		fontweight: "bold",					// Font Weight (bold or normal)
		fontname: "Verdana, Arial, sans-serif",			// Font Name
		padding: 4,							// Menu Item Padding or spacing
		subicon: "img/arrows.gif",	// Sub Menu Image (Leave this blank if not needed)
		border3d: null,						// 3D Border & Separator bar
		color3dhi: null,					// 3D High Color
		color3dlow: null,					// 3D Low Color
		activefontcolor: null,				// Current Page Item Font Color (leave this blank to disable)
		activebgrcolor: null,				// Current Page Item Background Color (leave this blank to disable)
		topicon: null,						// Top Bar image (Leave this blank to disable)
		headerfontcolor: "630003",			// Menu Header Font Color (Leave blank if headers are not needed)
		headerbgrcolor: "C1803C",			// Menu Header Background Color (Leave blank if headers are not needed)
		separatorcolor: "EDCA89",			// Menu Item Separator Color
		res: null							// Reserved for future use
		};
	
	// Gathering...		
	var ii = 0;
	for(var i in obj_default){
		if(new String(styleObj[i])!="undefined"){arr_param[ii] = styleObj[i];
		}else if(obj_default[i]!=null){arr_param[ii] = obj_default[i];}
		ii++;
	}
	return arr_param;
}
function buildMenu(menuObj){
	if(menuObj && menuObj.name){
		var arr_param = new Array(22);		// Last entry - items - is special and should not be pre-registred in the array...
		var arr_item = new Array();
		var obj_default = {
			name: null,						// Menu Name - This is needed in order for the menu to be called
			top:null,						// Menu Top - The Top position of the menu in pixels
			left: null,						// Menu Left - The Left position of the menu in pixels
			width: null,					// Menu Width - Menus width in pixels
			border: 1,						// Menu Border Width 
			position: null,					// Screen Position - here you can use "center;left;right;middle;top;bottom" or a combination of "center:middle"
			style: default_menu_style,		// Properties Array - this array is declared higher up as you can see above
			visible: 0,						// Always Visible - allows the menu item to be visible at all time (1=on/0=off)
			textalignment: "left",			// Alignment - sets the menu elements text alignment, values valid here are: left, right or center
			filter: default_menu_effect,	// Filter - Text variable for setting transitional effects on menu activation - see above for more info
			followscrolling: null,			// Follow Scrolling - Tells the menu item to follow the user down the screen placing the menu at the value specified.
			horizontal: 0,					// Horizontal Menu - Tells the menu to become horizontal instead of top to bottom style (1=on/0=off)
			persistent: 0,					// Keep Alive - Keeps the menu visible until the user moves over another menu or clicks elsewhere on the page (1=on/0=off)
			downiconposition: null,			// Position of TOP sub image left:center:right
			height: null,					// Set the Overall Width of Horizontal Menu to specified width or 100% and height to a specified amount
			bidirectional: 0,				// Right To Left - Used in Hebrew for example. (1=on/0=off)
			triggeronclick: null,			// Open the Menus OnClick - leave blank for OnMouseover (1=on/0=off)
			hide: null,						// ID of the div you want to hide on MouseOver (useful for hiding form elements)
			bgrimage: null,					// BackgroundÊimageÊforÊmenuÊColorÊmustÊbeÊsetÊtoÊtransparentÊforÊthisÊtoÊwork
			scrollable: null,				// ScrollableÊMenu
			misc: null,						// MiscellaneousÊMenuÊProperties
			res: null,						// Reserved for future use
			items: new Array()				// Menuitems - Array with items for this menu (SEE buildItem)
			};
		
		// Gathering...
		var ii = 0;
		arr_param[ii] = menuObj.name;		
		for(var i in obj_default){
			if(i!="name" && i!="items"){
				if(new String(menuObj[i])!="undefined"){arr_param[ii] = menuObj[i];
				}else if(obj_default[i]!=null){arr_param[ii] = obj_default[i];}
			}
			ii++;
		}
		// Gathering the items...
		if(new String(menuObj["items"])!="undefined"){
			for(n=0;n<menuObj["items"].length;n++){
				arr_item = buildItem(menuObj["items"][n]);
				for(m=0;m<arr_item.length;m++){arr_param[arr_param.length] = arr_item[m];}
			}
		}
		return arr_param;
	}else{
		return new String("you must specify a name");
	}
}
function buildItem(itemObj){
	var arr_param = new Array(5);
	var obj_default = {
		item: null,							// Description Text or Image (or any other HTML...)
		url: "",							// URL of item - OR the action of the item
		url2: null,							// URL of item in the event of an action assigned to the above
		statustext: null,					// Text to be display in the windows statusbar on mouseOver
		separator: 0						// The width of a separatorbar between items
		};
	
	// Gathering...
	var ii = 0;		
	for(var i in obj_default){
		if(new String(itemObj[i])!="undefined"){arr_param[ii] = itemObj[i];
		}else if(obj_default[i]!=null){arr_param[ii] = obj_default[i];}
		ii++;
	}
	return arr_param;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function neatURL(thisURL){
	if(thisURL.indexOf('javascript:')>-1){
		var doJS = escape(thisURL);
		return "javascript:eval(unescape(\""+doJS+"\"));"
	}else{
		return thisURL;
	}
}
var menu;
var preLoadArray = new Array();
	
function buildEntireMenu(thisMenuObj,thisMenuLevel,thisMenuWidth,recursiveFlag){
	if(thisMenuObj){
		//=============================
		var designWidth = 250;			// the width of the content area of page
		var designLeftMargin = 5; 		// the number of pixels from the leftmost of content area to place menu
		//=============================
		
		var menuItems = new Array();
		var topMenuWidthTotal = 0;
		for (var n=0;n<thisMenuObj.length;n++){
			var newItem = new Object();
			var menuWidth = ((typeof thisMenuWidth=="number")?thisMenuWidth:(thisMenuWidth[n]!=null)?thisMenuWidth[n]:190); // fallback default width of menu...
			
			var hasSubmenuLevel = (thisMenuObj[n]!=null && thisMenuObj[n].submenu.length>0)?''+thisMenuLevel+'_'+n:false;
			if(recursiveFlag){
				if(thisMenuObj[n]!=null){
					newItem.item = '<div style="margin-left:2px">'+thisMenuObj[n].text+'<\/div>';
					newItem.url = (hasSubmenuLevel)?'show-menu='+hasSubmenuLevel:neatURL(thisMenuObj[n].url);
					newItem.url2 = (hasSubmenuLevel)?neatURL(thisMenuObj[n].url):'';
					newItem.separator = 1;
					
					menuItems[menuItems.length] = newItem;
				}
			}else{
				// THE TOP MENU
				/*
					First we put a 'header' menu-item to display a 1x5px designer bit!
					Followed by the actual menu-item with rollover effect! (if the menu-obj is 'null' the menu-item will be 'header')
					NOTE: rollover effet has been removed - to re-inserte:
					in the [newItem.url = ...] and [newItem.url2 = ...] change [neatURL(thisMenuObj[n].url)] to [neatURL(thisMenuObj[n].url)+' swapimage=image/xxx.gif']
				*/
				menuItems[menuItems.length] = {
				 item:((thisMenuObj[n]!=null)?'<img src="/img/1x1_black.gif" width="1" height="5" />':'<img src="/img/hidden.gif" width="1" height="14" />'),
				 url:'# type=header;',
				 statustext:''
				};
				
				topMenuWidthTotal += (menuWidth+1);
				var topMenuContent = '';
				var nsWidthHack = '<img src="/img/hidden.gif" width="'+menuWidth+'" height="1" border="0" />'; //ns hack...
				if(thisMenuObj[n]!=null){
					var topMenuImgSrc = ''+thisMenuObj[n].text;
					var topMenuContent = '<img src="'+topMenuImgSrc+'" border="0" />';
					
					// PRELOAD TOP MENU IMAGES (to avoid double height bug...)
					var preLoadArrIndex = preLoadArray.length;
					preLoadArray[preLoadArrIndex] = new Image();
					preLoadArray[preLoadArrIndex].src = topMenuImgSrc;
				}
				topMenuContent += '<img align="top" src="/img/hidden.gif" width="1" height="10" border="0" />'; // keep the height of the top menu
				newItem.item = '<div style="padding-left:1px;padding-top:0px;">'+topMenuContent+'<\/div>'+nsWidthHack;
				newItem.url = (thisMenuObj[n]!=null)?((hasSubmenuLevel)?'show-menu='+hasSubmenuLevel:neatURL(thisMenuObj[n].url)):'# type=header;';
				if(hasSubmenuLevel) newItem.url2 = neatURL(thisMenuObj[n].url);
				if(thisMenuObj[n]==null) newItem.statustext = '';
				
				menuItems[menuItems.length] = newItem;
			}
			
			// FOR SUBMENUS WE DO A RECURSIVE CALL!
			if(hasSubmenuLevel) buildEntireMenu(thisMenuObj[n].submenu,hasSubmenuLevel,menuWidth,true);
		}
		
		// DOING THE Milonic DHTML Menu!!!
		var menuObj = new Object();
		menuObj.name = thisMenuLevel;
		menuObj.items = menuItems;
		if(!recursiveFlag){
			// THE MAIN MENU
                        if(navigator.appName=="Microsoft Internet Explorer") 
                           {menuObj.top = 128;
                           }
                         else
                           {menuObj.top = 128;
                           }
			 var menuOffset = designLeftMargin - ((designWidth-topMenuWidthTotal)/2);
			menuObj.left = "offset="+menuOffset;
			menuObj.position = "left";
			menuObj.style = buildStyle({bgrcolor1:"C1803C",bgrcolor2:"C1803C",padding:0});
			menuObj.border = 0;
			menuObj.visible = 1;
			menuObj.horizontal = 1;
		}else{
			menuObj.width = menuWidth+1;
			menuObj.border = 1;
		}
		menu = buildMenu(menuObj);addmenu();
	}else{
		return new String("invalide menu object");
	}
}
//=========================================

 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 //  REMEMBER TO REMOVE -- BELOW MOST BE SEND FROM CMS
 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		menuWidth=[null,null,null,null];



buildEntireMenu(menuList,"mnu",menuWidth);
dumpmenus();