
/**
 * Navigation roll-overs
 */
function navOver( name )
{
	var id		= "nav_" + name;
	$(id).src	= "/images/nav/" + name + "-over.gif";
	
	//	Close any current menu
	if( currentMenu ) hideSub();
}
function navOut( name )
{
	var id		= "nav_" + name;
	$(id).src	= "/images/nav/" + name + ".gif";
}
/**
 * Sub-Navigaion roll-overs
 */
function subNavOver( section, name )
{
	var id		= "subNav_" + name;
	$(id).src	= "/images/nav/sub/" + section + "/" + name + "-over.gif";
	
	//	Close any current menu
	if( currentMenu ) hideSub();
}
function subNavOut( section, name )
{
	var id		= "subNav_" + name;
	$(id).src	= "/images/nav/sub/" + section + "/" + name + ".gif";
}
/**
 * Navigation drop-downs
 */
var timeout				= 500;
var closeTimer			= null;
var currentMenu			= null;
var currentMenuName		= "";
var inCurrentMenu		= false;
var offsetLeft			= 0;
var offsetTop			= 0;
var isIE				= navigator.userAgent.toLowerCase().indexOf( 'msie' ) != -1
						|| navigator.appName.toLowerCase().indexOf( 'explorer' ) != -1;
var isIE7				= navigator.userAgent.toLowerCase().indexOf( 'msie 7' ) != -1;
var isSafari			= navigator.userAgent.toLowerCase().indexOf( 'safari' ) != -1;
var standardBody		= ( document.compatMode == "CSS1Compat" ) ? document.documentElement : document.body;

function showSub( name, inSection )
{
	//	Clear the timer
	clearTimer();
	
	//	Close the old menu
	if( currentMenu ) hideSub();
	
	//	Save this menu as the current menu
	currentMenu		= $('navSub_'+name);
	currentMenuName	= name;
	
	//	Save whether or not this is the current section of the site
	inCurrentMenu	= inSection;
	
	//	Show the rollover
	if( !inCurrentMenu )
		$("nav_" + currentMenuName).src	= "/images/nav/" + currentMenuName + "-over.gif";
	
	//	Show the sub-menu
	if( isIE )
	{
		offsetLeft		= getposOffset( $("nav_" + currentMenuName), "left" );
		//alert( "offsetLeft: " + offsetLeft );
		var moveLeft	= ( offsetLeft - getBrowserEdge( currentMenu, "right" ) + 4 ) + "px";
		//alert( "moveLeft: " + moveLeft );
		currentMenu.style.left	= moveLeft;
	}
	currentMenu.style.visibility		= "visible";
}
function hideSub()
{
	//	Hide the rollover
	if( currentMenuName != "" && !inCurrentMenu )
	{
		$("nav_" + currentMenuName).src	= "/images/nav/" + currentMenuName + ".gif";
		currentMenuName	= "";
	}
	
	//	Hide the menu
	if( currentMenu )
	{
		currentMenu.style.visibility	= "hidden";
		currentMenu						= null;
	}
}
function hideSubTimed()
{
	closeTimer	= window.setTimeout( hideSub, timeout );
}
function clearTimer()
{
	if( closeTimer )
	{
		window.clearTimeout( closeTimer );
		
		closeTimer	= null;
	}
}
function getposOffset( obj, offsetType )
{
	var totalOffset	= ( offsetType == "left" ) ? obj.offsetLeft : obj.offsetTop;
	var parentOff	= obj.offsetParent;
	
	while( !isSafari && parentOff != null )
	{
		totalOffset	= ( offsetType=="left" ) ? totalOffset + parentOff.offsetLeft : totalOffset + parentOff.offsetTop;
		parentOff	= parentOff.offsetParent;
	}
	
	return totalOffset;
}
function getBrowserEdge( obj, edgeType )
{
	var edgeOffset	= 0;
	
	if( edgeType == "right" )
	{
		var windowEdge	= ( document.all && !window.opera ) ? standardBody.scrollLeft + standardBody.clientWidth - 15 : window.pageXOffset + window.innerWidth - 15;
		
		currentMenu.contentmeasure	= currentMenu.offsetWidth;
		
		if( windowEdge - offsetLeft < currentMenu.contentmeasure )
			edgeOffset	= ddmenuitem.contentmeasure-obj.offsetWidth;
	}
	else
	{
		var topEdge		= ( document.all && !window.opera ) ? standardBody.scrollTop : window.pageYOffset;
		var windowEdge	= ( document.all && !window.opera ) ? standardBody.scrollTop + standardBody.clientHeight - 15 : window.pageYOffset + window.innerHeight - 18;
		
		currentMenu.contentmeasure	= currentMenu.offsetHeight;
		
		if( windowEdge - offsetTop < currentMenu.contentmeasure )
		{
			edgeOffset	= currentMenu.contentmeasure + obj.offsetHeight
			
			if( ( offsetTop - topEdge ) < currentMenu.contentmeasure )
				edgeOffset	= offsetTop + obj.offsetHeight - topEdge;
		}
	}
	
	return edgeOffset;
}



/**
 * Index image rotation
 */
var activeImage		= 'index_img_1';
var indexImgCount	= 10;
var indexImgCurr	= 1;

function rotate()
{
	indexImgCurr++;
	if( indexImgCurr > indexImgCount ) indexImgCurr = 1;
	
	transitionImage( activeImage, 'index_img_' + indexImgCurr );
	
	startRotation();
}
function startRotation()
{
	window.setTimeout( rotate, 4000 );
}
function transitionImage( oldImage,newImage )
{
	var fadeOut = function()
	{
		var div = $(oldImage).setStyles({ opacity: 1 });
	
		new Fx.Style(div, 'opacity', {duration: 700}).start(0);
		fadeIn();
	};  
	
	var fadeIn = function()
	{
		if( isIE7 )
		var div2 = $(newImage).setStyles({
			display: 'block',
			left: '-790px',
			opacity: 0
		});
		else
		var div2 = $(newImage).setStyles({
			display: 'block',
			opacity: 0
		});
		new Fx.Style(div2, 'opacity', {duration: 1200}).start(1);
	};
	
	if( newImage != activeImage )
	{
		fadeOut();
		activeImage = newImage;
	}
}