Z(function(){
    Z('ul.spy').simpleSpy();
});

(function(Z){
Z.fn.simpleSpy = function (limit, interval) {
    limit = limit || 3;
    interval = interval || 4000;

    return this.each(function () {
        var Zlist = Z(this),
            items = [],
            currentItem = limit,
            total = 0,
            height = Zlist.find('> li:first').height();
        Zlist.find('> li').each(function () {
            items.push('<li>' + Z(this).html() + '</li>');
        });

        total = items.length;
        Zlist.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });
        Zlist.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

        function spy() {
            var Zinsert = Z(items[currentItem]).css({height : 0, opacity : 0, display : 'none'}).prependTo(Zlist);
				Zlist.find('> li:last').animate({opacity : 0}, 1000, function () {
            	Zinsert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
            	Z(this).remove();
            });

            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }
            setTimeout(spy, interval)
        }
        spy();
    });
};  
})(jQuery);
