
function computeTagInfo() {
    var lstTags = new Object();
    for (var k in Delicious.tags) {
        lstTags[k.toLowerCase()] = [Delicious.tags[k],0];
    }
   
    for ( var i = 0; i < Delicious.posts.length; i++ ) {
        for( var j = 0; j < Delicious.posts[i].t.length; j++ ) {
            // alert(Delicious.posts[i].t[j].toLowerCase());
            lstTags[Delicious.posts[i].t[j].toLowerCase()][1]++;
        }
    }
    
    return lstTags;
}

function computeClassName(tCount) {
    var cName;
    if ( tCount == 0 ){ 
        cName = '';
    }
    if ( tCount < 3) {
        cName = 'significant';
    }
    else if (tCount < 6 ) {
        cName = 'prettysignificant';
    }
    else if (tCount < 12 ) {
        cName = 'relevant';
    }
    else if (tCount < 18 ) {
        cName = 'important';
    }
    else if (tCount < 24 ) {
        cName = 'prettyimportant';
    }
    else if (tCount < 36 ) {
        cName = 'veryimportant';
    }
    else if (tCount < 32 ) {
        cName = 'hot';
    }
    else if (tCount < 38 ) {
        cName = 'prettyhot';
    }
    else if (tCount < 44 ) {
        cName = 'veryhot';
    }
    else if (tCount < 48 ) {
        cName = 'cool';
    }
    else {
        cName = 'ueberkwel';
    }
    return cName;
}

function computeClassNameB(tCount) {
    var cName;
    if ( tCount == 0 ){ 
        cName = '';
    }
    else if ( tCount < 2) {
        cName = 'significant';
    }
    else if (tCount < 3 ) {
        cName = 'prettysignificant';
    }
    else if (tCount < 4 ) {
        cName = 'relevant';
    }
    else if (tCount < 5 ) {
        cName = 'important';
    }
    else if (tCount < 6 ) {
        cName = 'prettyimportant';
    }
    else if (tCount < 7 ) {
        cName = 'veryimportant';
    }
    else if (tCount < 8 ) {
        cName = 'hot';
    }
    else if (tCount < 9 ) {
        cName = 'prettyhot';
    }
    else if (tCount < 12 ) {
        cName = 'veryhot';
    }
    else if (tCount < 15 ) {
        cName = 'cool';
    }
    else {
        cName = 'ueberkwel';
    }
    return cName;
}


function createTagCloud(tagInfo) {
    var cloud = document.getElementById('tagcloud');
    for (var k in tagInfo) {
        var span1  = document.createElement('span');
        span1.className = 'tag' + computeClassName( tagInfo[k][0] );
        var span2  = document.createElement('span');
        span2.className= 'recent' + computeClassNameB( tagInfo[k][1] );
        var a = document.createElement('a');
        a.className = 'taghandler';
        a.setAttribute('href', 'http://del.icio.us/phish108/'+k);
        a.setAttribute('target', '_blank');
        
        span2.appendChild( document.createTextNode( k ));
        span1.appendChild(span2);
        a.appendChild(span1); // the link has to be outmost, 
                              // because otherwise IE applies the wrong styles
        cloud.appendChild(a);

        cloud.appendChild(document.createTextNode(' '));   
    }        
}

createTagCloud(computeTagInfo());

