$(document).ready(function() {

    function twitterify(tweet) {
        if (tweet.search(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/) > -1) {
            tweet = tweet.replace(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/, "<a href='$1'>$1</a>")
        }
        if (tweet.search(/@\w+/) > -1) {
            tweet = tweet.replace(/(@)(\w+)/g, "<a href='http://twitter.com/$2'>$1$2</a>");
        }
        return tweet;
    }

    function loadFeeds() {

        var panel = $('.twitter');

        panel.html('Loading...');

        var url = 'http://search.twitter.com/search.json?phrase=6kare&rpp=3&callback=?';

        $.getJSON(url, function(data) {

            var html = '';

            $.each(data.results, function() {

                html += '<div><h3><a href="http://twitter.com/' + this.from_user + '">' +
                        '<img src="' + this.profile_image_url + '" width="16" height="16" />' +
                        '<span>' + this.from_user + '</span></a></h3>' +
                        twitterify(this.text) +
                        '</p></div>';

            });

            if (html == '') {
                $('.twitterPanel').hide();
            }
            else {
                $('.twitterPanel').show();
                $('.twitter').html(html);
            }

        });

    }

    //loadFeeds();

    $('#language > .languageSel').hover( function() {
	$(this).find('.desc').show();
    }, function() {
	$(this).find('.desc').hide();
    });

});

