
TwitterAPI = {
    Statuses: {
        user_timeline:function(screen_name, count, callback){
            jQuery.getJSON("http://twitter.com/statuses/user_timeline/" + screen_name + ".json?count="+count+"&cb="+Math.random()+"&callback=?", callback);
        }
    }
};

window.theTweet = function() { var entities = { '"': '"', '&': '&', '<': '<', '>': '>' }; return { "link": function(t) { return t.replace(/[a-z]+:\/\/[a-z0-9-_]+\.[a-z0-9-_:~%&\?\/.=]+[^:\.,\)\s*$]/ig, function(m) { return '<a href="' + m + '">' + ((m.length > 25) ? m.substr(0, 24) + '...' : m) + '</a>'; }); }, "at": function(t) { return t.replace(/(^|[^\w]+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) { return m1 + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>'; }); }, "hash": function(t) { return t.replace(/(^|[^\w'"]+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) { return m1 + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>'; }); }, "clean": function(tweet) { return this.hash(this.at(this.link(tweet))); } }; } ();

$(document).ready(function () {

    if ($('#ews_menubar').length == 0) {
        $('#ewsmenu_main a[href="/resources/messages--media"]').click(function (e) {
            e.preventDefault();
            openPlayer('constancefree');


        });
    }
    if (typeof ews.Util == "undefined") {
        $('#ewsmenu_scrollerMenu li').each(function (intIndex, objValue) {

            //alert((intIndex+1)%6==1);
            if (intIndex % 4 == 0) {
                set = $("<div id='set" + intIndex + "' class='clear set'></div>");
                $("#ewsmenu_scrollerMenu").append(set);
            }
            set.append(this);
        });

        if ($('#ewsmenu_scrollerMenu li').length < 5) {
            $('#forward').hide();
            $('#backward').hide();
        }
        else {

            $("#ewsmenu_scrollerMenu").cycle({
                fx: 'scrollHorz',
                speed: 'slow',
                timeout: 0,
                next: '#forward',
                prev: '#backward'
            });


        }
    }
    else {
        $('#forward').hide();
        $('#backward').hide();
    }

    var tUser = $('#my_user').attr("href");
    var arr = tUser.split("/");
    var theUserName = arr[3];

    TwitterAPI.Statuses.user_timeline(theUserName, 5, function (json) {

        var content = "";
        content += '<ul class="statuses">';
        $.each(json, function (i) {
            //alert(this['user'].description);
            var tweet = theTweet.clean(this['text']);
            var d = new Date(this['created_at']);
            var date_show = d.getMonth() + 1 + '/' + d.getDate() + '/' + d.getFullYear() + ' ' + d.getHours() + ':' + d.getMinutes();
            content += '<li>' + tweet + '<em>posted on <span><a href="http://twitter.com/' + this['user'].screen_name + '/status/' + this['id'] + '" target="_blank">' + date_show + '</a></span></em></li>';
        });
        content += '</ul>';
        $('#tweets').append(content);
    });

});
