/*!======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.0.1
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2010 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/


vB_XHTML_Ready.subscribe(function() { load_cms_overlay(); });

var config_overlay
function load_cms_overlay()
{
	config_overlay = new vB_Overlay();
}

function cms_show_overlay(url)
{
	if (config_overlay == undefined)
	{
		config_overlay = new vB_Overlay();
	}
	config_overlay.show_ajax(url, '', this, true );

	return false;
}

//This is for the tree menus
function initVbTreeMenus(notInteractive) {
	var SHOW_ALL_TREE_ELEMENTS_THRESHOLD = window.vbGlobal_SHOW_ALL_TREE_ELEMENTS_THRESHOLD ? window.vbGlobal_SHOW_ALL_TREE_ELEMENTS_THRESHOLD : 10;//TODO: this probably should live in a config somewhere
	var vbTrees = YAHOO.util.Dom.getElementsByClassName("vb-tree-menu","div");
	for (var treeCount = 0; treeElement=vbTrees[treeCount]; treeCount++) {
		var activeLeaf = null;
		if (!treeElement._vbTreeAlreadyProcessed) {
			/* start: this must execute before instantiating TreeView from treeElement */
			var activeTreeNodeId = -1;
			var treeItems = treeElement.getElementsByTagName("li");
			for (var itemcount = 0; (activeTreeNodeId == -1) && (treeItem = treeItems[itemcount]); itemcount++) {
				if (treeItem.className && (YAHOO.util.Dom.hasClass(treeItem,"active"))) {
					activeLeaf = treeItem;
					activeTreeNodeId = itemcount + 1;
				}
			}
			/* end: end must execute before instantiating TreeView from treeElement */
			if (!notInteractive) {
				var tree = new YAHOO.widget.TreeView(treeElement);
				tree.subscribe("clickEvent",function(props){
					if (props && props.node && props.node.href) {
						location.href = props.node.href;
					}
				});
				tree.render();
				var nc = tree.getNodeCount();
				if (nc <= SHOW_ALL_TREE_ELEMENTS_THRESHOLD) {
					tree.expandAll();
				}
				if (activeTreeNodeId != -1) {
					var activeTreeNode = tree.getNodeByIndex(activeTreeNodeId);
					var p = activeTreeNode;
					while (p = p.parent) p.expand();
					activeTreeNode.focus();
					activeTreeNode.highlight();
					activeTreeNode.expand();
					YAHOO.util.Dom.addClass(activeTreeNode.getEl(),"activeVBMenuItem");
					//activeTreeNode.getEl().className += "activeVBMenuItem";
				}//if active tree node was found, expand parents and children and highlight it
			}//interactive/YUI vs Static/CSS
		    else {
		    	var headerLabel = "Site";

				var labelElement = YAHOO.util.Dom.getElementsByClassName("echo_section","span",document.body);
				labelElement = labelElement[0]?labelElement[0]:null;

		    	if (labelElement && activeLeaf) {
		    		//note: i *abhor* using .innerHTML
		    		var activeSectionLabel = activeLeaf.getElementsByTagName("a")[0].innerHTML;
		    		var parentSection = activeLeaf.parentNode.parentNode;
		    		var parentSectionLabel = 'Site';
		    		if (parentSection && (parentSection.tagName.toLowerCase() == "li")) {
		    			var parentSectionLabel = parentSection.getElementsByTagName("a")[0].innerHTML;
		    		}
		    		var headerLabel = parentSectionLabel + " &gt; " + activeSectionLabel;
		    	}//if activeLeaf exists, adorn the header with relevant info


		    	if (labelElement) {
					labelElement.innerHTML = headerLabel;
				}

				vBPrepTreeBranch(treeElement.getElementsByTagName("ul")[0],0,activeLeaf);
			}//render static navigation
			treeElement._vbTreeAlreadyProcessed = {};
		}//ensure this tree wasn't already processed -- ensures this function can be called multiple times without breaking things.
	}//loop thru vb-tree-menu elements, and render them using YAHOO.widget.TreeView
}//initVbTreeMenus

function vBPrepTreeBranch(branch,pLevelCounter,pActiveLeaf) {
	var isTreeRoot = false;
	YAHOO.util.Dom.addClass(branch,"level_" + pLevelCounter);
	if (pActiveLeaf && (pActiveLeaf.parentNode == branch)) {
		YAHOO.util.Dom.addClass(branch,"active_branch");
	}
	if (pLevelCounter > 0) YAHOO.util.Dom.addClass(branch, "not_root");
	else isTreeRoot = true;
	var leaves = YAHOO.util.Dom.getChildren(branch);
	for (var leafCounter = 0; leaf = leaves[leafCounter]; leafCounter++) {
		if (leaf.tagName && leaf.tagName.toLowerCase() == "li") {
			if ((!pActiveLeaf && isTreeRoot) || (pActiveLeaf && (pActiveLeaf.parentNode == branch)))  {
				YAHOO.util.Dom.addClass(leaf,"sibling_active");
			} else if (branch.parentNode == pActiveLeaf) {
				YAHOO.util.Dom.addClass(leaf,"direct_child_active");
			}
			YAHOO.util.Dom.addClass(leaf,"level_" + pLevelCounter);
			if (pLevelCounter > 0) YAHOO.util.Dom.addClass(leaf, "not_root");

			var childBranch = leaf.getElementsByTagName("ul");
			childBranch = childBranch[0]?childBranch[0]:null;
			if (childBranch) {
				vBPrepTreeBranch(childBranch,(pLevelCounter + 1),pActiveLeaf);
			}//recurse

		}//make sure it's an <li>
		else {
			alert("Why would you put an <" + leaf.tagName + "> tag inside of a <" + leaf.parentNode.tagName + "> tag?");
			alert(leaf.parentNode.tagName.innerHTML);
		}
	}//loop thru <li> leaves
}//vBPrepTreeBranch

/*======================================================================*\
|| ####################################################################
|| # NulleD By - FintMax
|| # CVS: $RCSfile$ - $Revision: 25662 $
|| ####################################################################
\*======================================================================*/