$(document).ready( function() 
{
	if ( !document.getElementById || !document.createTextNode )  // test to see if user agent supports modern dom
		return; 


	// fix display of PNG images and background images on IE5.5 and IE6	
	if ( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )
	{
            $.ifixpng( '/FileData/IMACSWeb/images/transparentpixel.gif' );
            $( 'img[src$=.png], #top, #bottom, #dl-top, #dl-bottom, #spotlight-top' ).ifixpng( 'crop' );
            $( '#program-finder' ).ifixpng( 'scale' );
	}

	// slideshow
	$('#slideshow').innerfade({
		speed: 1750, // speed of transition
		timeout: 7000, // time to view each slide
		type: 'sequence',
		containerheight: '110px'});

	// give IDs to each <a> 
	var atags = $( "#subnav a" );
	for ( var i = 0 ; i < atags.length ; i++ )
		atags.eq( i ).attr( "id", "a" + i );
		
	$( '#subnav ul .opener' ).click( 
		function () 
		{ 
			var next = $(this).next( 'ul' );
			if ( next.attr( 'class' ) == null || next.attr( 'class' ).indexOf( 'opened' ) < 0 )
			{
				next.addClass( "opened" );
				OpenMe( $(this) );
			}
			else
			{
				next.removeClass( "opened" );
				CloseMe( $(this) );
			}

			return false;
		}
	);
	
	$( '#subnav ul a' ).click( 
		function()
		{
			if ( $(this).attr( 'class' ) != null && $(this).attr( 'class' ).indexOf( 'opener' ) >= 0 )
				return; // don't round-trip on a opener link
		
			var uls = $('#subnav ul.opened');
			
			var toopen = "";
			for ( var i = 0 ; i < uls.length ; i++ )
			{
				if ( uls.eq( i ).attr( "id" ) != null )
					toopen += uls.eq( i ).attr( "id" ) + (i < (uls.length - 1) ? "," : "");
			}
			
			var href = $(this).attr( 'href' );
			href += (href.indexOf( "?" ) >= 0 ? "&" : "?") 
						+ "navname=" + ThisNavName()
						+ "&toopen=" + toopen
						+ "&scrolly=" + getScrollY() 
						+ "&subnavid=" + $(this).attr( "id" );
			
			$(this).attr( 'href', href );

			return true;
		}
	);

	var currentfound = false;
	
	var q = window.location.search.substring( 1 ); // query string after question mark
	if ( q != null && q != "" )
	{
		var params = q.split( "&" );
		var navname = null;
		
		for ( var i = 0 ; i < params.length ; i++ )
		{	
			if ( params[ i ].match( /(.*)=(.*)/g ) )
			{
				var paramname = RegExp.$1,
					paramvalue = RegExp.$2;
					
				switch ( paramname )
				{
					case "toopen":
						if ( navname == ThisNavName() )
						{
							var a = paramvalue.split( "," );
							for ( var j = 0 ; j < a.length ; j++ )
							{
								if ( a[ j ] && a[ j ] != "" )
								{
									var id = "#" + a[ j ];
									$( id ).addClass( "opened" );
									OpenMe( $( "#" + a[ j ] ).prev( "a" ) );
								}
							}
						}
						break;
						
					case "scrolly":
						window.scrollTo( 0, parseInt( paramvalue ) );
						break;
						
					case "navname":
						navname = paramvalue;
						break;
						
					case "subnavid":
						if ( navname == null || navname == ThisNavName() )
						{
							$("#subnav #" + paramvalue).addClass( "current" );
							currentfound = true;
						}
						break;
				}
			}
		}
		
	}
	
	if ( !currentfound )
	{
		// try to find subnav item to highlight based on file name
		var tagtofind = window.location.pathname.match( /([A-Za-z_]+\.htm)/gi );
		for ( var i = 0 ; i < atags.length ; i++ )
		{
			var thisatag = atags.eq( i );
			if ( thisatag.attr( "href" ) == tagtofind )
			{
				// highlight and open up as necessary 
				thisatag.addClass( "current" );
				
				// does this need to open up it's parents?
				var thisatagul = atags.eq( i ).parents( "ul" );
				thisatagul.addClass( "opened" );
				
				if ( thisatagul.prev( "a" ).length > 0 )
					OpenMe( thisatagul.prev( "a" ) );
				break;		
			}
		}
	}


	setTimeout( 'DoJumpTo()', 500 );
});


function OpenMe( thing )
{
	for ( var i = 0 ; i < thing.length ; i++ )
	{
		var thisthing = thing.eq( i );
		
		if ( thisthing.attr( "class" ).indexOf( "level1" ) > -1 )
		{
			thisthing.removeClass( "level1" );
			thisthing.addClass( "level1open" );
		}
		else
		{
			thisthing.removeClass( "level2" );
			thisthing.addClass( "level2open" );
		}
	}
}

function CloseMe( thing )
{
	if ( thing.attr( "class" ).indexOf( "level1" ) > -1 )
	{
		thing.addClass( "level1" );
		thing.removeClass( "level1open" );
	}
	else
	{
		thing.addClass( "level2" );
		thing.removeClass( "level2open" );
	}
}

function ThisNavName()
{
	return $("#subnav #navname").text();
}

// readmore
function readMore( id )
{
	var div = $("#" + id + " .extra");
	if ( div.css('display') == 'none' ) 
	{
		div.css('display','block').fadeIn();
	}
	else 
	{
		div.css('display','none').fadeOut();
	}
}

function getScrollY()
{
    var y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        y = window.pageYOffset;
    } else if( document.body && document.body.scrollTop ) {
        // DOM
        y = document.body.scrollTop;
    } else if( document.documentElement && document.documentElement.scrollTop ) {
        // IE6 standards compliant mode
        y = document.documentElement.scrollTop;
    }
    return y;
}
