// START WIDGET JS
function clicker(num,stopper) {
	if (num > $('tot').value) { num = 1; } // loop back to first image if last image ID reached in automated animation
	var old = parseInt($('cur').value); // grab currently displayed image
	if (num != old) { // if new image ID is not the same as currently displayed ID
		new Effect.Opacity("page"+num, {duration:.25,from:0,to:0.999999}); // fadeIn new image
		if ($('link'+num).value != 'window.open("","","");' && $('link'+num).value != 'window.location=""') {
			$('banCont1').setAttribute('onclick',$('link'+num).value); // reset page link to location of current link
		} else {
			$('banCont1').setAttribute('onclick',''); // reset page link to location of current link
		}
		if ($('title'+num).value != '') {
			$('banCont1').setAttribute('title',$('title'+num).value); // reset page title to location of current link
		} else {
			$('banCont1').setAttribute('title',''); // reset page title to location of current link
		}
		$('cur').value = num; // reset current image ID to new ID
	}
	if (stopper == undefined) { // continue automatic loop if stopper variable was not passed by user
		fadeOut = setTimeout('autoTrans()',speed); // loop back to fadeOut current image and start loop over
	} else { // if user triggered stopper with click
		// clear all timeouts and timeout variables to stop automation
		clearTimeout(fadeOut);
		clearTimeout(fadeIn);
		fadeOut = 0;
		fadeIn = 0;
	}
}

function autoTrans(num,stopper) {
	var old = parseInt($('cur').value); // grab currently displayed image ID
	if ((num != undefined && num != old) || num == undefined) { // make sure that same image not clicked on twice in a row
		new Effect.Opacity("page"+old, {duration:.25,from:1.0,to:0}); // fade current image
	}
	var newNum = old + 1; // increment image ID for sequential animation
	if (num == undefined && stopper == undefined) { // if animation is automatic
		fadeIn = setTimeout('clicker('+newNum+')',500); // send sequential image ID to fadeIn
	} else { // if image was chosen by user
		fadeIn = setTimeout('clicker('+num+',"true")',500); // send user image ID & stopper variable to fadeIn
	}
}

var speed = 6000; // speed in miliseconds (1000 = 1s)
var fadeIn = 0; // define fadeIn
var fadeOut = 0; // define fadeOut
clearTimeout();
clearTimeout(fadeIn);
clearTimeout(fadeOut);
Event.observe(window, 'load',
	function() {
		var fadeOut = setTimeout('autoTrans()',speed); // begin transitions automatically
	}
);
// END WIDGET JS
