/*
 * jquery.ticktick 1.0 - A small and tiny news ticker
 *
 * Copyright (c) 2009 mjl|rt
 */

(function($) {
    function moveItem(ul) {
        $('li:first', ul).animate({ marginLeft: 0 }, ul.ticktick_speed, "linear")
                         .animate({ marginLeft: 0 }, ul.ticktick_pause)
                         .fadeOut('slow', function(){ addLast(ul, this); });
    }

    function addLast(ul, first){
        $(first).css('margin-left', ul.ticktick_width)
                .appendTo(ul)
                .fadeIn('slow', function() { moveItem(ul); } );
    }

    $.fn.ticktick = function(opts) {
        this.ticktick_width = '' + this.width() + 'px';
        this.ticktick_speed = (opts && opts.speed) || 4000;
        this.ticktick_pause = (opts && opts.pause) || 1000;
        $('li', this).css('margin-left', this.ticktick_width);
        moveItem(this);
    };
})(jQuery);
