/*
 * The following code sections/functions are generalized and can be reused.
 *
 *	Version 1.0
 */
/*
 * Script original author: ricocheting.com
 *
 * Description: Modified from the original source
 */
function getOpaciaty( element ) {
	/*
	 * returns the image's opacity value setting
	 */
	var style = element.style;
	var x = 0;

	if ( style.MozOpacity != undefined ) { //Moz and older
		return ( style.MozOpacity );
	} else if ( style.filter != undefined ) { //IE
		x = element.filters.alpha.opacity / 100;
		return ( x );
	} else if ( style.opacity != undefined ) { //Opera
		return ( style.opacity );
	}
} /* End of getOpacity() */

function setOpacity( element, alpha ) {
	/*
	 * alpha is a value between 0 and 1; 0 is 100% transparent
	 */
	var style = element.style;

	if ( style.MozOpacity != undefined ) { //Moz and older
		style.MozOpacity = alpha;
	} else if ( style.filter != undefined ) { //IE
		style.filter = "alpha(opacity=0)";
		element.filters.alpha.opacity = ( alpha * 100 );
	} else if ( style.opacity != undefined ) { //Opera
		style.opacity = alpha;
	}
} /* End of setOpacity() */

function fade( ) {
	/*
	 * Fade out the current image element held by _imgx by 5 steps in 0.5 second
	 * _fading_step is a global
	 */
	if ( _fading_step <= 0 ) {
		window.clearTimeout( _fading_timer ); _fading_timer = 0;
		return;
	}
	x = _fading_step * 0.2; _fading_step--;
	setOpacity( _imgx, x );
	window.setTimeout( "fade()", 100 );

} /* End of fade() */

function forward_slide ( action ) {
	/*
	 * To use this function, there shall be an <img /> tag with the ID 'slide'.
	 */
	_imgx = document.getElementById("slide");	/* get the current slide being displayed */

	if ( action == _stop ) {
		window.clearTimeout( _timer );		_timer = 0;
		window.clearTimeout( _fading_timer );	_fading_timer = 0;
		setOpacity( _imgx , 1.0 );		/* reset the opacity */
		return;
	}

	if ( ++slideIndex >= _slides.length ) {
		/* _slides: global, keeping the slide source and other slide properties */
		slideIndex = 0;
	}

	_imgx.src = _preload_img[ slideIndex ].src;
	_imgx.width = _slides[ slideIndex ][1];
	_imgx.height = _slides[ slideIndex ][2];
	if ( _slides[ 0 ].length >= 4 ) {
		document.getElementById("pic_note").innerHTML = _slides[ slideIndex ][3];
	}

	setOpacity( _imgx , 1.0 );	/* Make sure it's 100% opacity */
	/*
	 * Schedule timer to fade the slide
	 */
	_fading_step = 4;					/* counting down to ZERO */
	_fading_timer = window.setTimeout( "fade()", 4500);
	/*
	 * Timer to forward to the next time--5 seconds later.
	 */
	_timer = window.setTimeout("forward_slide( !_stop )", 5000);
	return;
} /* forward_slide () */
