/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/

(function(jQuery){
jQuery.fn.vTicker = function(options) {
	var defaults = {
		speed: 700,
		pause: 4000,
		showItems: 2
	};

	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', '0px');
        });
    	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, padding: 0, display: 'block'});

		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);
		
		interval = setInterval('moveUp(obj, maxHeight)', options.pause);
		
		obj.hover(function(){
			//alert('hello');
			//obj.children('ul').stop();
			clearInterval(interval);
		}, function() {
			interval = setInterval('moveUp(obj, maxHeight)', options.pause);
		}
		);
	});
};
})(jQuery);