/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/
(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 700,
		pause: 4000,
		showItems: 3,
		animation: '',
		mousePause: true,
		isPaused: false
	};

	//var options2 = $.extend(defaults, options);

	moveUp = function(obj2, height, options2){
		if(options2.isPaused)
			return;
		
		var obj = obj2.children('ul');
		
    	first = obj.children('li:first').clone(true);
		
    	obj.animate({top: '-=' + height + 'px'}, options2.speed, function() {
        	$(this).children('li:first').remove();
        	$(this).css('top', '0px');
        });
		
		if(options2.animation == 'fade')
		{
			obj.children('li:first').fadeOut(options2.speed);
			obj.children('li:last').hide().fadeIn(options2.speed);
		}

    	first.appendTo(obj);
	};
	
	return this.each(function() {
		var obj = $(this);
		var maxHeight = 0;

		var options2 = $.extend(defaults, options);

		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 * options2.showItems);

		var interval = setInterval(function() { moveUp(obj, maxHeight, options2); }, options2.pause);
		
		if(options2.mousePause)
		{
			obj.bind("mouseenter",function(){
				options2.isPaused = true;
			}).bind("mouseleave",function(){
				options2.isPaused = false;
			});
		}
	});
};
})(jQuery);