// Slippy: A Simple Slider Widget
// Author: Thomas Peri
// Version 2009-05-12

var Slippy;

Slippy = function (options) {
	
	$(function () {
	
		var height, width, items, current, next, advance;
	
		// set up the container except for its height
		$(options.container).css({
			position: 'relative',
			top: 0,
			left: 0,
			display: 'block',
			overflow: 'hidden'
		});
		
		// grab the width, set some other initial values
		width = $(options.container).width();
		height = 0;
		items = [];
		current = 0;
		next = 0;
		
		// stash all the items, and determine the tallest height
		$(options.item).each(function () {
			items.push(this);
			height = Math.max(height, $(this).height());
		});
		
		// make the container be the height of the tallest item
		$(options.container).css({
			height: height
		});
		
		// set up each item
		$(options.item).each(function () {
			$(this).css({
				position: 'absolute',
				top: 0,
				width: width,
				left: width,
				paddingTop: (height - $(this).height()) / 2
			});
		});
		
		// cycle through
		advance = function () {
			if (current !== next) {
				$(items[current]).animate({
					left: -width
				});
			}
			$(items[next]).css({
				left: width
			}).animate({
				left: 0
			});
			
			current = next;
			next = (next + 1) % items.length;
		};
		
		advance();
		setInterval(advance, options.duration);

	});
};
