// Rotating quotes.
// no docs yet.

function quotate(options) {

	$(function () {
		var height,
			offset,
			width,
			quotes,
			index,
			scroll;
		
		offset = $(options.middle).outerWidth();
		height = 0;
		quotes = [];
		index = 0;
		
		scroll = function () {
			var next;
	
			next = (index + 1) % quotes.length;
	
			$(quotes[index]).css({
				left: 0,
				opacity: 1
			}).animate({
				left: -offset,
				opacity: 0
			}, 400);
	
			$(quotes[next]).css({
				left: offset,
				opacity: 0
			}).animate({
				left: 0,
				opacity: 1
			}, 600);
			
			index = next;
			
		};
		
		$(options.quote).
		each(function () {
			quotes.push(this);
			$(this).css({
				padding: 0,
				margin: 0,
				position: 'absolute',
				width: '148px', // do it here 'cause of safari
				top: 0,
				left: offset
			});
		});
		
		// for ie7
		$(options.container).css({
			display: 'block'
		});
		
		// defer this part for safari
		$(window).load(function () {
		
			$(options.quote).
			each(function () {
				height = Math.max(height, $(this).height());
			}).
			each(function () {
				$(this).css({
					paddingTop: ((height - $(this).height()) / 2) + 'px'
				});
			});
			
			$(options.container).height(height);
			
			$(quotes[0]).css({
				left: 0
			});
		
			if (quotes.length > 1) {
				setInterval(scroll, options.delay);
			}
			
		});
		
	});
}
