var image_number = 1;
var fade_image;
var background_fade_timer = 0;
var background_fade_counter;
var current_attraction = '';

function start_background()
{
	window.setInterval( 'load_next_image()', 5000 );
}

function load_next_image()
{
	fade_image = document.getElementById( 'background_image_fade' );
	fade_image.style.visibility = 'hidden';

	image_number++;

	if ( image_number > 6 )
	{
		image_number = 1;
	}

	fade_image.onload = start_fade;
	fade_image.src = 'images/background' + image_number + '.jpg';
}

function start_fade()
{
	if ( background_fade_timer == 0 )
	{
		background_fade_counter = 0;
		background_fade_timer = window.setInterval( 'on_fade_timer()', 20 );
	}
}

function on_fade_timer()
{
	background_fade_counter += 2;

	set_opacity( fade_image, background_fade_counter );

	if ( background_fade_counter >= 100 )
	{
		window.clearInterval( background_fade_timer );
		background_fade_timer = 0;

		document.getElementById( 'background_image' ).src = fade_image.src;
	}
}

function set_opacity( opacity_object, opacity_percent )
{
	opacity_object.style.opacity = opacity_percent / 100;
	
	if ( opacity_percent == 100 )
	{
		opacity_object.style.filter = '';
	}
	else
	{
		opacity_object.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + String( opacity_percent ) + ')';
	}

	if ( opacity_percent == 0 )
	{
		opacity_object.style.visibility = 'hidden';
	}
	else
	{
		opacity_object.style.visibility = 'visible';
	}
}

function goto_attraction( attraction_id )
{
	if ( window.location.href.indexOf( 'attractions.php' ) == -1 )
	{
		document.getElementById( 'selected_attraction' ).value = attraction_id;
		document.getElementById( 'attraction_form' ).submit();
	}
	else
	{
		if ( current_attraction != '' )
		{
			document.getElementById( 'link_' + current_attraction ).className = 'attraction';
			document.getElementById( 'footer_' + current_attraction ).className = '';
			document.getElementById( 'attraction_' + current_attraction ).className = 'attraction_left';
		}

		current_attraction = attraction_id;

		document.getElementById( 'link_' + current_attraction ).className = 'attraction selected';
		document.getElementById( 'footer_' + current_attraction ).className = 'selected';
		document.getElementById( 'attraction_' + current_attraction ).className = 'attraction_left selected';
	}
}


