
//
// Created on: 2010-01-11
// Author: M
//
// Startup-Script for the top-hifi website.
//
// ***
//
// LAST MODIFICATION:
//
// YYYY-MM-DD: Author
//      Description
//

DHTML = (document.getElementById || document.all || document.layers);
if (DHTML) {


/* Adds an event to window.onload without overwriting currently
 * assigned onload functions.
 * Function found at Simon Willison's weblog - 
 *      http://simon.incutio.com/ */
function
add_load_event (func)
{
    var old_onload  = window.onload;

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


/* Initialisiert Links (öffnen in neuem Fenster, öffnen des Mehl-Clients, 
 * usw.). */
function
init_links ()
{
    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];

        // Oeffnen von neuen Browserfenstern:
        if(anchor.getAttribute("href")  &&
           anchor.getAttribute("rel")   == "newwin")
        {
            anchor.href = "javascript:newwin('"+anchor.getAttribute("href")+"');";
        } else if(anchor.getAttribute("href")   &&
                  anchor.getAttribute("rel")    == "mehl")
        {
            var mailad  = anchor.innerHTML;
            mailad      = mailad.replace(/, /, "@");
            mailad      = mailad.replace(/ /g, ".");
            anchor.href         = "mailto:" + mailad;
            anchor.innerHTML    = mailad;
        } else if(anchor.getAttribute("href")   &&
                  anchor.getAttribute("rel")    == "picture")
        {
            // Link zu einem Fotos soll sich in einem Popup oeffen:
            anchor.href = "javascript:popupPic('" + anchor.getAttribute("href") 
                + "', '" + anchor.getAttribute("title") + "');";
        } else ;
    }
}


function
newwin(url) {
    window.open(url);
}


add_load_event (init_links);


} /* if DHTML */

