// JavaScript Document

// Options you can change
var banner_ids = ['image_1','image_2','image_3','image_4','image_5']; // id's of the divs to rotate
var banner_intvl = 8000; // time between rotations in milliseconds

 
// The function that does the rotation, the timer will pass the array
function _rotate(ids) {
	var divs = new Array();
	for(var i=0; i<ids.length; i++) {
		divs[divs.length] = document.getElementById(ids[i]);
	}
	for(var i=0; i<divs.length; i++) {
		if(divs[i].style.display == 'block') {
			divs[i].style.display = 'none';
			// divs[(i != (divs.length-1)) ? ++i : 0].style.display = 'block'; // forward only
			// I have no idea why I needed to assign the value back to 'i', but backwards scroll wasnt working without it
			divs[i = arguments[1] && typeof arguments[1] == 'boolean' ?
					i!=0 ? --i : divs.length-1 : 
					(i != (divs.length-1)) ? ++i : 0
				].style.display = 'block';
		}
	}
}

// manual function for clicky rotation, resets timers, moves in a given direction
function rotate(type,direction) {
	if(!window['timer_'+type] || !window[type+'_ids']) return;
	clearInterval(window['timer_'+type]);
	_rotate(window[type+'_ids'],direction=='back'?true:false);
	window['timer_'+type] = setInterval('_rotate('+type+'_ids)',window[type+'_intvl']);
}

// the timers, you can kill the timer with 'clearInterval(timer_XXX)'
timer_banner = setInterval('_rotate(banner_ids)',banner_intvl);
