
/* ----- mediapage_javascript.js ----- */
/*
 * Javascript function collection
 * ------------------------------
 * Version  :   0.3
 * Author   :   T.Hinze (HiDeVis)
 * Date     :   22.05.2006    
 *
 """ This Javascript contains all needed JS-functions.
 """  
*/

var imgNum;

function antiLinkBorder(e) {
    /* try to remove the border around active links (i.e. in mozilla-browsers)
    */
    var allLinksInPage = window.document.getElementsByTagName("a");
    for (var idx in allLinksInPage) {
        allLinksInPage[idx].onfocus = allLinksInPage[idx].blur;
    }
}
//---------------------------

function changeImageSource(elemID, newURL, newTITLE) {
    /* try to reference the element with the id 'elemID'.
       If this element is an image object, then change the attribute
       'src' to the given newURL.
    */
    var ref = window.document.getElementById(elemID);
    //alert(elemID);
    var elemTitleID = 'ATMediaPageAutoImageTitle';
    var Textknoten = document.createTextNode(newTITLE);
    var refTitle = window.document.getElementById(elemTitleID);
    // change src of the image
    //alert(refTitle);
    if (ref && ref.tagName == "IMG") {
        ref.src = newURL;
        
        if (refTitle) {
            refTitle.replaceChild(Textknoten, refTitle.firstChild);
        }
        
        var parent  = ref.parentNode;
        //alert(newTITLE);
        if (parent.tagName == 'A') {
            // change the href of the link
            var token1      = newURL.split("/");
            var newID       = token1[token1.length - 2];
            var href        = parent.href;
            var token2      = href.split("/");
            var oldID       = token2[token2.length - 2];
            var href        = href.replace(oldID, newID);
            parent.setAttribute('href', href);
        }
    }
}
//---------------------------


function autoChangeSideImage() {
    /* This function will be called in a defined interval. At every call
       the 'src' attribute of the specified HTML-element (by id) will be
       changed with a value from the array 'allImages'.
       This array was created by the Python-script 'createAutoImagesJSCode_py.
    */
    var targetID    = "ATMediaPageAutoImage";
    var newURL      = "";
    if (allImages.length) {
        // only change if array is exists
        var allImagesLength  = allImages.length;
        newURL  = allImages[imgNum].src;
        newTITLE = allImageTitle[imgNum];
        imgNum++;
        if (imgNum >= allImagesLength) {
            imgNum = 0;
        }
        changeImageSource(targetID, newURL, newTITLE);
    }    
}

//---------------------------


function initAutoChange() {
    /* initialize the interval for automatic image change
       The variable 'autoChangeDelay ' have to setup in other scriptparts before.
    */
    imgNum = 0;
    window.setInterval("autoChangeSideImage()", autoChangeDelay);
}
//---------------------------


