//
// $Archive: /WWW/SeamusCasey.com/inc/ads.js $
// $Modtime: 9/24/07 23:40 $
// $Revision: 3 $
// $NoKeywords: $
//

var ads = new Array( 'PickensPlan', 'TVOTA', 'Velmas', 'WrenchBlog', 'AutoRipper' );

var adIndex = 0; //Math.floor( ads.length * Math.random() );
var timerID = null;
var defaultTimeout = 3000;


// Each time this script is loaded, randomize the order of the ads.
ShuffleAds();

// Wait some time for the page to load before deciding what to show.
StartAdTimer( 500 );


function ShuffleAds()
{
	var Count = ads.length;
	
	for ( i = 0; i < Count; i++ )
	{
		var j = Math.floor( Count * Math.random() );
		var temp = ads[j];
		ads[j] = ads[i];
		ads[i] = temp;
	}
}


function ShowAd(ItemID)
{
	var Item = document.getElementById( ItemID );

	if ( Item )
	{
		Item.style.display = '';
	}
}

function HideAd(ItemID)
{
	var Item = document.getElementById( ItemID );
	
	if ( Item )
	{
		Item.style.display = 'none';
	}
}

function StartAdTimer(timeout)
{
	timerID = window.setTimeout( "SwitchAd()", timeout );
}

function StopAdTimer()
{
	if ( timerID != null )
	{
		clearTimeout( timerID );
		timerID = null;
	}
}

function SwitchAd()
{
	var i;
	
	for ( i = 0; i < ads.length; i++ )
	{
		if ( i == adIndex )
		{
			ShowAd( ads[i] );
		}
		else
		{
			HideAd( ads[i] );
		}
	}

	if ( adIndex < ( ads.length - 1 ) )
	{
		adIndex++;
	}
	else
	{
		adIndex = 0;
	}

	
	StartAdTimer( defaultTimeout );
}

