/*
	© 2004-2005 Imaginaré, LLC.  All rights reserved.  
	Imaginaré Photography & Videography and Imaginarephotovideo.com are trademarks of Imaginaré, LLC.
*/

function MenuItem(displayText, hoverText, uid, url, isRoot){
	this.displayText_ = (displayText == null) ? "" : trim(displayText);
	this.hoverText_ = (hoverText == null) ? "" : trim(hoverText);

	this.uid_ = (uid == null) ? "" : trim(uid);

	this.url_ = (url == null) ? "" : trim(url);

	this.isRoot_ = (isRoot) ? true : false;

	this.parent_ = null;
	this.children_ = null;
}

function MenuItem_isRoot(){ return this.isRoot_; }
function MenuItem_getDisplayText(){ return this.displayText_; }
function MenuItem_getHoverText(){ return this.hoverText_; }
function MenuItem_getURL(){ return this.url_; }
function MenuItem_getUID(){ return this.uid_; }

function MenuItem_getParent(){ return (this.parent_ == null || this.isRoot()) ? null : this.parent_; }
function MenuItem_setParent(parent){ this.parent_ = parent; }

function MenuItem_hasChildren(){ return (this.children_ == null || this.children_.length <= 0) ? false : true; }
function MenuItem_getChildren(){ return (this.hasChildren()) ? this.children_ : null; }
function MenuItem_addChild(child){
	if(child == null) return;
	if(this.children_ == null) this.children_ = new Array();
	child.setParent(this);
	this.children_[this.children_.length] = child;
}

//public static
function MenuItem_getDivName(id){ return MenuItem.DIV_PREFIX+id; }

//public
function MenuItem_getDivCode(left, top){
	var display = (this.isRoot()) ? "" : "none";
	var rootFeatures = (this.isRoot()) ? "text-align: center; " : "padding-left: 5px; padding-right: 5px; ";
	var divId = MenuItem.getDivName(this.getUID());
	var url = (this.getURL() == null || this.getURL() == "") ? null : "'"+this.getURL();
	if(url != null){
		if(url.indexOf("http") != 1){
			if(url.indexOf(".php?") < 0){ url += "?pageId="+this.getUID()+"'"; }
			else { url += "&pageId="+this.getUID()+"'"; }
		}
		else{
			url += "'";
		}
	}
	
	var divStart =	"<div "+
			"id='"+divId+"' "+
			"class='"+MenuItem.CLASS+"' "+
			"style='"+
				"width: "+MenuItem.WIDTH+" px; "+
				"height: "+MenuItem.HEIGHT+" px; "+
				"left: "+left+" px; "+
				"top: "+top+" px; "+
				"background-color: "+MenuItem.BACKGROUND_COLOR+"; "+
				"color: "+MenuItem.FOREGROUND_COLOR+"; "+
				"display: "+display+"; "+
				rootFeatures +
			"' "+
			"onMouseOver=\"Menu.showColor('"+divId+"'); navMenu.hideExceptForMyPath('"+this.getUID()+"')\" "+
			"onMouseOut=\"Menu.hideColor('"+divId+"')\" "+
			"onClick=\"navMenu.navigate("+url+")\" "+
			"title=\""+this.getHoverText()+"\" "+
			">";

	var divContent = this.getDisplayText();

	var divEnd = "</div>";

	return divStart + divContent + divEnd;
}

function Menu_hideColor(id){
	var element = document.getElementById(id);
	if(element != null){
		element.style.backgroundColor = MenuItem.BACKGROUND_COLOR;
		element.style.color = MenuItem.FOREGROUND_COLOR;
	}
}

//static
function Menu_showColor(id){
}

//public
function Menuitem_getAllDivIdsToShowForSelf(){
	var siblings = this.getSiblingDivIds();
	var parents = this.getAllParentDivIds();
	var children = this.getChildrenDivIds();

	siblings = unionArrays(siblings, parents);
	siblings = unionArrays(siblings, children);
	return siblings;
}

//private
//includes self
function Menuitem_getSiblingDivIds(){
	if(this.isRoot()) return new Array();

	var siblilngItems = this.getParent().getChildren();

	var siblings = new Array();
	for(var i=0; i<siblilngItems.length; i++){
		siblings[siblings.length] = MenuItem.getDivName(siblilngItems[i].getUID());
	}

	return siblings;
}

//private
function Menuitem_getChildrenDivIds(){
	if(!this.hasChildren()) return new Array();

	var childrenItems = this.getChildren();

	var children = new Array();
	for(var i=0; i<childrenItems.length; i++){
		children[children.length] = MenuItem.getDivName(childrenItems[i].getUID());
	}

	return children;
}

//private
function Menuitem_getAllParentDivIds(){
	if(this.isRoot() || this.getParent().isRoot()) return new Array();
	return MenuItem.getAboveLevel(this);
}

//private static
function MenuItem_getAboveLevel(item){
	if(item == null || item.isRoot()) return new Array();
	var parent = item.getParent();
	var parentSiblings = parent.getSiblingDivIds();
	parentSiblings = unionArrays(parentSiblings, parent.getAllParentDivIds(parent));
	return parentSiblings;
}

function MenuItem_getAllDivIdsForThisBranch(){
	var ids = new Array(MenuItem.getDivName(this.getUID()));
	if(this.hasChildren()){
		for(var i=0; i<this.getChildren().length; i++){
			ids = unionArrays(ids, this.getChildren()[i].getAllDivIdsForThisBranch());
		}
	}
	return ids;
}

function MenuItem_getLevel(){
	var i=0;
	element = this;
	while(!element.isRoot()){
		i++;
		element = element.getParent();
	}
	return i;
}

//==================================================================================


new MenuItem(null, null, null, null, false);


MenuItem.DIV_PREFIX = "nav_";
MenuItem.CLASS = "floatElement";
MenuItem.WIDTH = "120";
MenuItem.HEIGHT = "17";
MenuItem.BACKGROUND_COLOR = "#444444";
MenuItem.FOREGROUND_COLOR = "#ffffff";
MenuItem.HIGHLIGHT_BACKGROUND_COLOR = "#87C0FA";
MenuItem.HIGHLIGHT_FOREGROUND_COLOR = "#000000";


MenuItem.getAboveLevel = MenuItem_getAboveLevel;
MenuItem.getDivName = MenuItem_getDivName;


MenuItem.prototype.isRoot = MenuItem_isRoot;
MenuItem.prototype.getDisplayText = MenuItem_getDisplayText;
MenuItem.prototype.getHoverText = MenuItem_getHoverText;
MenuItem.prototype.getURL = MenuItem_getURL;
MenuItem.prototype.getUID = MenuItem_getUID;
MenuItem.prototype.getParent = MenuItem_getParent;
MenuItem.prototype.setParent = MenuItem_setParent;
MenuItem.prototype.hasChildren = MenuItem_hasChildren;
MenuItem.prototype.getChildren = MenuItem_getChildren;
MenuItem.prototype.addChild = MenuItem_addChild;
MenuItem.prototype.getDivCode = MenuItem_getDivCode;
MenuItem.prototype.getAllDivIdsToShowForSelf = Menuitem_getAllDivIdsToShowForSelf;
MenuItem.prototype.getSiblingDivIds = Menuitem_getSiblingDivIds;
MenuItem.prototype.getChildrenDivIds = Menuitem_getChildrenDivIds;
MenuItem.prototype.getAllParentDivIds = Menuitem_getAllParentDivIds;
MenuItem.prototype.getAllDivIdsForThisBranch = MenuItem_getAllDivIdsForThisBranch;
MenuItem.prototype.getLevel = MenuItem_getLevel;
