var IsIE = navigator.appVersion.indexOf("MSIE") >= 0;
var IsNS6up = navigator.userAgent.indexOf("Gecko")>=0;
var IsMac  = navigator.appVersion.indexOf("Mac")>=0;
var isNS4 = (document.layers) ? true: false;
var isDOM = (document.getElementById) ? true: false;
var IsIE4 = IsIE && !isDOM;
var iMenuSeq = 0;

function MS_Tree(id)
{
	this.id = id;
	this.items = new Array();
	this.depth = 0;
	this.addItem = function(aItem){this.items[this.items.length] = aItem;};
}

function MS_TreeItem(id)
{
	this.id = id;
	this.tree = null;
	this.subtree = null;
	this.makeSubtree =  function(aTree){this.subtree = aTree;};
}
function MS_Stack()
{
	this.items = new Array();
	this.length = function(){ return this.index;};
	this.index = 0;
	this.push = function(aItem){this.items[this.index] = aItem;this.index++;};
	this.pop = function(){ var aItem = this.items[this.index-1]; delete this.items[this.index-1] ; this.index--; return aItem;};
	this.toString =  function(){return  this.items.toString();};
}


function MS_Menu(id)
{
	this.id = (id)? id : ("MenuRoot" + iMenuSeq++); 
	this.bgColor = "#003366";
	this.bgColorOver = "#6699CC";

	this.topFontFamily = "Arial,sans-serif";
	this.topFontSize = "8pt";
	this.topFontColor = "white";
	this.topFontWeight = "bold";
	
	this.fontFamily = "Arial,sans-serif";
	this.fontSize = "8pt";
	this.fontColor = "white";
	this.fontColorOver = "white";
	this.borderWidth = "1px";
	this.borderColor = "#6699CC";
	this.itemWidth = 	"150px"; 
	this.itemHeight = 	"20px"; 	
	this.hasMoreHtml = "";
	this.htmlBetweenTopItems = "<br><br>";
	this.offsetLeft = "0px";
	this.offsetTop = "0px";	

	this.menuWidth = 	parseInt(this.borderWidth,10) * 2 + parseInt(this.itemWidth,10);

	this.BEGIN = MS_Menu_Begin;
	this.END = MS_Menu_End;
	this.POPUP = MS_Menu_Popup;
	this.MENUITEM = MS_Menu_Item;

//	this.m_Stack = new Array();
	this.m_Stack = new MS_Stack();

	this.depth = 0;
	this.treeRoot = new MS_Tree(id);
	this.currentTree = this.treeRoot;
	this.currentTreeItem = null;
	this.selectedMenu = null;
	this.selectedMenuItem = null;
	this.selectedLayerByDepth = null;
	this.RENDER = MS_Menu_Draw;
}

function MS_Menu_Begin()
{
	this.m_Stack.push (this.currentTree);	
	if(this.m_Stack.length() >this.depth) this.depth = this.m_Stack.length();
	if(this.currentTreeItem) {
		this.currentTree = this.currentTreeItem.subtree;

	}
}

function MS_Menu_End()
{	this.currentTree.topMenuObj = this;
	this.currentTree = this.m_Stack.pop();
}

function MS_Menu_Popup(id, url, target, offImage, onImage, selectedImage)
{	
	this.currentTreeItem = new MS_TreeItem(id);
	this.currentTreeItem.url = url;
	this.currentTreeItem.target = target;

	this.currentTreeItem.offImage = offImage;
	if(!onImage)  onImage =  offImage; this.currentTreeItem.onImage = onImage;
	if(!selectedImage) selectedImage = onImage; this.currentTreeItem.selectedImage =  selectedImage;

	this.currentTreeItem.subtree = new MS_Tree(id);
	this.currentTreeItem.subtree.depth =  this.m_Stack.length();
	this.currentTreeItem.tree = this.currentTree;
	this.currentTree.addItem(this.currentTreeItem);

}

function MS_Menu_Item(id, url, target, offImage, onImage, selectedImage)
{
	this.currentTreeItem = new MS_TreeItem(id);
	this.currentTreeItem.url = url;
	this.currentTreeItem.target = target;

	this.currentTreeItem.offImage = offImage;
	if(!onImage)  onImage =  offImage; this.currentTreeItem.onImage = onImage;
	if(!selectedImage) selectedImage = onImage; this.currentTreeItem.selectedImage =  selectedImage;

	this.currentTreeItem.tree = this.currentTree;
	this.currentTree.addItem(this.currentTreeItem);
}


if(isNS4){
	document.write("<scri" + "pt language=javascript src=/MS_Menu_NS4.js></scr" + "ipt>");
}else if(isDOM){
	document.write("<scri" + "pt language=javascript src=/MS_Menu_DOM.js></scr" + "ipt>");
}else if(IsIE4){
	document.write("<scri" + "pt language=javascript src=/MS_Menu_IE4.js></scr" + "ipt>");
}
