var pcb = {}
var pcb_c = 0;
var pcb_m = 10;
var pcb_begriffe;

window.addEvent('domready', function() {
    pcb.dataInit(true);
});

pcb.dataInit = function(add_event) {
    var hn = 'http://' + window.location.hostname + '/?type=500';
    if (window.location.hostname == 'www.computerwissen.de') hn = 'http://' + window.location.hostname + '/cms/?id=508&type=500';
    var jsonRequest = new Request.JSON({
        url: hn,
        //url: 'http://' + window.location.hostname + '/hub_neu/?type=500',
        method: 'get',
        onComplete: function(json) {
            pcb.dataProcessor(json);
        }
    }).send();
    if (add_event) $('pcb_reloaderurl').addEvent('click', function() {return pcb.reloadWidget();});
    pcb_c = 0;
}

pcb.dataProcessor = function(json) {
    pcb_begriffe = json;
    pcb_m = json.items.length;
    var theTerm = json.items[pcb_c].title;
    var theUrl = json.items[pcb_c].link;
    pcb.setTerm(theTerm, theUrl);
}

pcb.setTerm = function(theTerm,theUrl) {
    //set term
    $('pcb_term').set('text', theTerm);
    //set termurl
    $('pcb_termurl').set('href', theUrl);
    //set answerurl
    $('pcb_answerurl').set('href', theUrl);
    return false;
}

pcb.doRefresh = function() {
    pcb_c++;
    if (pcb_c < pcb_m) {
        pcb.dataProcessor(pcb_begriffe);
    } else {
        pcb.dataInit(false);
    }
}

pcb.reloadWidget = function() {
    pcb.doRefresh();
    return false;
}