/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/

(function(jQuery){
jQuery.fn.vTicker = function(options) {
	var defaults = {
		speed: 700,
		pause: 3000,
		showItems: 1
	};

	var options = jQuery.extend(defaults, options);

	moveUp = function(obj, height){
    	first = obj.children('ul').children('li:first').clone(true);
    	obj.children('ul')
    	.animate({top: '-=' + height + 'px'}, options.speed, function() {
        	jQuery(this).children('li:first').remove();
        	jQuery(this).css('top', '3px');
        });

    	first.appendTo(obj.children('ul'));
	};
	
	return this.each(function() {
		obj = jQuery(this);
		maxHeight = 0;

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

		obj.children('ul').children('li').each(function(){
			if(jQuery(this).height() > maxHeight)
			{
				maxHeight = jQuery(this).height();
			}
		});

		obj.children('ul').children('li').each(function(){
			jQuery(this).height(maxHeight);
		});

		obj.height((maxHeight * options.showItems)+7);
		
    	interval = setInterval('moveUp(obj, maxHeight)', options.pause);
	});
};
})(jQuery);
