
	var dds = (window.isMainPage ? '' : '../');

var cm='',pm='',pmfs=''; //Current menu, previous menu and previous menu for showing
var scroll_pos = new Object(); //for fancy menu effect
var menuHidingTimeout;
var menuEventsAdded;

//These variable are filled in by menudata_xx.js:
var menuIDs= new Array(), menuWidths={};
var scrollFrames;
var frameDisplayTime;
var menuHidingDelay;
var scrollExponent,imageNames = new Array(), showDelay;

//var spewingn,spewing={};


// Here are various variables that can be tweaked with:

// How many milliseconds the menus stay there when the mouse moves away:
menuHidingDelay = 337;

// Delay in milliseconds before a submenu pops up:
showDelay = 250;



// ---Menu sliding effect:---

// Number of frames:
scrollFrames =  10;

// How long each frame lasts (in milliseconds):
frameDisplayTime = 23;


var x_positions=[];
var y_positions=[];
var totalbumpheights=0;
for (var x = 0; x<=scrollFrames; x++) {
	totalbumpheights += (y_positions[x] = Math.exp((x*10/scrollFrames - 11) / 2));
}
for (var x = scrollFrames; x>=0; x--) {
	x_positions[x] = y_positions[x] / totalbumpheights;
	if(x<scrollFrames) x_positions[x] += x_positions[x + 1];
}

var menuAnimData = { 'mi_middle' : {}, 'leftHalf' : {}, 'rightHalf' : {}};
var menuElems={};

function miover(id){ //when the mouse moves over a menu item (one with a submenu)
	var li,ss;
	hideOthers(id)
	//If the last menu was a submenu of this one
	if (pmfs.substring(0,id.length)==id){
		//else showMenu(id);
	}
	else {
			if (!scroll_pos[id.substring(0,li)]) showMenu(id);
	}
}
function miout(id){ //when the mouse moves off a menu item
	if (cm==id){
		cm='';
		pm=pmfs=id;
	}
	setTimeout('pmfs == "' + id + '" && !cm && (pmfs="")', 1);
	if (menuHidingTimeout)clearTimeout(menuHidingTimeout);
	menuHidingTimeout=setTimeout('hideAll()',menuHidingDelay);
}
/*
function smiover(obj,id) { //when the mouse moves over a "simple" menu item (without a submenu)
	if (!(ss=id.substring(0,id.lastIndexOf('_'))).lastIndexOf('_')){  //if this menu item is in a root menu
		if (!scroll_pos[ss]) obj.nextSibling.className='menuitem_active';
	}
	else obj.nextSibling.className='menuitem_active';
}
function smiout(obj) {//when the mouse moves off a "simple" menu item
	obj.nextSibling.className='menuitem'
}*/
function mover(id){ //when the mouse moves over a menu
	hideOthers(id)
}
function mout(id){ //when the mouse moves off a menu
	if (cm==id){
		cm='';
		pm=pmfs=id;
	}
	if (menuHidingTimeout)clearTimeout(menuHidingTimeout);
	menuHidingTimeout=setTimeout('hideAll()',menuHidingDelay);
}
function showMenu(id){
	if (id.lastIndexOf('_')) { // Not root menu
		menuElems['mi' +id ].style.color="#fff";
	}
	else {//root menu
		var menuitem = menuElems['mi' +id ].firstChild;
		if (menuitem.tagName&&menuitem.tagName.toLowerCase() == 'img') menuitem.src = dds + 'umages/sn-' + imageNames[id.substring(1)] + '.gif';
	}
	if (menuItems[id].length) {
		setTimeout("cm == '" + id + "' && fancy_show('"+id+"')",showDelay);
	}
}
var fs_info='';
function fancy_show(id){
	var nid=id.substring(1); //numeric ID (without the underscore)
	var mi = menuElems['mi'+id];
	var subtract2 = false;
	var startelem = mi.clientHeight && mi.clientWidth ? mi : mi.firstChild.tagName  && mi.firstChild.tagName.toLowerCase()=='img' ? mi.firstChild : (subtract2 = true, mi.parentNode);
	var elem= startelem;
	var mix = miy = 0;	
	while (elem){
		mix+=elem.offsetLeft;//-element.scrollLeft;	
		miy+=elem.offsetTop;//-element.scrollTop;
		elem=elem.offsetParent;
	}
	
	/*if (!startelem.clientHeight) {
		var miw = mi.parentNode.clientWidth - 24;
		var mih = mi.parentNode.clientHeight - 8;
	}
	else {*/
		var miw = startelem.clientWidth;
		var mih = startelem.clientHeight;
		subtract2 && (mih -= 2);
//	}

	var menu = menuElems['m'+id];
	var sty=menu.style;
	var sty2 = menuElems['m'+id+'clone'].style;
	
	if (!scroll_pos[id]){ // If this is the first frame:
		//Set the frame number and display the frame:
		scroll_pos[id]=scrollFrames;
		sty.display=sty2.display='';

		//Get all the measurements and positions:
		menuWidths[id] = menu.childNodes[2].firstChild.clientWidth + 24;
		menuAnimData.mi_middle[id] = Math.floor(mix + miw/2);
		menuAnimData.leftHalf[id] = Math.floor(menuWidths[id] / 2);
		if (menuAnimData.leftHalf[id] + menuAnimData.mi_middle[id] - document.body.scrollLeft > document.body.clientWidth - 6) {
			menuAnimData.rightHalf[id] = document.body.clientWidth - 6 + document.body.scrollLeft - menuAnimData.mi_middle[id];
			menuAnimData.leftHalf[id] = menuWidths[id] - menuAnimData.rightHalf[id];
		} else {
			 menuAnimData.mi_middle[id] - 6 - document.body.scrollLeft < menuAnimData.leftHalf[id] && (menuAnimData.leftHalf[id] = menuAnimData.mi_middle[id] - 6 - document.body.scrollLeft);
			menuAnimData.rightHalf[id] = menuWidths[id] - menuAnimData.leftHalf[id];
		}

		//Put the neck in its place:
		menuElems['msp'+id].style.width = 
		menuElems['msp'+id+'clone'].style.width =
			menuAnimData.leftHalf[id] - Math.floor(miw/2) + 'px';
		menuElems['mneck'+id].style.width = 
		menuElems['mneck'+id+'clone'].style.width =
			miw + 'px';
			fs_info='';
	}
	else scroll_pos[id]--;//if (id == '_1_2' && scroll_pos[id] == 5)return; 
	if (scroll_pos[id]) setTimeout('fancy_show("'+id+'")',frameDisplayTime);

	var mi_middle = menuAnimData.mi_middle[id];
	var leftHalf = menuAnimData.leftHalf[id];
	var rightHalf = menuAnimData.rightHalf[id];

	if (scroll_pos[id]) {
		var clipTop = Math.floor(y_positions[scroll_pos[id]] * menu.clientHeight / y_positions[scrollFrames]);
		var newTop = miy + mih - clipTop;
		var clipRight = Math.ceil(x_positions[scroll_pos[id]] * leftHalf);
		var newLeftL = mi_middle - clipRight;
		var clipLeft = Math.ceil(x_positions[scroll_pos[id]] * rightHalf);
		var newLeftR = mi_middle + clipLeft - menuWidths[id];
fs_info += menu.clientHeight + ' ' + clipTop + ' ' + newTop + ' ' + clipRight + ' ' + newLeftL + ' ' + clipLeft + ' ' + newLeftR + '\n';
		sty.width = clipRight + 'px';
		sty.top=sty2.top=newTop;
		sty.left=newLeftL + 'px';
		sty2.left = newLeftR + 'px';
		sty.clip='rect(' + clipTop + 'px ' + clipRight + 'px ' + menu.clientHeight + 'px ' + '0px)';
		sty2.clip='rect(' + clipTop + 'px ' + menuWidths[id] + 'px ' + menu.clientHeight + 'px ' + (menuWidths[id] - clipLeft) + 'px)';
		//if (id == '_1_2') alert(newLeftL + ' + ' + clipLeft + ' = ' + (newLeftL + clipLeft) + '; ' + newLeftR);
		//alert( clipRight + '   ' + leftHalf + "\n" + clipLeft + '   ' + rightHalf);
		//alert(newLeftL + '    ' + newLeftR);
	} else {
		//spewing[id] && (spewing[id]=spewingn=false);
		sty.left = mi_middle - leftHalf;
		sty.top = miy + mih;
		sty.width = '';
		sty.clip='rect(0px ' + menuWidths[id] + 'px 1000000px 0px)';
		// I have to leave it clipped because IE4Win won't let me turn it off, and Opera4Mac tries to extend the div to the right edge of the window.
		sty2.display='none';
	}
}
function hideOthers(id){// alert('hiding '+ id)
	if (cm.substring(0,id.length) != id) { //if what was the current menu is not a child of this menu
		cm=id;

		var indx,toClose=pm;
		while  ((indx = toClose.lastIndexOf('_'))>=0){//alert(id+'   '+toClose);
			//if this menu is not a child of the previous one
			if(id.substring(0,toClose.length) != toClose){//alert(id +' is closing '+toClose+' because prev was '+pm);
				hideMenu(toClose);
				//spewingn=false;
				toClose = toClose.substring(0,indx);
			}
			else {
				break;
			}
		}
	}
	else ('can\'t hide oher than ' + id + ' \'cos cm is ' + cm);
}
function hideAll() {
//This function checks to see whether the menus should be hidden before actually doing it.
	//if (spewingn){
//		if (menuHidingTimeout)clearTimeout(menuHidingTimeout);
//		menuHidingTimeout=setTimeout('hideAll()',menuHidingDelay);
//		return;
	//}
	// if no menu is active (has the mouse on it):
	if (!cm) {
		var indx;
		while  ((indx = pm.lastIndexOf('_'))>=0){
			hideMenu(pm);
			pm = pm.substring(0,indx);
		}
	pmfs='';
	}
}
function hideMenu(id) {// alert(id);
	if (menuElems['m' + id]) {
		menuElems['m'+ id].style.display='none';
		menuElems['m'+ id+'clone'].style.display='none';
	}
	if (id.lastIndexOf('_')){ //Not root:
		menuElems['mi'+id].style.color='';//className='mi';
	}
	else { //root menu
		var menuitem = menuElems['mi' +id].firstChild;
		if (menuitem.tagName && menuitem.tagName.toLowerCase() == 'img') menuitem.src=dds + 'umages/sn-' + imageNames[id.substring(1)] + 's.gif';
	}
}

//javascript:menuElems['m_2'].style.display='';

function resizeMenus(){
	// This actually chooses between existing menus of different sizes.
	var window_width=/*window.innerWidth ||*/ document.body.clientWidth;
	var id, this_menu,  number_of_rose,item;
	for (var i=0;i<menuIDs.length;++i){
		id = menuIDs[i];
		number_of_rose = 0;
		while(++number_of_rose <= menuItems[id].length) {
			if(!(this_menu = document.getElementById('m' + id + 'x' + number_of_rose))) continue;
							
			this_menu.style.visibility='hidden';
			this_menu.style.display='';
			
			if((this_menu.childNodes[2].firstChild.clientWidth > 900 || this_menu.childNodes[2].firstChild.clientWidth > window_width - 12) && number_of_rose < menuItems[id].length) {
				this_menu.style.display='none';
				continue;
			}
//javascript:var m ='';for(var i in menuElems)m+=i+' = '+menuElems[i] + '\n';alert(m)
			this_menu.style.display='none';
			this_menu.style.visibility='';
			

			menuElems['m' + id] = this_menu;
			menuElems['msp' + id] = document.getElementById('msp' + id + 'x' + number_of_rose);
			menuElems['mneck' + id] = document.getElementById('mneck' + id + 'x' + number_of_rose);
			menuElems['m' + id + 'clone'] = document.getElementById('m' + id + 'x' + number_of_rose + 'clone');
			menuElems['msp' + id + 'clone'] = document.getElementById('msp' + id + 'x' + number_of_rose + 'clone');
			menuElems['mneck' + id + 'clone'] = document.getElementById('mneck' + id + 'x' + number_of_rose + 'clone');
			item=-1; while (++item < menuItems[id].length){
				menuElems['mi' + menuItems[id][item][0]] = document.getElementById('mi' + menuItems[id][item][0] + 'x' + number_of_rose);}
			break;
		}
	}
	if(!menuEventsAdded) addMenuEvents();
	window.menuResizeTimeout = void(0);
}


function addMenuEvents(){
	var elem;
	for (var i=0;i<10;++i){
		if (!(menuElems['mi_'+i] = elem = document.getElementById('mi_'+i))) continue;
		elem.onmouseover = new Function ('miover("_'+i+'")');
		elem.onmouseout=new Function('miout("_'+i+'")');
	}
	menuEventsAdded=true;
	 ctosPrld();
}
function calculateScrollIntervals(){
	var elem;
	for(var i=0;i<leftEdges.length;++i){
		if(elem = document.getElementById('m_'+i)){
			elem.style.visibility='hidden';
			elem.style.display='';
			//interval[i] = elem.clientHeight/scrollFrames;
			clipcoords[i] = 'px ' + elem.clientWidth + 'px ' + elem.clientHeight + 'px 0px';
			elem.style.display='none';
			elem.style.visibility='';
		}
	}
}

var __id = "_-1";
var __toWrite=new Object();
var __prevLevel=0 ;
var menuItems = new Object();
function addMenuItem(level,title,link){
	var li;
	var idcopy=__id;
	if (__prevLevel > level) {
		var difference = __prevLevel-level;
		while(difference--){
			__id = __id.substring(0,__id.lastIndexOf('_'));
		}
	} else if (__prevLevel < level) {
		__id += '_-1';
	};
	__id = __id.substring(0,(li = __id.lastIndexOf('_'))+1) + (__id.substring(li+1)*1+1);
	var __parentId = __id.substring(0,li);
	if (!level){
		menuIDs[menuIDs.length] = __id;
		menuItems[__id] = new Array();
	}
	else if (title.substring(title.length-2) == ' >'){
		menuIDs[menuIDs.length] = __id;
		menuItems[__id] = new Array();
		menuItems[__parentId][menuItems[__parentId].length] = [__id, title.substring(0,title.length-1), link];
	}
	else {
		menuItems[__parentId][menuItems[__parentId].length] = [__id, title, link];
	}
	__prevLevel=level;
}

function writeMenus(){

	var id, this_menu, item, menu_body, html, number_of_rose, row_num, j,items_in_this_row, items_in_last_row,level;
	var arowText = '<span class=arrrow>▼</span>';
	for (var i=0;i<menuIDs.length;++i){
		id = menuIDs[i];
		if(!menuItems[id].length) continue;
		
		level = id.split('_').length;
				
		
		number_of_rose = 0;
		while(true) {
			number_of_rose++;
			while((items_in_last_row = menuItems[id].length - (items_per_row = Math.ceil(menuItems[id].length / number_of_rose)) * (number_of_rose - 1)) < 1)
				number_of_rose++;
			html=lmth='';

			row_num = 0;

			while(row_num++ < number_of_rose) { // from 1 to numberofrose
				html+='<tr>';
				if(row_num == number_of_rose){
					items_in_this_row = items_in_last_row;
					// if the number of items in the last row is not congruent with the number of items in each of the other rows with regard to the modulus 2:
//					if ((items_per_row - items_in_this_row) % 2) {
//						html += "<td colspan=" + items_per_row + " align=center><table cellpadding=0 cellspacing=0 border=0><tr>";
//						lmth = "</tr></table></td>";
//					} else {
						j=0; while (j++ < Math.floor((items_per_row - items_in_this_row) / 2))
							html += "<td></td>";
//					}
				}
				for (item = items_per_row * (row_num - 1), j=0; j<(row_num < number_of_rose ? items_in_this_row = items_per_row : items_in_this_row); j++, item++) {
					html += "<td";
					//this_cell.setAttribute ('class', 'menucell');
//					if (items_per_row > items_in_this_row)
//						html += ' align=center';
//					else j && (html += ' align=' + (j < items_in_this_row-1 ? 'center' : 'right'));
					html += " class=midiv><table border=0 cellpadding=0 cellspacing=0><tr><td><a id='mi" +  menuItems[id][item][0] + 'x' + number_of_rose + "' href='" +  menuItems[id][item][2] + "' class=mi";
					if (menuItems[menuItems[id][item][0]]) { //If this item has a submenu
						html += ' onmouseover="miover(\'' + menuItems[id][item][0] + '\')" onmouseout="miout(\'' +  menuItems[id][item][0] + '\')"';
					}
					html += '>' + menuItems[id][item][1] + (menuItems[menuItems[id][item][0]] ? arowText : '') + '</table></a></td>';
				}
				html +=lmth+"</tr>";
				lmth='';
			}
			document.write('<div id="m' + id + 'x' + number_of_rose + '" style="z-index: 2;position: absolute;display:none;top: 0px; left: 0px; white-space:nowrap; overflow: hidden" onmouseover="mover(\'' + id + '\')" onmouseout="mout(\'' + id + '\')"><img src="' + dds + 'umages/t.gif" style="height: 10px; width:1px" id=msp' + id + 'x' + number_of_rose + '><img src="' + dds + 'umages/g85' + (level % 2 ? 2 : '') + '.png" style="height: 10px; width:1px" id=mneck' + id + 'x' + number_of_rose + '><div class=menubody' + (level % 2 ? 2 : '') + '><table cellpadding=0 cellspacing=0>' + html + '</table></div></div>');
			if (items_per_row <= 1) break;
		}
		
		/*   CLONE  */

		number_of_rose=0;
		while(true) {
			number_of_rose++;
			while((items_in_last_row = menuItems[id].length - (items_per_row = Math.ceil(menuItems[id].length / number_of_rose)) * (number_of_rose - 1)) < 1)
				number_of_rose++;

			html='';
			row_num = 0;
			while(row_num++ < number_of_rose) { // from 1 to numberofrose
				html+='<tr>';
				if(row_num == number_of_rose){
					items_in_this_row = items_in_last_row;
					// if the number of items in the last row is not congruent with the number of items in each of the other rows with regard to the modulus 2:
//					if ((items_per_row - items_in_this_row) % 2) {
//						html += "<td colspan=" + items_per_row + " align=center><table cellpadding=0 cellspacing=0 border=0><tr>";
//						lmth = "</table>";
//					} else {
						j=0; while (j++ < Math.floor((items_per_row - items_in_this_row) / 2))
							html += "<td>";
//					}
				}
				for (item = items_per_row * (row_num - 1), j=0; j<(row_num < number_of_rose ? items_in_this_row = items_per_row : items_in_this_row); j++, item++) {
					html += "<td";
					//this_cell.setAttribute ('class', 'menucell');
//					if (items_per_row > items_in_this_row)
//						html += ' align=center';
//					else j && (html += ' align=' + (j < items_in_this_row-1 ? 'center' : 'right'));
					html += " class=midiv><span class=mi>" + menuItems[id][item][1] + (menuItems[menuItems[id][item][0]] ? arowText : '') + '</span>';
				}
				html +=lmth+"</tr>";
				lmth='';
			}
			document.write('<div id="m' + id + 'x' + number_of_rose + 'clone" style="z-index: 2;position: absolute;display:none;top: 0px; left: 0px; white-space:nowrap" onmouseover="mover(\'' + id + '\')" onmouseout="mout(\'' + id + '\')"><img src="' + dds + 'umages/t.gif" style="height: 10px; width:1px" id=msp' + id + 'x' + number_of_rose + 'clone><img src="' + dds + 'umages/g85' + (level % 2 ? 2 : '') + '.png" style="height: 10px; width:1px" id=mneck' + id + 'x' + number_of_rose + 'clone><div class=menubody' + (level % 2 ? 2 : '') + '><table cellpadding=0 cellspacing=0 border=0>' + html + '</table></div></div>');
			if (items_per_row <= 1) break;
		}
	}
}




function examine (toExamine, dispName, tabs) { 
	var toReturn='';
	if (typeof tabs =='undefined') tabs ='';
	if (typeof toExamine == 'object' || typeof toExamine == 'function') {
		if (typeof toExamine.length == 'number'){ //array
			toReturn += tabs + dispName + "\n";
			for(var i =0; i< toExamine.length; ++i){
				toReturn += examine (toExamine[i], "[" + i + "]", tabs + '\t');
			}
		}
		else {
			toReturn += tabs + dispName + "\n";
			for(var i in toExamine) {
				toReturn += examine (toExamine[i], "['" + i + "']", tabs + '\t');
			}
		}
	}
	else {
		toReturn += tabs + dispName + "=" + toExamine + "\n";
	}
	return toReturn;
}




