var adv_effects = new Array();

function adv_fadeOutAll()
{
	i = 1;
	while( document.getElementById('adv_img' + i) )
	{
		if(adv_effects[i] != null)
			adv_effects[i].cancel();
		
		adv_effects[i] = new Effect.Opacity('adv_img'+i, {duration:2.0, to:0});
		i++;
	}
}

function adv_fadeOut( id )
{
	if(adv_effects[id] != null)
		adv_effects[id].cancel();
		
	adv_effects[id] = new Effect.Opacity('adv_img'+id, {duration:0.5, to:0});
}

function adv_fadeIn( id )
{
	if(adv_effects[id] != null)
		adv_effects[id].cancel();
		
	adv_effects[id] = new Effect.Opacity('adv_img'+id, {duration:0.5, to:1});
}


//
// MAIN SPONSOR - DIASHOW
//

var adv_main_path = 'media/advertisement/main/';
var adv_main_images = new Array( 'sunconcept_01.png', 'sunconcept_02.png', 'sunconcept_03.png', 'sunconcept_04.png' );
var adv_main_index = 1;

function Show()
{
	// show current image 5s long then call Next()
	window.setTimeout( 'Next()', 5000 );
}

function Next()
{
	// fade current image out (in 2s) then call Switch()
	//emile( 'adv_main', 'opacity:0.0;', { duration: 2000, after: Switch } );
	new Effect.Opacity( 'adv_main', { from: 1.0, to: 0.0, duration: 2.0, afterFinish: Switch } );
}

function Switch()
{
	// get components
	var adv_main = document.getElementById( 'adv_main' );
	var adv_main_background = document.getElementById( 'adv_main_background' );
	
	// get next image index
	var i = ( adv_main_index + 1 ) % adv_main_images.length;
	
	// set take over background image (currently displayed) to actual image (restore opacity)
	adv_main.src = adv_main_path + adv_main_images[adv_main_index];
	//adv_main.style.opacity = 1.0;
	//adv_main.style.filter = "alpha(opacity='1')";
	$('adv_main').setOpacity(1.0);
	
	
	// set background image to next image in array
	adv_main_background.style.background = "url('" + adv_main_path + adv_main_images[i] + "')";
	
	// take over new image index
	adv_main_index = i;
	
	// call Show()
	Show();
}
