function addLoadEvent(func) 
{ 
    var oldonload = window.onload; 
    
    if (typeof window.onload != 'function') 
    { 
        window.onload = func; 
    } 
    else 
    { 
        window.onload = function() 
        { 
            if (oldonload) 
            { 
                oldonload(); 
            } 
            func(); 
        } 
    } 
}

function init_skill_tree() {
    // When a users checks a checkbox the LI-element containing the
    // checkbox should be set to expanded or collapsed depending on
    // the checkbox-state.
    //
    // This script finds the checkboxes within the skill-tree and
    // expands the leafs depending on checkbox state.
    //
    // It allso attaches eventlisteners to the checkboxes to expand /
    // collapse the trees based on the users actions
    
    // Find all inputs in the skill tree    
    var skilltree = document.getElementById('skill-tree');          
    var inputs = skilltree.getElementsByTagName('input');

    // Go though each input looking for checkboxes
    for(var i=0; i < inputs.length;i++)
    {
        if( inputs[i].type.toLowerCase() != 'checkbox') 
        {
            continue;
        }
            
        // Check if the LI containg the checkbox contains any ul elements
        var subitems = inputs[i].parentNode.getElementsByTagName('ul');
            
        if( subitems.length == 0 )
        {
            continue;
        }

        // Attach eventlistener
        inputs[i].onclick= function() {
            // Find LI containing this checkbox
            var node = this.parentNode;

            while( node.tagName.toLowerCase() != 'li' )
            {                                       
                node = node.parentNode;
            }
                
            // Expand / Collapse the LI element based on checkbox state
                
            if( this.checked )
            {                               
                node.className = "expanded";
            }
            else
            {
                node.className = "collapsed";                               
            }
        };

        // Trigger eventlistener
        inputs[i].onclick();
    }
}

function initVideo(id, url) { 
    var google = pageTracker;
    var provider = "";
                
    flowplayer(id, {
        src: "/design/lns/flash/flowplayer-3.1.5.swf",
        wmode: "transparent",
        clip: {
            provider: "psu",
            url: url,
            // track start event for this clip         
            onStart: function(clip) {             
                google._trackEvent("Videos", "Play", clip.url);         
            }, 
         
            // track pause event for this clip. time (in seconds) is also tracked        
            onPause: function(clip) {             
                google._trackEvent("Videos", "Pause", clip.url, parseInt(this.getTime()));         
            },                 
         
            // track stop event for this clip. time is also tracked         
            onStop: function(clip) {             
                google._trackEvent("Videos", "Stop", clip.url, parseInt(this.getTime())); 
            },                  
         
            // track finish event for this clip         
            onFinish: function(clip) {             
                google._trackEvent("Videos", "Finish", clip.url);         
            }
        },
        plugins: {
            psu: {
                url: 'flowplayer.pseudostreaming-3.1.3.swf'
            }
        }

    }); 
}
