
var thedirs = "up";
(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 700,
		pause: 4000,
		showItems: 4,
		animation: "fade",
		mousePause: true
	};

	var options = $.extend(defaults, options);

	moveUp = function(obj, height){
		obj = obj.children('ul');
    	first = obj.children('li:first').clone(true);

    	obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
        	$(this).children('li:first').remove();
        	$(this).css('top', '0px');
        });

        if(options.animation == 'fade')
		{
			obj.children('li:first').fadeOut(options.speed);
			obj.children('li:last').hide().fadeIn(options.speed);
		}

    	first.appendTo(obj);
	};

    moveDown = function(obj, height){
         obj = obj.children('ul');
    	last = obj.children('li:last').show().clone(true);

        if(options.animation == 'fade')
		{
		    var counts = 0;
		    obj.children('li').each(function()
            {
               counts++;
               if(counts == options.showItems)
               {
                    $(this).fadeOut(options.speed);
               }

            });

		}

        obj.css('top', '-' + height + 'px');
        obj.animate({top: '+=' + height + 'px'}, options.speed, function() {
            $(obj.children('li:last')).remove();
            $(this).css('top', '0px');
        });

        last.insertBefore(obj.children('li:first'));
        if(options.animation == 'fade')
		{
		    obj.children('li:first').hide().fadeIn(options.speed);
		}


	};

    moveing = function(obj, height)
    {
        if(thedirs == "up")
        {
            moveUp(obj, height);
        }
        else
        {
            moveDown(obj, height);
        }
	};
	
	return this.each(function() {
		obj = $(this);
		maxHeight = 0;

		obj.css({overflow: 'hidden', position: 'relative'})
			.children('ul').css({position: 'absolute'});

		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);
		
    	interval = setInterval('moveing(obj, maxHeight)', options.pause);
		
		if(options.mousePause)
		{
			obj.bind("mouseenter",function(){
				clearInterval(interval);
			}).bind("mouseleave",function(){
				interval = setInterval('moveing(obj, maxHeight)', options.pause);
			});
		}
	});
};
})(jQuery);
