// Begin custom code

// Prepare Timer Array
var actionTimer= new Array(1);
var menulistARR= new Array(1);

// Set check user Input timer
var checkIt;
var menuTimer;

// Close All Timer
var closeouttimer= 5000;

// Menu Delay
var menudelay= 50;

// Make sure checkDivs has fired
var checkD= "0";

// Miserable friggin browsers
var macMode= 0;

// Try firing checkdivs onload
checkdivs();

function checkdivs()
	{
	// Grab All Divs
	var divSRC= getelementcount("div");

	// Do we even have Divs?
	if (divSRC.length == 0)
		{
		// Nope
		return;
		}

	// Precounters
	var j=0;
	var prevgroupnumberINT= -1;
	var premenulistARR= new Array(1);
	var menulistSTR;

	// Start the loop
	for(i=0;i<divSRC.length;i++)
		{
		// Do we have a custom att?
		if (divSRC[i].getAttribute("type"))
			{
			// It's got a type so let's run it
			if (divSRC[i].getAttribute("type") == "menu")
				{
				premenulistARR[j] = divSRC[i].getAttribute("group")+"|"+divSRC[i].id;

				// Make sure we have a status attribute
				divSRC[i].setAttribute("status", "closed");

				// Give each Menu a unique numerical id
				divSRC[i].setAttribute("order", j);


				j= j+1;
				}

			// Also, Flash checking code can go here, too
			}
		}

	// Process Menu Div List
	// Split Arrays into individual strings
	// Merge into one parent Array
	j=0;

	for(i=0;i<premenulistARR.length;i++)
		{
		menulistSTR= premenulistARR[i].substr(premenulistARR[i].indexOf("|")+1)+",";

		prevgroupnumberINT= parseInt(premenulistARR[i].substr(0,premenulistARR[i].indexOf("|")));

		menulistARR[prevgroupnumberINT]= menulistSTR+menulistARR[prevgroupnumberINT];
		}

	checkD= "true";

	if (checkPlat('mac'))
		{
		macMode= 1;
		if (checkPlat('msie'))
			{
			macMode= 2;
			}
		}
	}

// Gets Browser Info
function checkPlat(string)
{
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


// Find Y Position
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


// Get Div counts
function getelementcount(myelement)
	{
	var elementcount = document.getElementsByTagName(myelement);
	return elementcount;
	}

// Activates/Deactivates events for a trigger
function switchtrigger(myElement,status,action)
	{
	var tempSTR= "";
	var holdSTR= myElement;
	myElement= document.getElementById(holdSTR);


	// BUG
	if (!(myElement))
		{
		return;
		}

	// Are we switching on?
// 3W specific
	if (status != "off")
		{
		// Yep
// 3W specific
		if (myElement.mystatus)
			{
			myElement.onmouseout= new Function("changebutton(this,'0','"+myElement.mystatus+"','yes');");
			}else{
			myElement.onmouseout= new Function("changebutton(this,'0','off','yes');");
			}
		if (action)
			{
			tempSTR= myElement.getAttribute("onClick");
			}else{
			tempSTR= "DoMenu('"+myElement.getAttribute("target")+"','Y');"
			}

		// 3W specific
		//tempSTR= "changebutton(this,'0','on','yes'); "+tempSTR;
		tempSTR= "changebutton(this,'0','over','yes'); "+tempSTR;
		myElement.onmouseover= new Function(tempSTR);
		}else{
		// Nope
		myElement.onmouseout= new Function("checkUserInput();");
		myElement.onmouseover= new Function("checkUserInput();");
		}
	}

// Changes rollover image
function changebutton(myElement,myElementID,status,dosiblings)
	{
	// Do we have the object?
	if ((!(myElement)) || (myElement == 0))
		{
		// Nope
		myElement= document.getElementById(myElementID);
		}

	//Swapping an image?
	if (myElement.src)
		{
		// Yep
		var mySRC= myElement.src;
		}else{
		// Not an image
		var mySRC= myElement.className;
		}

	// Are we specifically telling it off/on?
	if (status)
		{
		// Yep
		mySRC= mySRC.replace("_off","_"+status);
		mySRC= mySRC.replace("_on","_"+status);
		// 3W specific
		mySRC= mySRC.replace("_over","_"+status);
		}else{
		// Nope
		if ((mySRC.indexOf("_off")) > 0)
			{
				mySRC= mySRC.replace("_off","_on");
			}
			else
			{
				mySRC= mySRC.replace("_on","_off");
			}
		}


	// MAC exception
	if (macMode < 2)
		{
		// Last time: Swapping an image?
		if (myElement.src)
			{
			// Yep
			myElement.src= mySRC;
			}else{
			// Not an image
			myElement.className= mySRC;
			}

		// Siblings
		if (dosiblings)
			{
			parentElement= myElement.parentNode;
			childNodes= parentElement.childNodes;
			for(z=0;z<childNodes.length;z++)
				{
				if ((childNodes[z].tagName == "TD") || (childNodes[z].tagName == "IMG"))
					{
					changebutton(childNodes[z],'0',status);
					}
				}
			}else{

			// Keep me alive
			checkUserInput();
			}
		}else{
		// Lousy, friggin Hack because of Stupid MAC IE
		if (myElementID == "x")
			{
			if (myElement.src)
				{
				// Yep
				myElement.src= mySRC;
				}else{
				// Not an image
				myElement.className= mySRC;
				}
			}
		}
	}
	
// Changes rollover image -- 3w specific
function changebuttonDrop(myElement,myElementID,status,dosiblings)
	{
	// Do we have the object?
	if ((!(myElement)) || (myElement == 0))
		{
		// Nope
		myElement= document.getElementById(myElementID);
		}

	//Swapping an image?
	if (myElement.src)
		{
		// Yep
		var mySRC= myElement.src;
		}else{
		// Not an image
		var mySRC= myElement.className;
		}

	// MAC exception
	if (macMode < 2)
		{
		// Last time: Swapping an image?
		if (myElement.src)
			{
			// Yep
			myElement.src= mySRC;
			}else{
			// Not an image
			myElement.className= mySRC;
			}

		// Siblings
		if (dosiblings)
			{
			parentElement= myElement.parentNode;
			childNodes= parentElement.childNodes;
			for(z=0;z<childNodes.length;z++)
				{
				if ((childNodes[z].tagName == "TD") || (childNodes[z].tagName == "IMG"))
					{
					changebutton(childNodes[z],'0',status);
					}
				}
			}else{

			// Keep me alive
			checkUserInput();
			}
		}else{
		// Lousy, friggin Hack because of Stupid MAC IE
		if (myElementID == "x")
			{
			if (myElement.src)
				{
				// Yep
				myElement.src= mySRC;
				}else{
				// Not an image
				myElement.className= mySRC;
				}
			}
		}
	}


// Debugging Functions
function writebugs(mymessage)
	{
	txtbox= document.getElementById("TXTjscript");
	txtbox.value= txtbox.value+"\n"+mymessage;
	}

function checklen()
	{
	txtbox= document.getElementById("TXTjscript");
	txtARR= txtbox.value.split("\n");
	if (txtARR.length >= 200)
		{
		return 1;
		}else{
		return 0;
		}
	}



// Triggers the menu timer
function checkUserInput()
	{
	if (checkIt)
		{
		clearTimeout(checkIt);
		}

	if (menuTimer)
		{
		clearTimeout(menuTimer);
		}

	checkIt = setTimeout('closeAll()',closeouttimer);
	}


// Kills all menus
function closeAll()
	{
	// Cycle through our overall list of menus
	for(i=1;i<=menulistARR.length;i++)
		{
		if (menulistARR[i])
			{
			closegroup(i,"0");
			}
		}

	if (checkIt)
		{
		clearTimeout(checkIt);
		}
	}


// DoMenu
function DoMenu(menuID,killgroup)
	{
	if (menuTimer)
		{
		clearTimeout(menuTimer);
		}
	tempSTR= "setMenu('"+menuID+"','"+killgroup+"')";
	menuTimer = setTimeout(tempSTR,menudelay);
	}


// Begins Menu opening process
function setMenu(menuID,killgroup)
	{
	if (menuTimer)
		{
		clearTimeout(menuTimer);
		}

	// Grab our menu
	var targetDIV= document.getElementById(menuID);

	// BUG
	// -- Something is generating a NULL menuID
	if (!(targetDIV))
		{
		return;
		}
	// End Bug

	var direction= targetDIV.getAttribute("direction");
	var interval= targetDIV.getAttribute("speed");
	var max= targetDIV.getAttribute("maxsize");
	var min= targetDIV.getAttribute("minsize");
	var order= targetDIV.getAttribute("order");
	var status= targetDIV.getAttribute("status");
	var trigger= targetDIV.getAttribute("trigger");
	var group= targetDIV.getAttribute("group");

	// Whether it's open or not, we're passing it to slideDIV

	// Are we killing all in group?
	if (killgroup == "Y")
		{
		// Yep, so is our target open?
		if (status == "closed")
			{
			// Nope, commence with group closure
			closegroup(group,menuID);
			}
		}

	// Ok, now work our menu
	slideDIV(trigger,menuID,direction,interval,max,min,order);

	// MAC exception
	if (macMode < 1)
		{
		// Make sure we're doing user Input
		checkUserInput();
		}
	}


// Close group for non menus
function closegroupPUB(groupID)
	{
	closegroup(groupID,"0");
	}


// Closes all menus within a group
function closegroup(groupID,srcID,srcType)
	{
	if (!(menulistARR[groupID]))
		{
		return;
		}

	// First, grab all menus in our group
	groupARR= menulistARR[groupID].split(",")

	// Now, begin cycling through
	for(i=0;i<=groupARR.length;i++)
		{
		// It's not our DIV, is it?
		if (groupARR[i] != srcID)
			{
			// Nope, so Does it exist?
			var myDiv= document.getElementById(groupARR[i]);
			if (myDiv)
				{
				// Yep, so is it open?
				if (myDiv.getAttribute("status") == "open")
					{
					if (myDiv.getAttribute("trigger") != "")
						{
						// Yep, so close it
						setMenu(groupARR[i],"N");

						// Turn off its trigger
						if (macMode < 2)
							{
							// 3W specific
							mytarget= document.getElementById(myDiv.getAttribute("trigger"));
							if (mytarget.mystatus)
								{
								changebutton('0',myDiv.getAttribute("trigger"),mytarget.mystatus,'yes');
								}else{
														changebutton('0',myDiv.getAttribute("trigger"),'off','yes');
								}
							}
						}
					}
				}
			}
		}
	}

// Begins DIV size changing process
function slideDIV(source,target,direction,interval,max,min,order,afterfunction)
	{
// Need a way to determine control id
//	var controlID= source.id.substringing(0,source.id.indexOf("IMG"));

	var myDiv= document.getElementById(target);
	interval= parseInt(interval);
	max= parseInt(max);
	min= parseInt(min);

	if (direction == "across")
		{
		var targetsize= parseInt(myDiv.style.width);
		}else{
		var targetsize= parseInt(myDiv.style.height);
		}

	if (targetsize > min)
		{
		var action= "reduce";

		if (macMode < 2)
			{
			switchtrigger(source,"on");
			}
		divstatus= "hide";
		}else{
		var action= "enlarge";

		if (macMode < 2)
			{
			switchtrigger(source,"off");
			}

		divstatus= "show";
		}

	// MAC exception
	if (macMode < 2)
		{
		window.clearInterval(actionTimer[order]);
		if (macMode == 1)
			{
			//afterfunction += "||LOCALhidedivsSAF(\""+divstatus+"\");"
			}
		var myfunc= "resizeElement('"+target+"','"+direction+"','"+action+"','"+interval+"','"+max+"','"+min+"','"+order+"');"
		actionTimer[order] = window.setInterval(myfunc, 1);
		}else{
		//afterfunction += "||LOCALhidedivsIE(\""+divstatus+"\");"
		resizeElement(target,direction,action,max,max,min,order);
		}
	}


// Actually does the resizing
function resizeElement(target,direction,action,interval,max,min,mytimer,afterfunction)
	{
	var myDiv= document.getElementById(target);
	interval= parseInt(interval);
	max= parseInt(max);
	min= parseInt(min);
	var stopfunc= 0;
	myDiv.style.overflow= "hidden";
	var afterfunctionTimer= new Array(1);

	if (direction == "across")
		{
		var targetsize= parseInt(myDiv.style.width);
		}else{
		var targetsize= parseInt(myDiv.style.height);
		}

	if (action == "enlarge")
		{
		myDiv.setAttribute("status","open");
		}

	if (action == "reduce")
		{
		myDiv.setAttribute("status","closed");
		}

	if ((action == "reduce") && ((targetsize-interval <= min) || (interval == max)))
		{
			if (direction == "across")
				{
				myDiv.style.width= min;
				}else{
				myDiv.style.height= min;
				}
			window.clearInterval(actionTimer[mytimer]);
			stopfunc= 1;
			if (afterfunction)
				{
				afterfunction += "||";

				afterfunctionARR= afterfunction.split("||");
				for(y=0;y<afterfunctionARR.length-1;y++)
					{
					if (afterfunctionARR[y] != "")
						{
						afterfunctionTimer[y] = setTimeout(afterfunctionARR[y],0);
						}
					}
				}
		}

	if ((action == "enlarge") && ((targetsize+interval >= max) || (interval == max)))
		{
			if (direction == "across")
				{
				myDiv.style.width= max;
				}else{
				myDiv.style.height= max;
				}
			window.clearInterval(actionTimer[mytimer]);
			stopfunc= 1;

			myDiv.style.overflow= "visible";
			if (afterfunction)
				{
				afterfunction += "||";

				afterfunctionARR= afterfunction.split("||");
				for(y=0;y<afterfunctionARR.length-1;y++)
					{
					if (afterfunctionARR[y] != "")
						{
						afterfunctionTimer[y] = setTimeout(afterfunctionARR[y],0);
						}
					}
				}
		}

	if (stopfunc == 0)
		{
		if (action == "enlarge")
			{
			if (direction == "across")
				{
				myDiv.style.width= targetsize+interval;
				}else{
				myDiv.style.height= targetsize+interval;
				}
			}

		if (action == "reduce")
			{
			if (direction == "across")
				{
				myDiv.style.width= targetsize-interval;
				}else{
				myDiv.style.height= targetsize-interval;
				}
			}
		}
	}


// Jump to another page
function pagejump(myURL)
	{
		window.location= myURL;
	}


// Opens New Windows
function opennewwindow(url,height,width,type,windowname)
	{

	height= parseInt(height)+100;
	width= parseInt(width)+100;

	if (type)
		{
		if (type == "movie")
			{
			if (url.indexOf(".mov") > 1)
				{
				var _params = "width="+width+",height="+height+",resizable=no,status=no,scrollbars=no,top=244,left=426";
				}
			}
		}

	var _params = "width="+width+",height="+height+",margin-top=0,margin-left=0,resizable=no,status=no,scrollbars=no,top=244,left=426";

	if (!(windowname))
		{
		windowname= "media";
		}

	newWindow= window.open(url, windowname, _params);

	if (url.indexOf(".mov") > 1)
		{
		newWindow.document.write("<html><head><\/head><body topmargin=\"0\" leftmargin=\"0\" background="+url+"><\/body><\/html>");
		}
	}


// Resizes the current window
function resizeWindow(width, height)
	{
	window.resizeTo(width, height);
	}