// ***********************************************************************
//   Script for controlling first page feature item
// ***********************************************************************
// this array consists of the id attributes of the divs we wish to alternate between
var divs_to_fade = new Array( 'pcg_feature_item_0', 'pcg_feature_item_1', 'pcg_feature_item_2', 'pcg_feature_item_3', 'pcg_feature_item_4' );

// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var feature_index = 0;

// the number of milliseconds between swaps.  Default is five seconds.
var feature_wait = 5000;

// the interval, so we can access it later
var feature_interval = null;

// only keep on fading when this is not true
var is_paused = false;

// the function that performs the fade
function swapFade() {
	// Silly IE hack because it is stupid, oh so stupid
	if( feature_index == -1 ) feature_index = 0;

	if( !is_paused )
	{
		Effect.Fade(divs_to_fade[feature_index], { duration:1, from:1.0, to:0.0 });
		document.getElementById( 'pcg_feature_controls_number' + (feature_index+1) ).className = "pcg_feature_controls_inactive";
		feature_index++;
		if (feature_index == 5) feature_index = 0;
		document.getElementById( 'pcg_feature_controls_number' + (feature_index+1) ).className = "pcg_feature_controls_active";
		Effect.Appear(divs_to_fade[feature_index], { duration:1, from:0.0, to:1.0 });
	}
}

// the function that handles clicks
function swapFadeToItem( item ) {
	// Silly IE hack because it is stupid, oh so stupid
	if( feature_index == -1 ) feature_index = 0;
	
	clearInterval( feature_interval );	
	if( item != feature_index )
	{
		document.getElementById( 'pcg_feature_controls_number' + (feature_index+1) ).className = "pcg_feature_controls_inactive";
		document.getElementById( 'pcg_feature_controls_number' + (item+1) ).className = "pcg_feature_controls_active";
		Effect.Fade(divs_to_fade[feature_index], { duration:1, from:1.0, to:0.0 });
		Effect.Appear(divs_to_fade[item], { duration:1, from:0.0, to:1.0 });
	}
	feature_index = Number( item );
}

function swapFadeUp() {
	// Silly IE hack because it is stupid, oh so stupid
	if( feature_index == -1 ) feature_index = 0;
	
	if( feature_index == 0 )
		j = 4;
	else
		j = feature_index - 1;
	swapFadeToItem( j );
}
function swapFadeDown() {
	// Silly IE hack because it is stupid, oh so stupid
	if( feature_index == -1 ) feature_index = 0;
	
	if( feature_index == 4 )
		j = 0;
	else 
		j = feature_index + 1;
	swapFadeToItem( j );
}
function pauseFade() {
	is_paused = true;
}
function resumeFade() {
	is_paused = false;
}

// the onload event handler that starts the fading.
function startPage() {
	setTimeout( "feature_interval = setInterval('swapFade()',feature_wait)", feature_wait );
}

// ***********************************************************************
// ***********************************************************************
// ***********************************************************************