
var a_images_slideshow = new Array()
var a_images = new Array()
var image_opacity = 1
var last_call
var slideshow_continue = true
var last_cycle_call
var global_image_index = 0
var global_bg_target
var global_image_target
var fadeIn = 1
var fadeOut = 0

if (navigator.appName.indexOf("Microsoft")!=-1) 
{ 
	var browser = 'IE'
}
else 
{ 
	var browser = 'MZ' 
}





function set_opacity(object,opacity)
{
	if (object.filters)
	{
		object.filters.alpha.opacity = opacity
	}
	else if (object.style.MozOpacity)
	{
		object.style.MozOpacity = opacity/100
	}
	else if (object.style.opacity)
	{
		object.style.opacity = opacity/100
	}
	else if (object.style.Opacity)
	{
		object.style.Opacity = opacity/100
	}
	else if (object.style.KhtmlOpacity)
	{
		object.style.KhtmlOpacity = opacity/100
	
	}
	
}

function fade_in()
{
	
	set_opacity(global_image_target,image_opacity)
	
	if (fadeIn != 1)
	{
		setTimeout( "fade_in()", 70 )
	}
	else if ( image_opacity < 100 )
	{
		
		image_opacity = image_opacity + 3
		last_call = setTimeout( "fade_in()", 70 )
	}
	else
	{
		setTimeout( "global_bg_target.src = global_image_target.src", 100 )

		image_opacity =  100
		fadeIn = 0;
		fadeOut = 1
		
	}
	
}

function fade_out()
{
	set_opacity(global_image_target,image_opacity)
	
	if (fadeOut != 1)
	{
		setTimeout( "fade_out()", 50 )
	
	}
	else if ( image_opacity > 25 )
	{
		
		image_opacity = image_opacity - 3
		
		last_call = setTimeout( "fade_out()", 50 )
	}
	else
	{
		image_opacity = 25	
		fadeIn = 1
		fadeOut = 0
		global_image_target.src = a_images_slideshow[global_image_index]
		fade_in()
	}
	
}

function extinguish()
{
	image_opacity = 1
	fadeIn = 1

	if ( last_call != '' )
	{
		clearTimeout( last_call )
	}

	if ( browser == 'IE' )
	{
		global_image_target.filters.alpha.opacity = 1
	}
	else
	{
		global_image_target.style.MozOpacity= 1/100
	}

}

function clear_last_call()
{
	if ( last_call != '' )
	{
		clearTimeout( last_call )
	}
}

function pause_slideshow( pause_button_image )
{
	if ( slideshow_continue )
	{
		slideshow_continue = false

		if ( last_cycle_call != '' )
		{
			clearTimeout( last_cycle_call )
		}
		document.getElementById('lnkPause').innerHTML = 'play';
	}
	else
	{
		document.getElementById('lnkPause').innerHTML = 'pause';
		slideshow_continue = true
		cyle_thru_images()
	}	
}

function image_next()
{
	
	if ( image_opacity > 0 && image_opacity < 100 )
	{
		
		setTimeout( "image_next()", 500 )
	}
	else
	{
		global_image_index++


		if ( global_image_index >= a_images_slideshow.length )
		{
			global_image_index = 0	
		}
		
		clear_last_call();
		//fade_out()
		extinguish();
		setTimeout( "global_image_target.src = a_images_slideshow[global_image_index];global_image_target.alt = a_images[global_image_index].alt;global_image_target.title = a_images[global_image_index].title", 50 );
		setTimeout( "fade_in()", 100 );
	}

}

function cyle_thru_images()
{
	
	image_next();


	if ( slideshow_continue )
	{
		last_cycle_call = setTimeout( "cyle_thru_images()", 5*1000 ); 
	}	
}

function start_slideshow()
{

	global_bg_target = document.getElementById("image_bg");

	global_image_target = document.getElementById("image_fg");
	
	extinguish();
	global_image_target.src = a_images_slideshow[global_image_index];
	fade_in();

	if ( a_images_slideshow.length > 1 )
	{
		setTimeout( "cyle_thru_images()", 4*1000 );
	}

}
