var TIME_ON_SLIDE = 7000; //1000 ms = 1 sec
var SCROLL_DURATION = 1000;

var contentDivs = [ 'div_1', 'div_2' ];
var currIdx = 0;
var scroll = null;
var timeout = null;

window.addEvent('domready', function() {
	scroll = new Fx.Scroll2('content_wrapper', {
		wait: false,
		duration: SCROLL_DURATION,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	});

	$('left_link').addEvent('click', scrollLeft);
	$('right_link').addEvent('click', scrollRight);
	setTimeout(doTimedSlide, TIME_ON_SLIDE); //begin timed sliding
});

function scrollLeft(event) {
	event = new Event(event).stop();

	--currIdx; //decrement
	if(currIdx <= 0) currIdx = 0; //check lower bound
	scroll.toElement(contentDivs[currIdx]); //scroll
} //end method scrollLeft

function scrollRight(event) {
	if(event) event = new Event(event).stop();

	++currIdx; //increment
	if(currIdx >= contentDivs.length) currIdx = contentDivs.length - 1; //check upper bound
	scroll.toElement(contentDivs[currIdx]); //scroll
} //end method scrollRight

function doTimedSlide() {
	scrollRight(window.event); //do scrolling

	setTimeout(function() { //continue timer after finished scrolling
		//continue to the next slide as long as there is one
		if(currIdx < contentDivs.length - 1)
			timeout = setTimeout(doTimedSlide, TIME_ON_SLIDE); //begin timer
		else togglePlayPause(); //pause timed sliding
	}, SCROLL_DURATION);
} //end function doTimedSlide

function togglePlayPause() {
	var lnk = $('play_pause_link');
	var currOp = lnk.innerHTML;
	
	if(currOp.test(/pause/gi)) { //if we're pausing
		clearTimeout(timeout); //stop timer
		lnk.innerHTML = '<img src="graphics/00000016/layout/header/play.gif" alt="Play" border="0" />'; //toggle play/pause text
	} //end if
	else { //if we're playing
		if(currIdx >= contentDivs.length - 1) currIdx = -1; //if we're at the end, we need to start it over
		doTimedSlide(); //begin timed sliding
		lnk.innerHTML = '<img src="graphics/00000016/layout/header/pause.gif" alt="Pause" border="0"/>'; //toggle play/pause text
	} //end else
} //end method playPause