/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/
(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 11501,
		mousePause: true,
		itemspace:17,
		isPaused: false
	};

	var options = $.extend(defaults, options);

	
	startMove = function(obj2){
		if(options.isPaused)
			return;
			
    	obj2.animate({top: -20}, (parseInt(obj2.css("top"))+20) * options.speed / (options.containerheight), "linear", function(){
			var mh = 0;
			$(this).parent().children().each(function(){
				var ti = $(this);
				if (parseInt(ti.css('top')) > mh) mh = parseInt(ti.css('top')) + ti.height();
			});
		
			$(this).css("top", mh + options.itemspace);
			startMove($(this));
		});
		
		//if(options.animation == 'fade')
		//{
		//	obj.children('li:first').fadeOut(options.speed);
		//	obj.children('li:last').hide().fadeIn(options.speed);
		//}

    	//first.appendTo(obj);
	};
	
	return this.each(function() {
		var obj = $(this);
		var maxHeight = 0;

		obj.css({display:'block',overflow: 'hidden', position: 'relative'});
		options.containerheight = obj.height();
		localheight = options.containerheight;
		obj.css("height", obj.parent().height());
		
		
		$(".tickeritem", obj).each(function(){
			var item = $(this);
			$(this).css({position: 'absolute', top: localheight , margin: 0, padding: 0});
			localheight += item.height() + options.itemspace;
			startMove($(this));
		});

		if(options.mousePause)
		{
			obj.bind("mouseenter",function(){
				obj.children().stop();
			}).bind("mouseleave",function(){
				$(this).children().each(function(){
					startMove($(this));
				})
			});
		}
	});
	
};
})(jQuery);
