function showAd(adNum)
{    		
	var adURL = (adNum == 1) ? "ad1.html" : "ad2.html";
	loadAd(adURL);
	
	// show the ad container
	var fade = new Fx.Tween( $('adSpace') );
	fade.start('opacity', '0', '1');
	
	$('adSpace').style.visibility = 'visible';
	
	// start visual countdown
	var secondsRemaining = 16;
	
	// set the initial value of the countdown
	$('adSpace-header-secondsRemaining').innerHTML = 15;
	
	// update the countdown every second
	var updateAdCounter = function()
	{
		$('adSpace-header-secondsRemaining').innerHTML = (secondsRemaining <= 15) ? secondsRemaining : 15;
	
		if( secondsRemaining == 0 ){
			$clear( updateAdCounter );
			adComplete();	
		}
		
		secondsRemaining--;
	
	}.periodical( 1000 );
	
	return true;	
}
    	
function hideAd()
{
  	var fade = new Fx.Tween( $('adSpace') );
	fade.start('opacity', '1', '0');
	
	var hideAdContainer = function()
	{
		$('adSpace').style.visibility = 'hidden';
	  	$('adSpace').style.opacity = 0;
    	$clear(hideAdContainer);
    	$('mySWF').adComplete();
    	unloadAd();
	}.periodical( 2000 );
}

function loadAd(src)
{
	$('theAd').src = src;// + "?" + new Date().getTime();
}

function unloadAd()
{
	$('theAd').src = 'blank.html';
}

function adComplete()
{
	hideAd();
}
