var TweetBox = function ($jObj, word) {
    
    this.obj = $jObj;
    this.obj_inner;
    this.data = word;
    
    this.init = function () {
        this.obj.height(this.obj.outerHeight(true));
        this.obj.empty().append('<span class="inner"></span>');
        this.obj_inner = this.obj.find('.inner');
    }
    
    this.getJSON = function () {
        var url = 'http://search.twitter.com/search.json?rpp=5&callback=?&q=' + this.data;
        var self = this;
        $.getJSON(url, function (data) {
            self.populate(data);
        });
    }
    
    this.populate = function (data) {
        var text = "";
        $.each(data.results, function (i, tweet) {
            text += tweet.text + ' ';
        })
        this.obj_inner.text(text);
        this.obj.attr('js_width',this.obj_inner.outerWidth());
        this.prepareAnimation();
    }
    
    this.prepareAnimation = function () {
        this.obj_inner.css('left',318);
        this.doAnimation();
    }
    
    this.doAnimation = function () {
        var target = this.obj.attr('js_width');
        var speed = 0.04;
        var time = Math.round(target / speed);
        target *= -1;
        var self = this;
        this.obj_inner.animate({left:target}, time, "linear", function () {
            self.prepareAnimation();
        });
    }
    
    this.init();
}

