//
// image map rollover
// from: http://www.oreillynet.com/pub/a/javascript/2003/07/01/bonusrecipe.html
//
function initMaps() {
    if (document.getElementById) {
        var mapIds = initMaps.arguments;    // pass string IDs of containing map elements
        var i, j, area, areas;
        for (i = 0; i < mapIds.length; i++) {
            areas = document.getElementById(mapIds[i]).getElementsByTagName("area");
            
            for (j = 0; j < areas.length; j++) {  // loop thru area elements
                area = areas[j];
                area.onmousedown = imgSwap;    // set event handlers
                area.onmouseout = imgSwap;
                area.onmouseover = imgSwap;
                area.onmouseup = imgSwap;
            }
        }
    }
}

// image swapping event handling
function imgSwap(evt) {
    // don't do this on the iphone it does not support hoover
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        return;
    }
    evt = (evt) ? evt : event;                   // equalize event models
    var elem = (evt.target) ? evt.target : evt.srcElement;
    var imgClass = elem.parentNode.name;         // get map element name
    var coords = elem.coords.split(",");         // convert coords to clip
    var clipVal = "rect(" + coords[1] + "px " +
    coords[2] + "px " +
    coords[3] + "px " +
    coords[0] + "px)";
    var imgStyle;
    
    switch (evt.type) {
        case "mousedown" :
            imgStyle = document.getElementById(imgClass + "Down").style;
            imgStyle.clip = clipVal;
            imgStyle.visibility = "visible";
            break;
        case "mouseout" :
            document.getElementById(imgClass + "Over").style.visibility = "hidden";
            document.getElementById(imgClass + "Down").style.visibility = "hidden";
            break;
        case "mouseover" :
            imgStyle = document.getElementById(imgClass + "Over").style;
            imgStyle.clip = clipVal;
            imgStyle.visibility = "visible";
            break
        case "mouseup" :
            document.getElementById(imgClass + "Down").style.visibility = "hidden";
            // guarantee click in IE
            if (elem.click) {
                elem.click();
            }
            break;
    }
    evt.cancelBubble = true;
    return false;
}


/* WebKit fade in, Usage: onload="fadein(id)' */
function fadein(id) {
    var element = document.getElementById(id);
    
    var fadeinWorker = function(id) {
        var element = document.getElementById(id);
        element.style.WebkitTransition  = "opacity 2s linear 0.5s";
        element.style.opacity           = 1;
    }
    
    element.style.opacity   = 0;        // fadeout first
    setTimeout(fadeinWorker, 1, [id]);  // trigger fadein after onLoad()
}


// play another song
function play(url) {
    var player = document.player;
    if(! player) {
        player  = document.getElementById('player');
    }
    // IE needs absolute urls
    /* but drupal does this for us
    if((url.search('^http://') < 0) && (url.search('^/') < 0)) {
        url = document.location.pathname + '/' + url;
    }
     */
    if(player) {
        player.SetURL(url);
        player.SetAutoPlay(true);  // can not use play as movie might not be loadded, yet
    } else {
        alert('Fehler: Kann das QuickTime plugin nicht ansprechen.');
    }
}

