var scriptName;

var IE4 = (document.all && !document.getElementById) ? true : false;
var N4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false; 

if(IE4){
	scriptName=menuPath+"code/ie4.js";
}
if(IE5){
	scriptName=menuPath+"code/ie5.js";
}
if(N6){
	scriptName=menuPath+"code/n6.js";
}
if(N4){
	scriptName=menuPath+"code/n4.js";
}

var childrenArray = new Array(menuArray.length);
var timer;
var menuElement;

function makeMenus(){
setStyle();
for (var i=0; i<menuArray.length; i++){
    menuElement = new MenuElement(menuArray[i][0], menuArray[i][1], menuArray[i][2], menuArray[i][3], menuArray[i][4]);
    childrenArray[menuArray[i][0]] = menuArray[i][3];
	createHTML(menuElement);
	}
}

function setStyle(){
setMenuLeft();
writeStyleSheet();  
}

function MenuElement(name, text, link, children, image){
    this.name = name;
    this.text = text;
    this.link = link;
    this.children = children;
    this.image = image;
    this.isTopMenu=isTopMenu;
    this.isTopMenuChild=isTopMenuChild;
    this.hasChildren=hasChildren;
    this.isImage=isImage;
    this.getInitialVisibility=getInitialVisibility;
    this.getLeftPosition=getLeftPosition;
    this.getTopMenuWidth=getTopMenuWidth;
    this.getMenuWidth=getMenuWidth;
    this.getMenuName=getMenuName;
    this.isFirstMenu=isFirstMenu;
    this.getStyleWidth=getStyleWidth;
    this.getTopStyleWidth=getTopStyleWidth;
    this.getBorderStyle=getBorderStyle;
    this.isFirstChildTopMenu=isFirstChildTopMenu;
    this.isChild1OfChild1TopMenu=isChild1OfChild1TopMenu;
}

function getMenuName(){
	//work out name of menu it belongs to...
	var menuName="";
	if (!this.isTopMenu()){
		menuName = this.name.substring(0, this.name.length-(this.name.length-2));
	}
	else{
		menuName=this.name;
	}
return menuName;
}

function getNumberOfChildren(name){
	return childrenArray[name];
}

function isTopMenu(){
	return (this.name.length==2);
}

function isTopMenuChild(){
	var parent="";
	if (!this.isTopMenu()){
		parent=getParentName(this.name);
		}
return (parent.length==2);
}

function hasChildren(){
	return (menuElement.children>0);
}

function isImage(){
	return (menuElement.image==1);
}

function getParentName(name){
	if (name.length==2){
		parentName = null;
	}
	else{
		var nameArray = name.split("x");
		var childLength = nameArray[nameArray.length-1].length;
		parentName = name.substring(0,name.length-(childLength+1));
	}
return parentName;
}

function getTopStyleWidth(){
var width;
	for (var i=0;i<widthArray.length;i++){
		if (widthArray[i][0]==this.getMenuName()){
			width = widthArray[i][1];
			break;
		}
	}
return width;		
}

function getStyleWidth(){
var width;
	for (var i=0;i<widthArray.length;i++){
		if (widthArray[i][0]==this.getMenuName()){
			width = widthArray[i][2];
			break;
		}
	}
return width;		
}

function isFirstChildTopMenu(){
return ((this.name.length==4)&&(this.name.charAt(this.name.length-1)==1))
}

function isChild1OfChild1TopMenu(){
var parent = getParentName(this.name);
return ((parent.length==4)&&(parent.charAt(parent.length-1)==1)&&(this.name.charAt(this.name.length-1)==1));
}

function getTopMenuWidth(){
	var width;
	for (var i=0;i<widthArray.length;i++){
		if (widthArray[i][0]==this.getMenuName()){
			width = widthArray[i][1];
		}
	}		
	return width;
}


function getMenuWidth(){
	var width;
	if(this.isTopMenu()){
		width=this.getTopMenuWidth();
	}
	else{
	for (var i=0;i<widthArray.length;i++){
		if (widthArray[i][0]==this.getMenuName()){
			width = widthArray[i][2];
			break;
		}
	}
	}
return width;
}

function isFirstMenu(){
	return(this.getMenuName()=="m1");
}

function delayHide(name){
	if (name.length>2){
		changeBackground(name,menuBGcolor);
		changeFontColor(name,menuFontColor);
	}
	timer = eval("setTimeout(\"hideItems('"+name+"')\","+delay+")");
	//set timer 1
	//b4 set timer for 2, activate action of first timer then set timer 2
}
