window.onload = function() {
	var e, i = 0;
	$('gallery').getChildren('div').each(function(e) {
		if (e.hasClass('on') || e.hasClass('off')) {
			e.addEvent('click', function(event){toggleVis(event.target);});
		}
	});
	loop();
}
	
	
	
function toggleVis (e) {
	if (!$(e)) return false;
	if (e.hasClass('on')) return true; // if it's already on, don't do anything
	var getEls = $('featureInner').getChildren('div.fBanner');
	getEls.each(function(el) {
		el.fade('out');
		setTimeout(function(){ // wait a bit for the fade to finish before continuing
				el.removeClass('show');
				el.addClass('hide');
				$('gallery').getChildren('div').each(function(tab) { tab.removeClass('on'); tab.addClass('off');});
			}, 
		300);
	});
	img = $(e.getAttribute('title'));
	setTimeout(function() { // wait a bit for the fade to finish
		e.addClass('on');
		e.removeClass('off');
		img.removeClass('hide');
		img.addClass('show');
		img.fade('in');
		}, 
	300);
}

var loop_pos = 0;
function loop() {
	toggleVis($('gallery').getChildren('div')[loop_pos]);
	loop_pos<3?loop_pos++:loop_pos=0;
	setTimeout(function() {loop();}, 7000);
}