
/*
 * Browses through all link-tags and looks for rel="newwin".
 * If found, those links receive onclick events that enable
 * a the creation of a new window, when the link is clicked.
 * Derived from the lightbox-script: 
 *      http://www.huddletogether.com
 */
function
initNewWin()
{
    if(!document.getElementsByTagName) {
        return ;
    }

    var anchors = document.getElementsByTagName("a");

    // Loop through all anchor tags
    for(var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];

        if(anchor.getAttribute("href")  &&
           anchor.getAttribute("rel")   == "newwin")
        {
            anchor.href = "javascript:newwin('"+anchor.getAttribute("href")+"');";
        } else if(anchor.getAttribute("href")  &&
                  anchor.getAttribute("rel")   == "video")
        {
            anchor.href = "javascript:popup_video('"+anchor.getAttribute("href")+"', 380, 340);";
        }
    }
}

function
newwin(url)
{
    window.open(url);
}

function
popup_video(url, width, height)
{
    var left    = (screen.width/2) - (width/2);
    var top     = (screen.height/2) - (height/2);
    top        -= 100;
    day         = new Date();
    id          = day.getTime();
    eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);");
}


/*
 * Adds an event to window.onload without overwriting currently
 * assigned onload functions.
 * Function found at Simon Willison's weblog - 
 *      http://simon.incutio.com/ 
 */
function
addLoadEvent(func)
{
    var old_onload  = window.onload;

    if(typeof window.onload != 'function') {
        window.onload   = func;
    } else {
        window.onload   = function() {
            old_onload();
            func();
        }
    }
}

addLoadEvent(initNewWin);

