$(function() {
    
    var $tt = $(".term-tab"),
        $tc = $(".term-contents");
    
    function loadUrl(url) {
        $tc.empty().append($(".loading-please-wait").clone().show());
        $.ajax({
            url: url,
            dataType: "html",
            success: function(html) {
                $tc.html(html);
                $tc.find(".term-filter a").click(function() {
                    loadUrl($(this).attr("href"));
                    return false;
                });
                dbpediaBox.bind($tc.find(".terms h3"));
            }
        });
    }
    
    $tt.click(function() {
        var $this = $(this);
        $tt.removeClass("active");
        $this.addClass("active");
        loadUrl($this.find("a").attr("href"));
        return false;
    });
    
    dbpediaBox.bind(".term-cloud a");
});
