jQuery.fn.carousel = function(orientation, delay) {
	/*switch (orientation) {
		case 'vetical':
			break;
		case 'horizontal':
			break;
	}*/
	
	var carousel = this;
	
	var totalHeight = 0;
	this.children().each(function(i) {
		var height = $(this).outerHeight(true);
		var top = 0;
		
		top = height * i;
		totalHeight += height;
		
		$(this).css({
			position: 'absolute',
			top: top + 'px',
			left: '0'
		});
		
	});
	this.css('height', totalHeight + 'px');
	
	var rotateDelay = setInterval(rotate, 6000, carousel);
	
	function rotate(target) {
		target.children().each(function() {
			var nextPosition = parseFloat( $(this).css('top') ) - $(this).outerHeight(true);
			$(this).animate({
				top: nextPosition + 'px'
			}, 500, 'easeInOutBack', function() {
				if ( parseFloat( $(this).css('top') ) < 0 ) {
					var nextPosition = totalHeight - $(this).outerHeight(true);
					$(this).fadeOut(0, function() {
						$(this).css('top', nextPosition + 'px');
						$(this).fadeIn(500);
					});
				}
			});
		});
	}
	
	carousel.children().hover(
		function() {
			clearInterval(rotateDelay);
			$(this).css('background-position', 'bottom right');
		},
		function() {
			$(this).css('background-position', 'bottom left');
			if ( carousel.children(':animated').length == 0 ) {
				rotate(carousel);
			}
			rotateDelay = setInterval(rotate, 6000, carousel);
		}
	);
}

$(document).ready(function() {
	$('#carousel').carousel('vertical', 5000);
});