(function($) {
    $.fn.twitterTicker = $.fn.twitterTicker = function(options) {
        var opts = $.extend({}, $.fn.twitterTicker.defaults, options);
        $(this).append('<ul id="twitter_update_list" style="margin:12px 0 0 25px;padding-bottom:10px;list-style-type:none;"><li></li></ul>');

        var pl = $('<p style="margin:0 0 0 35px;padding-bottom:30px;" id="' + opts.preloaderId + '">' + opts.loaderText + '</p>');
        $(this).append(pl);
        $.getScript("http://twitter.com/javascripts/blogger.js");
        $.getScript("http://twitter.com/statuses/user_timeline/" + opts.userName + ".json?callback=twitterCallback2&count=" + opts.numTweets, function() {
            $(pl).remove();
            var el = $("ul#twitter_update_list");
            stopTicker(el);
            el.items = $("li", el);
            el.items.not(":eq(0)").hide().end();
            el.currentitem = 0;
            startTicker(el);
        });
        startTicker = function(el) {
        el.tickfn = setInterval(function() { doTick(el) }, opts.delay)
        };
        stopTicker = function(el) {
            clearInterval(el.tickfn);
        };
        doTick = function(el) {
			if (el.pause) return;
            el.pause = true;
            $(el.items[el.currentitem]).fadeOut("slow",
			function() {
			    $(this).hide();
			    el.currentitem = ++el.currentitem % (el.items.size());
			    $(el.items[el.currentitem]).fadeIn("slow",
					function() {
					    el.pause = false;
					}
				);
			}
		);
        };
        this.each(
		function() {
		    if (this.nodeName.toLowerCase() != "ul") return;
		}
	)
	.addClass("twitterTicker");
	$(".twitterTicker").css({float:"left",font:"italic bold 11px/13px Georgia,'Times New Roman',Times,serif",background:"url(img/web/iconos/fondoTwitter.gif) no-repeat left top"});
    };
    $.fn.twitterTicker.defaults = {
        userName: null,
        numTweets: 5,
        delay: 4000,
        preloaderId: "preloader",
        loaderText: "Loading tweets...",
        slideIn: false
    };
})(jQuery);