/*
	Tadas Juozapaitis ( kasp3rito@gmail.com )
	
	Fred Snyder (fred@blindacre.com)

	Rewritten with proper closures to handle multiple vtickers on same page - FS
*/

(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 9000,
		pause: 7000,
		showItems: 1,
		animation: '',
		mousePause: true
	};
	var options = $.extend(defaults, options);
	

	return this.each(function() {
		var obj = $(this);
		maxHeight = 0;

		obj.css({overflow: 'hidden', position: 'relative'})
			.children('ul').css({position: 'absolute', margin: 0, padding: 0})
			.children('li').css({margin: 0, padding: 0});

		obj.children('ul').children('li').each(function(){
			if($(this).height() > maxHeight)
			{
				maxHeight = $(this).height();
			}
		});
		obj.children('ul').children('li').each(function(){
			$(this).height(maxHeight);
		});
		obj.height(maxHeight * options.showItems);

		var moveUp = function() {
			var ul = obj.children('ul');
			var first = ul.children('li:first').clone(true);
			var height = ul.children('li:first').height();
			ul.animate({top: '-=' + height + 'px'}, options.speed, function() {
				$(this).children('li:first').remove();
				$(this).css('top', '0px');
			});
			
			if(options.animation == 'fade')
			{
				ul.children('li:first').fadeOut(options.speed);
				ul.children('li:last').hide().fadeIn(options.speed);
			}

			first.appendTo(ul);
		}
		var interval = setInterval(moveUp, options.pause);
		obj.bind("mouseenter", function() {
			clearInterval(interval);
		});
		obj.bind("mouseleave", function() {
			interval = setInterval(moveUp, options.pause);
		});
	});
};
})(jQuery);