// JavaScript Document

//DOM is ready so initialize script
function windowLoaded()
{
	addDropDowns();	
	preLoader(imgArray);
}
//Navigation IDs
var navArray = ["ourFirm", "services", "clientLogIn", "links", "contact"];
//Mouseover images
var bulletOn = "/images/bullet_over.gif";
var bulletOff = "/images/bullet.gif";

var imgHolder = new Image();
var imgArray = [bulletOn];



function preLoader(srcArray)
{
	for(i = 0; i < srcArray.length; i++)
	{
		imgHolder.src = srcArray[i];
	}
}


//Add mouseover functions to show drop down menus
function addDropDowns()
{
	for(i = 0; i < navArray.length; i++)
	{
		var currentListItem = document.getElementById(navArray[i]); //The list item with a drop down menu
		var topLink = currentListItem.getElementsByTagName("a")[0]; // The top anchor tag in the list item has the mouseover script
		var currentMenu = document.getElementById(navArray[i] + "Drop"); //The drop down menu to be shown
		//If there is a drop down menu then add the mouseovers
		if(currentMenu)
		{
			topLink.onmouseover = showDropDown;
			currentMenu.onmouseover = mcancelclosetime;
			currentMenu.onmouseout = mclosetime;
			topLink.onmouseout = mclosetime;
		}
		else topLink.onmouseover = mclose; //every other link will close the menu immediately	
	}
}

function showDropDown()
{
	var thisMenu = this.parentNode.id + "Drop"; 
	thisBullet = this.getElementsByTagName("img")[0]; 
	mopen(thisMenu, thisBullet);
}



// Copyright 2006-2007 javascript-array.com
//Modified by Nick Inhofe 2009

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;
var bullet = false;



// open hidden layer

function mopen(id, thisBullet)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	mclose();
	bullet = thisBullet;


	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'block';
	bullet.src = bulletOn;

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.display = 'none';
	if (bullet) bullet.src = bulletOff;
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


function isMember(element, classname) 
{
	var classes = element.className;  // Get the list of classes
	if (!classes) return false;             // No classes defined
	if (classes == classname) return true;  // Exact match

	// We didn't match exactly, so if there is no whitespace, then 
	// this element is not a member of the class
	var whitespace = /\s+/;
	if (!whitespace.test(classes)) return false;

	// If we get here, the element is a member of more than one class and
	// we've got to check them individually.
	var c = classes.split(whitespace);  // Split with whitespace delimiter
	for(var i = 0; i < c.length; i++) { // Loop through classes
		if (c[i] == classname) return true;  // and check for matches
	}

	return false;  // None of the classes matched
}




