/*
Blue Shift Inc Website Javascript

Behavior scripts for for BSI navigation elements

Copyright Max Johnson 2007
*/

// global nav timer vars //
var timerOn = false;
var timerId = null;
var timerList = new Array();


function dump( message)
{
	if( document.getElementById('dump') )
	{
		document.getElementById('dump').innerHTML += message;
		document.getElementById('dump').style.display = "block";
	}
}

function display( message )
{
	if( document.getElementById('Gray_Top') )
	{
		document.getElementById('Gray_Top').innerHTML = message;	
	}
}

function showHideElement( id, state )
{
	if( obj = document.getElementById(id) )
	{
		if( state == "show" )
		{
			obj.style.visibility = "visible";
		}
		else
		{
			obj.style.visibility = "hidden";
		}
	}
}

function showHideSubNav( navId, state )
{
		// define nav elements //
		parentID = navId.replace("_SubNav", ""); // if this is a subnav, we get the id of the parent nav by removing "_SubNav" from the navId
		oNav = document.getElementById( parentID ); // use parent id to get parent element
		oSubNav = null; // define subNav element
		
		// find if current element is subNav or not
		if ( navId.match("_SubNav") )
		{
			oSubNav = document.getElementById(navId);
		}
		else
		{
			if( document.getElementById( navId+"_SubNav" ) ) // if the current element has a subNav attached
			{
				oSubNav = document.getElementById( navId + "_SubNav" ); // set sub nav element
			}
		}
		
		// hide all subnavs that are not the one we want to show //
		var arrLen = gSubNavArr.length;
		for( e=0; e < arrLen; ++e )
		{
			// if current nav has sub-nav, hide all others immediatly, otherwise fade out //
			if( oSubNav )
			{
				if( oSubNav.id != gSubNavArr[e].id )
				{
					currentOpac( gSubNavArr[e].id, 0, 0);
				}
			}
			else
			{
				currentOpac( gSubNavArr[e].id, 0, 500);
			}
		
		}
		
		if( oSubNav )
		{
			// show or hide current nav, depending on passed variable //
			if( state == "show" )
			{
				currentOpac( oSubNav.id, 100, 200);
			}
			else
			{
				currentOpac( oSubNav.id, 0, 500);
			}
		}
}

function BSINavOver()
{
	// test for mouseout timer and see if this element has subnavigation //
	thisId = this.id;
	SubNavTest = thisId.match( "_SubNav" );
	
	// rollover if not SubNav
	if( !SubNavTest && document.images )
	{
		document.getElementById( thisId + "_Circle" ).src = gRootDir + "images/circle-over.png";
	}
	
	// if SubNavTest is true, set oSubNav to object, else try to find subnav //
	oSubNav = ( SubNavTest != null )? this : document.getElementById( thisId + "_SubNav" );
	
	if ( timerOn && oSubNav )
	{
		// cancel timer operation //										
		clearTimeout(timerId);
		
		timerId = null; 
		timerOn = false; 
	}
	
	// fade in SubNav
	showHideSubNav( thisId, "show" );
}

function BSINavOut()
{
	// test for mouseout timer and see if this element has subnavigation //
	thisId = this.id;
	SubNavTest = thisId.match( "_SubNav" );
	
	if( !SubNavTest )
	{
		document.getElementById( thisId + "_Circle" ).src = gRootDir + "images/circle.png";
	}
	
	// if SubNavTest is true, set oSubNav to object, else try to find subnav //
	oSubNav = ( SubNavTest != null )? this : document.getElementById( thisId + "_SubNav" );
	
	if ( oSubNav ) {
		//dump( oSubNav + ", ");
		timerOn = true; // set timer flag
		timerId = setTimeout( ("showHideSubNav( \"" + thisId + "\", \"hide\" )") , 1000); // delay hiding the subnav for 1 sec
	}
	else
	{
		showHideSubNav( thisId, "hide" );
	}
}


function BSISubNavOver()
{
	this.style.listStyleType = "disc";
	this.style.color = "#3e45ba";
}

function BSISubNavOut()
{
	this.style.listStyleType = "circle";
	this.style.color = "#999";
}