// BROWSERABFRAGE
var agt      = navigator.userAgent.toLowerCase();
var isMajor  = parseInt(navigator.appVersion);
var isNav    = ((agt.indexOf('mozilla')     !=-1) && (agt.indexOf('spoofer') == -1)
             && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')   == -1)
             && (agt.indexOf('webtv')      == -1));
var isNav4   = (isNav && (isMajor == 4));
var isNav5up = (isNav && (isMajor >= 5));
var isIE     = (agt.indexOf("msie") != -1);
var isMac = (agt.indexOf("mac")>0);
var isIE5 = (navigator.appVersion.indexOf('MSIE 5') > 0 ) ? true : false;

var pageScroll = false;
var pagey,pageid;

// IMAGE ARRAYS
function initImages () {
        for (i = 1; i <= 2; i++) {
                portraits[i] = new Image();
                portraits[i].src = "images/portrait" + i + ".jpg";
        }

        for (s = 1; s <= 4; s++) {
                archi[s] = new Image();
                archi[s].src = "images/archi" + s + ".jpg";
        }
}

// image preload
function WM_preloadImages() {
/* *** vorladen von bildern in den browser-cache *** */
        if (document.images) {
                if (typeof(document.WM) == 'undefined'){
                        document.WM = new Object();
                }
                document.WM.loadedImages = new Array();
                // Loop through all the arguments.
                var argLength = WM_preloadImages.arguments.length;
                for(arg=0;arg<argLength;arg++) {
                // For each arg, create a new image.
                        document.WM.loadedImages[arg] = new Image();
                        // Then set the source of that image to the current argument.
                        document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
                }
        }
}


/* ********************** ALLGEMEINE FUNKTIONEN **** */

function getDiv(id,parentID) {
        if(isIE) {
                return document.all[id];
        }
        else if(isNav5up) {
                return document.getElementById(id);
        }
        else if(isNav4) {
                if (parentID != null) {
                        return document.layers[parentID].document.layers[id];
                }
                else {
                        return document.layers[id];
                }
        }
}

function getDivStyle(id,parentID) {
        if(isIE) {
                return document.all[id].style;
        }
        else if(isNav5up) {
                return document.getElementById(id).style;
        }
        else if(isNav4) {
                if (parentID != null) {
                        return document.layers[parentID].document.layers[id];
                }
                else {
                        return document.layers[id];
                }
        }
}

function getImage(id)
{
        if(isNav4) {
                return document.layers[id].document;
        }
}

function getForm(id,layerID) {
        if(isIE) {
                return document.all[id];
        }
        else if(isNav5up) {
                return document.getElementById(id);
        }
        else if(isNav4) {
                if (layerID != null) {
                        return document.layers[layerID].document.forms[id];
                }
                else {
                        return document.forms[id];
                }
        }
}

function showLayer(x) {
        if(isIE || isNav5up) {
                getDivStyle(x).visibility="visible";
        }
        else if(isNav4) {
                getDivStyle(x).visibility="show";
        }
}


function hideLayer(x) {
        if(isIE || isNav5up) {
                getDivStyle(x).visibility="hidden";
        }
        else if(isNav4) {
                getDivStyle(x).visibility="hide";
        }
}

function setLayerPos(obj,x,y) {
        obj.left = x;
        obj.top = y;
}

// swap image
function swapImage(id, src, x) {
        if(isIE) {
                document.all[id].src = src;
        }
        else if(isNav5up) {
                //alert(document.getElementById(id));
                //document.getElementById(id).src = src;
                document.images[id].src = src;
        }
        else if(isNav4) {
                getImage(x)[id].src = src;
        }
}

// FUNKTIONEN FÜR BILDWECHSEL UND LINK

function nextPortraitImage() {
        portraitCount++;
        if (portraitCount >= portraitMax) {
                portraitCount = 0;
        }
        if  (isIE || isNav5up) {
                document.portrait.src = portraits[portraitCount].src;
        } else if(isNav4) {
                document.layers["wuerfel"].document.portrait.src = portraits[portraitCount].src;
        }
}

function nextArchiImage() {
        archiCount++;
        if (archiCount >= archiMax) {
        //hier wurde vom JMB fuer pan-net archiCount auf 4 gesetzt, vorher 0
                archiCount = 4;
        }
        if  (isIE || isNav5up) {
                document.archi.src = archi[archiCount].src;
        }
        else if(isNav4)  {
                document.layers["wuerfel"].document.archi.src = archi[archiCount].src;
        }
}
//angepasst vom JMB fuer pan-net
function gotoPortraitUrl(filerumpf) {
        document.location = filerumpf + (portraitCount+1) + ".htm";
}
//angepasst vom JMB fuer pan-net
function gotoArchiUrl(filerumpf) {
        document.location = filerumpf + (archiCount+1) + ".htm";
}

function openWindow(seite) {
        window.open(seite, 'ganzertext', 'menubar=no,locationbar=no,personalbar=no,directories=no,scrollbars=no,width=280,height=400');
}

function closeWindow() {
        if(isIE || isNav4) {
                parent.close();
        }
        else if(isNav5up) {
                window.close();
        }
}

//steuerung des sprungbefehlmenues
function jumpMenu(id){
        self.location=id.options[id.selectedIndex].value;
}

/* ********************* NAVIGATION OBEN **** */

//Navigation-oben: mouseout-event aus submenulayer wird an die funktion hideSubmenu() weitergeleitet
function eventUmleitung(i) {
        if(isIE || isNav5up) {
                var z = 0;
                while(i[z] != null) {
                        (getDiv(i[z])).onmouseout=hideSubmenu;
                        z++;
                }
        }
        else if(isNav4) {
                var z = 0;
                while(i[z] != null)        {
                        getDiv(i[z]).captureEvents(Event.MOUSEOUT);
                        getDiv(i[z]).onmouseout=hideSubmenu;
                        z++;
                }
        }
}

//MouseOut-Umleitung von Submenulayer
// event.toElement: Objekt, auf dem sich die Maus bewegt (funktioniert nicht in netscape)
// contains(Ziel): gibt an, ob sich ein Element in einem anderen befindet!
function hideSubmenu(ereignis) {

        if(isIE || isNav5up) {
                var m = (getDiv(submenuOld));
                var x = (m.contains(event.toElement));

            //wenn layer das objekt enthält, welches das event ausgelöst hat, so passiert nichts, ansonsten 'else'
                if(x) {}
                else {
                        hideLayer(submenuOld);
                }
        }
        else if(isNav4) {
                var target = ereignis.target;

                if(target == getDiv(submenuOld)) {
                        hideLayer(submenuOld);
                }
        }
}

//Rollover über Menu
function doCheck(x) {
    if(submenuOld!=null) {
                hideLayer(submenuOld);

                if(x!=null) {
                        showLayer(x);
                        submenuOld=x;
                }
        }
        else {
                if(x) {
                        showLayer(x);
                        submenuOld=x;
                }
        }
}

//Submenupunkt wurde angeklickt
function doClick(x) {
        if(submenuOld) {
                hideLayer(submenuOld);
        }
        if(submenuClicked!=null) {
                hideLayer(submenuClicked);
                if(x) {
                        showLayer(x);
                        submenuClicked = x;
                }
        }
}

function doClickMenu(x) {
        hideLayer(submenuOld);
        if(submenuClicked!=null) {
                hideLayer(submenuClicked)
                //menuepunkt muss andere farbe kriegen!
        }
}

/* ********************* SCROLLING **** */
// scroll nach oben
function pageUp(id, y) {
        if (id) pageid = id;
        if (y) pagey = y;
        var div = getDiv(pageid);
        if(isNav5up || isIE) {
                var clipV = div.style.clip.split("rect(")[1].split(")")[0].split("px");
                if((clipV[0]) > 0) {
                        div.style.top  = parseInt(div.style.top) + pagey;
                        div.style.clip = "rect(" + (parseInt(clipV[0])-pagey) + "px " + clipV[1] + "px " + (parseInt(clipV[2])-pagey) + "px " + clipV[3] + "px)";
                }
        }
        else if(isNav4) {
                if((div.clip.top) > 0) {
                        div.top += pagey;
                        div.clip.top -= pagey;
                        div.clip.bottom -= pagey;
                }
        }
        pageScroll = setTimeout("pageUp()",50);
}

// scroll nach unten
function pageDown(id, y) {
        if (id) pageid = id;
        if (y) pagey = y;
        var div   = getDiv(pageid);
        if(isNav5up || isIE) {//neu
                var clipV = div.style.clip.split("rect(")[1].split(")")[0].split("px");
                if(parseInt(clipV[2]) < parseInt(div.offsetHeight)) {
                        div.style.top  = parseInt(div.style.top) - pagey;
                        div.style.clip = "rect(" + (parseInt(clipV[0])+pagey) + "px " + clipV[1] + "px " + (parseInt(clipV[2])+pagey) + "px " + clipV[3] + "px)";
                }
        }
        else if(isNav4) {
                if((div.clip.bottom) < (div.document.height)) {
                        div.top -= pagey;
                        div.clip.top += pagey;
                        div.clip.bottom += pagey;
                }
        }
        pageScroll = setTimeout("pageDown()",50);
}

// scroll nach links (neu)
function pageLeft(id, x) {
        if (id) pageid = id;
        if (x) pagex = x;
        var div   = getDiv(pageid);
        if(isNav5up || isIE) {//neu
                var clipV = div.style.clip.split("rect(")[1].split(")")[0].split("px");
                if(parseInt(clipV[3]) > 0) {
                        div.style.left  = parseInt(div.style.left) + pagex;
                        div.style.clip = "rect(" + clipV[0] + "px " + (parseInt(clipV[1])-pagex) + "px " + clipV[2] + "px " + (parseInt(clipV[3])-pagex) + "px)";
                }
        }
        else if(isNav4) {
                if((div.clip.left) > 0 ) {
                        div.left += pagex;
                        div.clip.left -= pagex;
                        div.clip.right -= pagex;
                }
        }
        pageScroll = setTimeout("pageLeft()",50);
}

// scroll nach rechts (neu)
function pageRight(id, x) {
        if (id) pageid = id;
        if (x) pagex = x;
        var div   = getDiv(pageid);
        if(isNav5up || isIE) {//neu
                var clipV = div.style.clip.split("rect(")[1].split(")")[0].split("px");
                if(parseInt(clipV[1]) < parseInt(div.offsetWidth)) {
                        div.style.left  = parseInt(div.style.left) - pagex;
                        div.style.clip = "rect(" + clipV[0] + "px " + (parseInt(clipV[1])+pagex) + "px " + clipV[2] + "px " + (parseInt(clipV[3])+pagex) + "px)";
                }
        }
        else if(isNav4) {
                if((div.clip.right) < (div.document.width)) {
                        div.left -= pagex;
                        div.clip.left += pagex;
                        div.clip.right += pagex;
                }
        }
        pageScroll = setTimeout("pageRight()",50);
}

function pageScrollStop() {
        if (pageScroll) {
                clearTimeout(pageScroll);
        }
        pageScroll = false;
}

// background-farbe aendern
function yearHigh(menuObject) {
                menuObject.style.background='#FFFFFF';
}

function yearLow(menuObject) {
                menuObject.style.background='#E6F3BE';
}

// home-scrolltext
function showText(id) {
        timeouts[2].triggerend = -1
        for (i=0; i<6; i++) {
                obj = getDivStyle("text"+i,"texte");
                setLayerPos(obj,433,0);
        }
        scrollText(id);
}

function scrollText(id){
        stobj = getDivStyle("text"+id,"texte");
        stx = 433;
        stvx = -10;
        stdx = -1000;
        scrollX();
}

function scrollX() {
        stx += stvx;
        if (stx > stdx) {
                setLayerPos(stobj,stx,0);
                timeouts[2].triggerend = 1
        }
}

// UNIQUE settimeout
function masterTimeout() {
        i=0;
        while(timeouts[i] != null) {
                if (timeouts[i].triggerend == ++timeouts[i].trigger && timeouts[i].triggerend != -1) {
                        timeouts[i].trigger = 0;
                        eval(timeouts[i].f);
                }

                i++;
        }
        setTimeout("masterTimeout()",100);
}

function timeoutObj(f,triggerend) {
        this.triggerend = triggerend;
        this.trigger = 0;
        this.f = f;
}

//fuer pressefotodownload-satelliten
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}