﻿(function ($) {
    $.fn.techtweets = function (options) {

        var defaults = {
            account: "edsondewes",
            count: 5,
            page: 1,
            imgtitle: "Siga-nos no Twitter",
            imgsrc: "/Style Library/techresult/imagens/twitter_siganos.png"
        };

        var options = $.extend(defaults, options);
        var url = "http://twitter.com/status/user_timeline/" + options.account + ".json?count=" + options.count + "&page=" + options.page + "&callback=?";
        var obj = this;

        $.getJSON(url, function (data) {

            obj.each(function () {
                var last = $("<p />");
                var others = $("<ul />").addClass("twitter"); ;

                $.each(data, function (i, post) {
                    if (i == 0)
                        last.html(post.text);
                    else
                        others.append($("<li />").html(post.text));
                });
                $(this)
                    .append(last)
                    .append(others)
                    .append(
                        $("<a />").attr({
                            href: "http://www.twitter.com/" + options.account,
                            "class": "twitter-siga",
                            title: options.imgtitle
                        })
                            .html($("<img />").attr({
                                src: options.imgsrc,
                                alt: options.imgtitle,
                                border: 0
                            }))
                    );
            });
        });
        return this;
    }
})(jQuery);
