/*
 *	Simple Infinite Scroller
 *	http://www.enertiasolutions.com
 */
Event.observe(window, 'load', function() {
	//Init Scroller
	//***************************************************************************
	
	$$('div#simple_scroller > ul > li').each(function(h, i) {
		if(i != 0) {
			h.setStyle({ opacity: 0.0 });
		} else {
			currentScroller = h;
		}
	});
	
	if($$('div#simple_scroller > ul > li').size() > 1) {
		updateScroller();
	}
	//Scroller Click Handlers
	//***************************************************************************
	Event.observe('scrollPrevious', 'click', function(f) {
		if($$('div#simple_scroller > ul > li').size() <= 1) {
			return false;
		}
		currentScroller.setStyle({ zIndex : '1' });
		
		new Effect.Opacity(previousScroller, { from: 0.0, to: 1.0, duration: 0.5, queue: 'end' });
		new Effect.Opacity(currentScroller, {from: 1.0, to: 0.0, duration: .25, queue: 'end' });
		
		currentScroller = previousScroller;
		updateScroller();
	});
	Event.observe('scrollNext', 'click', function(f) {
		if($$('div#simple_scroller > ul > li').size() <= 1) {
			return false;
		}
		currentScroller.setStyle({ zIndex : '1' });
		
		new Effect.Opacity(nextScroller, { from: 0.0, to: 1.0, duration: 0.5, queue: 'end' });
		new Effect.Opacity(currentScroller, {from: 1.0, to: 0.0, duration: .25, queue: 'end' });
		
		currentScroller = nextScroller;
		updateScroller();
	});
});
//Scroller
//***************************************************************************
var currentScroller = '';
var previousScroller = '';
var nextScroller = '';
function updateScroller() {
	//alert(currentScroller.inspect());
	currentScroller.setStyle({ zIndex : '2' });
	previousScroller = currentScroller.previous('#simple_scroller > ul > li');
	nextScroller = currentScroller.next('#simple_scroller > ul > li');

	if(previousScroller != undefined) {
		//$('scrollPrevious').show();
	} else {
		previousScroller = $$('#simple_scroller > ul > li').last();
		//$('scrollPrevious').hide();
	}
	
	if(nextScroller != undefined) {
		//$('scrollNext').show();
	} else {
		nextScroller = $$('#simple_scroller > ul > li').first();
		//$('scrollNext').hide();
	}
}
