
//
// Created on: 2009-11-11
// Author: M
//
// Startup-Script for the RKI 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);
}


/* The photo in the header section gets randomly selected by this function. */
function
init_photo ()
{
	if (document.getElementById("photo")) {
		var photonr = get_rand (1, 9);
		document.getElementById("photo").src = 
			"images/header/0"+photonr+".jpg";
	}
}

/* Function from naden.de */
function
get_rand (min, max)
{
       if( min > max ) {
               return( -1 );
       }
       if( min == max ) {
               return( min );
       }

       return( min + parseInt( Math.random() * ( max-min+1 ) ) );
} 



add_load_event (init_links);
add_load_event (init_photo);


} /* if DHTML */
