var s_fadeOpacity = new Array();
s_fadeOpacity[ "primary" ] = 9;
s_fadeOpacity[ "secondary" ] = 9;
var s_fadeTimer = null;
var s_fadeHtml = new Array();
var s_timers = new Array();
function writeFader( p_id, p_color, p_top, p_left, p_height, p_width, p_isOpaque, p_zIndex, p_context )
{
	p_context.write( "<div id='fader_" );
	p_context.write( p_id );
	p_context.write( "' style='position:absolute;z-index:" );
	p_context.write( p_zIndex );
	p_context.write( ";top:" );
	p_context.write( p_top );
	p_context.write( ";left:" );
	p_context.write( p_left );
	p_context.write( ";height:" );
	p_context.write( p_height );
	p_context.write( ";width:" );
	p_context.write( p_width );
	p_context.write( "'>" );
	for( var i = 0; i < 10; i++ )
	{
		writePng( "fader_" + p_id + "_" + i, "img/fader_" + p_color + "_" + i + ".png", p_height, p_width, "overflow:hidden;position:absolute;top:0;left:0;visibility:" + ( p_isOpaque && i == 9 ? "visible" : "hidden" ), p_context );
	}
	p_context.write( "</div>" );
}
function registerTimer( p_timer )
{
	s_timers.push( p_timer );
}
function cancelAll()
{
	for( var i = 0; i < s_timers.length; i++ )
	{
		var l_timer = s_timers.pop( i );
		clearTimeout( l_timer );
	}
	if( s_fadeTimer != null )
	{
		clearTimeout( s_fadeTimer );
		s_fadeTimer = null;
	}
}
function fadeOut( p_id )
{
	if( s_fadeOpacity[ p_id ] > -1 )
	{
		document.getElementById( "fader_" + p_id + "_" + s_fadeOpacity[ p_id ]).style.visiblity = "hidden";
	}
	s_fadeOpacity[ p_id ] += 2; // 2 instead of 1 to speed things up
	document.getElementById( "fader_" + p_id + "_" + s_fadeOpacity[ p_id ]).style.visibility = "visible";
	if( s_fadeOpacity[ p_id ] == 9 )
	{
		if( p_id != "secondary" )
		{
			document.getElementById( "secondary_wrapper" ).style.visibility = "hidden";
		}
		if( top.loader.init )
		{
			top.loader.init();
		}
		document.getElementById( p_id ).innerHTML = s_fadeHtml[ p_id ];
		s_fadeHtml[ p_id ] = null;
		fadeIn( p_id );
	}
	else
	{
		s_fadeTimer = setTimeout( "fadeOut('" + p_id + "')", 10 );
	}
}
function fadeIn( p_id )
{
	if( s_fadeOpacity[ p_id ] > -1 )
	{
		document.getElementById( "fader_" + p_id + "_" + s_fadeOpacity[ p_id ]).style.visibility = "hidden";
	}
	s_fadeOpacity[ p_id ] -= 2; // 2 instead of 1 to speed things up
	if( s_fadeOpacity[ p_id ] > -1 )
	{
		document.getElementById( "fader_" + p_id + "_" + s_fadeOpacity[ p_id ]).style.visibility = "visible";
		s_fadeTimer = setTimeout( "fadeIn('" + p_id + "')", 10 );
	}
	else
	{
		document.getElementById( "fader_" + p_id ).style.visibility = "hidden";
		if(( p_id == "primary" ) && top.loader.run )
		{
			top.loader.run();
		}
	}
}
function load( p_html, p_id )
{
	if( p_id == null )
	{
		p_id = "primary";
	}
	cancelAll();
	if( s_fadeOpacity[ p_id ] == 9 )
	{
		document.getElementById( p_id ).innerHTML = p_html;
		fadeIn( p_id );
	}
	else
	{
		s_fadeHtml[ p_id ] = p_html;
		fadeOut( p_id );
	}
}
// corrects a bug when you go back in IE
// to a page that uses the secondary fader
function checkLoader( p_loader )
{
	if( top.loader.getLoader && ( top.loader.getLoader() == p_loader ))
	{
		return true;
	}
	else
	{
		top.location.href = "index.html";
		return false;
	}
}
function resetSecondary( p_top, p_left, p_height, p_width, p_scrollable )
{
	for( var i = 0; i < 10; i++ )
	{
		var l_fadeLayer = document.getElementById( "fader_secondary_" + i );
		l_fadeLayer.style.height = p_height;
		l_fadeLayer.style.width = p_width;
	}

	var l_fader = document.getElementById( "fader_secondary" );
	l_fader.style.height = p_height;
	l_fader.style.width = p_width;
	
	var l_content = document.getElementById( "secondary" );
	l_content.innerHTML = "";
	l_content.style.height = p_height;
	l_content.style.width = p_width;
	l_content.style.overflow = ( p_scrollable ? "auto" : "hidden" );
	
	var l_wrapper = top.main.document.getElementById( "secondary_wrapper" );
	l_wrapper.style.top = p_top;
	l_wrapper.style.left = p_left;
	l_wrapper.style.height = p_height;
	l_wrapper.style.width = p_width;
	l_wrapper.style.visibility = "visible";
}