All pastes #346173 Raw Edit

Jstr

public text v1 · immutable
·published 2007-02-09 03:24 UTC
rendered paste body
var menus = [], Menu_Open = null;

function Menu_Init()
{
	var arr = getElementsByClassName("menu").concat( getElementsByClassName("last_menu") );
	var i, len = arr.length;
	
	for (i = 0; i < len; i++)
	{
		menus[menus.length] =
			new Menu( arr[i] , getElementsByClassName("sub_menus", arr[i])[0] , getElementsByClassName("sub_menu", arr[i]) , i );
	}
}

function Menu(node, menu, options, indice)
{
	var i, len = options.length, w = 0;
	
	this._intvCheck = null;
	this._overMenu = false;
	this._overSub = false;
	this._nodeInfo = getNodeInfo(node);
	this._clickSub = false;
	
	this.node = node;
	this.menu = menu;
	this.options = options;
	this.indice = indice;
	
	this.showMenu = Menu_ShowMenu;
	this.hideMenu = Menu_HideMenu;
	
	this.node.onmouseover = Menu_MouseOver;
	this.node.onmouseout = Menu_MouseOut;
	this.node.onclick = Menu_MouseClick;
	
	this.menu.style.position = "absolute";
	this.menu.style.visibility = "hidden";
	this.menu.style.display = "block";

	for (i = 0; i < len; i++)
	{
		if (options[i].offsetWidth > w)
			w = options[i].offsetWidth;
		
		if (w < this.node.offsetWidth)
			options[i].style.width = this.node.offsetWidth +"px";
		
		options[i].onmouseover = Menu_MouseOverSub;
		options[i].onmouseout = Menu_MouseOutSub;
		options[i].onclick = Menu_MouseClickSub;
	}

	if (this.menu.offsetWidth < this.node.offsetWidth)
	{
		if (w <= this.node.offsetWidth)
			this.menu.style.width = this.node.offsetWidth +"px";
		else
			this.menu.style.width = w +"px";
	}
}

function Menu_MouseOver()
{
	var menu = Menu_FromElement(this);
	
	menu._overMenu = true;

	if (Menu_Open == menu)
		return;

	this.style.backgroundColor = "#A7B9CC";

	if (menu.options.length > 0)
		menu.showMenu();
	else if (Menu_Open)
		Menu_Open.hideMenu(1);
}

function Menu_MouseOut()
{
	var menu = Menu_FromElement(this);
	menu._overMenu = false;

	if (!menu._overSub && Menu_Open != menu)
		this.style.backgroundColor = "transparent";
}

function Menu_MouseClick()
{
	if (this.className != "menu")
		return;
	
	var menu = Menu_FromElement(this);
	if (menu._clickSub)
		return;

	var href = this.getElementsByTagName("a")[0].getAttribute("href");
	if (href) location.href = href;
	
	return(false);
}

function Menu_MouseOverSub()
{
	this.style.backgroundColor = "#A7B9CC";
	this.getElementsByTagName("a")[0].style.color = "#FFFFFF";
}

function Menu_MouseOutSub()
{
	this.style.backgroundColor = "transparent";
	this.getElementsByTagName("a")[0].style.color = "#003366";
}

function Menu_MouseClickSub()
{
	if (this.className != "sub_menu")
		return;
	
	var node = this;
	while ( (IE) ? node.parentElement : node.parentNode )
	{
		node = (IE) ? node.parentElement : node.parentNode;
		if (node.className == "menu" || node.className == "last_menu")
			break;
	}
	var menu = Menu_FromElement(node);
	menu._clickSub = true;
	
	var href = this.getElementsByTagName("a")[0].getAttribute("href");
	if (href) location.href = href;
	
	return(false);
}

function Menu_ShowMenu()
{
	if (Menu_Open)
		Menu_Open.hideMenu(1);
		
	if (this._intvCheck)
	{
		clearInterval(this._intvCheck);
		this._intvCheck = null;
	}
	
	this.menu.style.left = "0px"; //this._nodeInfo.x +"px";
	this.menu.style.top = this._nodeInfo.h +"px";
	this.menu.style.visibility = "visible";
	this._intvCheck = setInterval("menus["+ this.indice +"].hideMenu()", 2000);

	Menu_Open = this;
}

function Menu_HideMenu(bNoCheck)
{
	if ( bNoCheck || ( !this._overMenu && !this._overSub ) )
	{
		if (Menu_Open == this) Menu_Open = null;

		this.node.onmouseout();
		this.menu.style.visibility = "hidden";

		if (this._intvCheck)
		{
			clearInterval(this._intvCheck);
			this._intvCheck = null;
		}
	}
}

function Menu_FromElement(element)
{
	var i, len = menus.length;
	
	for (i = 0; i < len; i++)
		if (menus[i].node == element)
			return( menus[i] );
	
	return(false);
}

function getNodeInfo(node)
{
	var xPos = 0, yPos = 0, width = 0, height = 0, srcNode = node;
	while ( (IE) ? node : (typeof node.tagName != "undefined") )
	{
		if (node.tagName != "TR")
		{
			xPos += node.offsetLeft;
			yPos += node.offsetTop;
		}
		node = (IE) ? node.parentElement : node.parentNode;
	}
	if (typeof srcNode.offsetWidth != "undefined")
	{
		width = srcNode.offsetWidth;
		height = srcNode.offsetHeight;
	} else if (typeof srcNode.width != "undefined") {
		width = srcNode.width;
		height = srcNode.height;
	}
	return(
		{ x : xPos , y : yPos , w : width , h : height }
	);
}

function getElementsByClassName(className, node, limit, buffer)
{
	var children = null, returnArr = [], i;
	
	var buff = (buffer) ? buffer : 0;
	
	if (node == undefined) node = document.body;
	else if (typeof node != "object") return([]);
	else if (node.className == className)
	{
		returnArr[returnArr.length] = node;
		++buff;
	}
	
	if (buff >= limit) return(returnArr);
	
	children = (node.children) ? node.children : node.childNodes;
	for (i = 0; i < children.length; i++)
	{
		returnArr = returnArr.concat(
				getElementsByClassName( className, children[i], limit, buff )
		);
	}
	
	return(returnArr);
}

----------------------------JS IS ABOVE------------------------------------------------------------------------------

	function get_current_options()
	{
		// loops through the menus and returns the options
		// associated with the current file
		
		global $menus, $content_file;
		
		$file = $content_file .".php";
		
		$len = count($menus);
		for ($i = 0; $i < $len; $i++)
		{
			if ($menus[$i]["url"] != $file)
			{
				$option_len = count($menus[$i]["options"]);
				for ($x = 0; $x < $option_len; $x++)
					if ($menus[$i]["options"][$x]["url"] == $file)
						return( $menus[$i]["options"] );
			} else
				return( $menus[$i]["options"] );
		}
		
		return(null);
	}

	// declare menu variables
	$menus = array(
		array( "name" => "Home" , "url" => "index.php" ) ,
		array( "name" => "Services" , "url" => "services.php" ) ,
		array(
		       "name" => "Portfolio" ,
		       "url" => "portfolio.php" ,
		       "options" => array(
				array( "name" => "Desktop Publishing" , "url" => "desktop.php" ) ,
				array( "name" => "Graphic Design" , "url" => "grfx.php" ) ,
				array( "name" => "Web Design" , "url" => "webdev.php" ) 
			)
		) ,
		array( "name" => "F.A.Q" , "url" => "faq.php" ) ,
                array( "name" => "Customer Care" , "url" => "customer_care.php" ) ,
                array( "name" => "Contact Us" , "url" => "contact.php" ) ,
		array( "name" => "Live Support" , "url" => "#" )
	);

?>