﻿// OS
var system = 'pc'; // pc as default

if ((navigator.appVersion.indexOf('Lin') != -1)
        || (navigator.appVersion.indexOf('X11') != -1)) {
    system = 'lin';
} else if (navigator.appVersion.indexOf('Mac') != -1) {
    system = 'mac';
}

// browsertyp
function Client() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.isNS = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
    this.isNS4 = (this.isNS && (this.major < 5));
    this.isNS6 = (this.isNS && (this.major >= 5));
    this.isIE = (agent.indexOf("msie") != -1);
    this.name = 'default';

    this.browser = -1;

    // this.NS = 0;
    this.NS4 = 0;
    this.NS6 = 1;
    this.IE = 2;

    if (this.isNS4) {
        this.browser = this.NS4;
        this.name = 'ns_' + system;
    } else if (this.isNS6) {
        this.browser = this.NS6;
        this.name = 'ns6_' + system;
    } else if (this.isIE) {
        this.browser = this.IE;
        this.name = 'ie_' + system;
    }
}
var client = new Client();

// set helper variables to access layers and style attributes
// more convenient
var doc = "";
var sty = "";

if (client.isNS4) {
    doc = "document.";
    sty = "";
} else if (client.isNS6) {
    doc = "document.";
    sty = "";
} else if (client.isIE) {
    doc = "document.all.";
    sty = ".style";
}





var menuInitialSelection = -1;
// var menuTop = 0;

function initSecNavi() {
    updateSecNavi(menuInitialSelection);
    var secRow = 0;
    if (client.isNS4) {
        while (document['s' + secRow]) {
            document['s' + secRow].visibility = "visible";
            secRow++;
        }

    } else if (client.isIE) {
        while (document.all['s' + secRow]) {
            document.all['s' + secRow].style.visibility = "visible";
            secRow++;
        }
    } else if (client.isNS6) {
        while (document.getElementById('s' + secRow)) {
            document.getElementById('s' + secRow).style.visibility = "visible";
            secRow++;
        }
    }

}

function updateSecNavi(sel) {

    var intSel = parseInt(sel);
    var y = menuTop;
    var secRow = 0;

    if (client.isNS4) {
        while (document['s' + secRow]) {
            document['s' + secRow].top = y;
            y += document['s' + secRow].document.height;
            if (secRow == intSel) {
                if (document['s' + secRow + 't']) {
                    document['s' + secRow + 't'].top = y;
                    y += document['s' + secRow + 't'].document.height;
                    document['s' + secRow + 't'].visibility = "visible";
                }
            } else {
                if (document['s' + secRow + 't']) {
                    document['s' + secRow + 't'].visibility = "hidden";
                }
            }

            secRow++;
        } // while
    } else if (client.isIE) {
        while (document.all['s' + secRow]) {
            document.all['s' + secRow].style.posTop = y;
            y += document.all['s' + secRow].offsetHeight;
            if (secRow == intSel) {
                if (document.all['s' + secRow + 't']) {
                    document.all['s' + secRow + 't'].style.posTop = y;
                    y += document.all['s' + secRow + 't'].offsetHeight;
                    document.all['s' + secRow + 't'].style.visibility = "visible";
                }
            } else {
                if (document.all['s' + secRow + 't']) {
                    document.all['s' + secRow + 't'].style.visibility = "hidden";
                }
            }

            secRow++;
        } // while
    } else if (client.isNS6) {
        while (document.getElementById('s' + secRow)) {
            document.getElementById('s' + secRow).style.top = y;
            y += parseInt(document.getElementById('s' + secRow).offsetHeight);
            if (secRow == intSel) {
                if (document.getElementById('s' + secRow + 't')) {
                    document.getElementById('s' + secRow + 't').style.top = y;
                    y += parseInt(document.getElementById('s' + secRow + 't').offsetHeight);
                    document.getElementById('s' + secRow + 't').style.visibility = "visible";
                }
            } else {
                if (document.getElementById('s' + secRow + 't')) {
                    document.getElementById('s' + secRow + 't').style.visibility = "hidden";
                }
            }

            secRow++;
        } // while
    }

    return false; // no link to follow
}





function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function P7_autoLayers() { //v1.2 by PVII
    var g, b, k, f, args = P7_autoLayers.arguments;
    var a = parseInt(args[0]); if (isNaN(a)) a = 0;
    if (!document.p7setc) {
        p7c = new Array(); document.p7setc = true;
        for (var u = 0; u < 10; u++) { p7c[u] = new Array(); } 
    }
    for (k = 0; k < p7c[a].length; k++) {
        if ((g = MM_findObj(p7c[a][k])) != null) {
            b = (document.layers) ? g : g.style; b.visibility = "hidden";
        } 
    }
    for (k = 1; k < args.length; k++) {
        if ((g = MM_findObj(args[k])) != null) {
            b = (document.layers) ? g : g.style; b.visibility = "visible"; f = false;
            for (j = 0; j < p7c[a].length; j++) {
                if (args[k] == p7c[a][j]) { f = true; } 
            }
            if (!f) { p7c[a][p7c[a].length++] = args[k]; } 
        } 
    }
}





//Positionierung des JS-Scrollers fuer Product

var locHContent = "0";
var locVContent = "0";
var widthContent = "441";
var heightContent = "408";

var locHBar = "478";
var locVBar = "178";
var widthBar = "1";
var heightBar = "386";

var locHThumb = "474";
var locVThumb = "50";
var widthThumb = "9";
var heightThumb = "";

var locHUpArrows = "470";
var locVUpArrows = "164";
var widthUpArrows = "";
var heightUpArrows = "";

var locHDownArrows = "470";
var locVDownArrows = "564";
var widthDownArrows = "";
var heightDownArrows = "";

var pageMinW = 309;
var pageMinH = 370;



// *** COMMON CROSS-BROWSER COMPATIBILITY CODE ***

var isDOM = document.getElementById ? 1 : 0;
var isIE = document.all ? 1 : 0;
var isNS4 = (navigator.appName == 'Netscape' && !isDOM) ? 1 : 0;
var isIE4 = (isIE && !isDOM) ? 1 : 0;
var isWin = (navigator.platform.indexOf('Win') != -1) ? 1 : 0;
var isDyn = (isDOM || isIE4 || isNS4);

function getRef(id, par) {
    par = !par ? document : (par.navigator ? par.document : par);
    return (isIE ? par.all[id] :
  (isDOM ? (par.getElementById ? par : par.ownerDocument).getElementById(id) :
  par.layers[id]));
}

function getSty(id, par) {

    if (getRef(id, par).style == null) {
        return getRef(id, par)
    } else {
        return (isNS4 ? getRef(id, par) : getRef(id, par).style);
    }


}


if (!window.LayerObj) var LayerObj = new Function('id', 'par',
 'this.ref=getRef(id, par); this.sty=getSty(id, par); return this');
function getLyr(id, par) { return new LayerObj(id, par) }

function LyrFn(fn, fc) {
    LayerObj.prototype[fn] = new Function('var a=arguments,p=a[0]; with (this) { ' + fc + ' }');
}

LyrFn('x', 'if (!isNaN(a[0])) sty.left=p; else return parseInt(sty.left)');
LyrFn('y', 'if (!isNaN(a[0])) sty.top=p; else return parseInt(sty.top)');
LyrFn('w', 'if (p) (isNS4?sty.clip:sty).width=p; ' +
 'else return (isNS4?ref.document.width:ref.offsetWidth)');
LyrFn('h', 'if (p) (isNS4?sty.clip:sty).height=p; ' +
 'else return (isNS4?ref.document.height:ref.offsetHeight)');
LyrFn('vis', 'sty.visibility=p');
LyrFn('clip', 'if (isNS4) with(sty.clip) { left=a[0]; top=a[1]; right=a[2]; bottom=a[3] } ' +
 'else sty.clip="rect("+a[1]+"px "+a[2]+"px "+a[3]+"px "+a[0]+"px)" ');


if (!window.page) var page = { win: window, minW: 0, minH: 0, MS: isIE && !window.opera }

page.winW = function()
{ with (this) return Math.max(minW, MS ? win.document.body.clientWidth : win.innerWidth) }
page.winH = function()
{ with (this) return Math.max(minH, MS ? win.document.body.clientHeight : win.innerHeight) }

// *** LOAD FILES INTO DIV FUNCTIONS ***

function scrLoad(fName) {
    with (this) {
        if (!fName || !loaded || !isDyn) return;
        loadingFile = fName;
        if (onbeforeload) onbeforeload();
        if (isIE || isDOM) with (bufRef.document) {
            write('<html><body onload="parent.' + myName + '.fileLoaded()">' +
   '<iframe name="nestBuf" src="' + fName + '"></iframe></body></html>');
            close();
            if (!bufRef.nestBuf || (isIE4 && !isWin)) {
                bufRef.location.href = fName;
                setTimeout(myName + '.fileLoaded()', 5000);
            }
        }
        else if (isNS4) {
            if (window.ns4LayerLoading) {
                setTimeout(myName + '.load("' + fName + '")', 100);
                return;
            }
            window.ns4LayerLoading = true;
            div.ref.onload = new Function(myName + '.fileLoaded()');
            div.ref.load(fName, cWidth);
        }
    } 
}

function scrFileLoaded() {
    with (this) {
        activeScr = null;
        if (isNS4) window.ns4LayerLoading = false;
        if ((isDOM || isIE) && loadingFile) {
            var bufDoc = bufRef.nestBuf ? bufRef.nestBuf.document : bufRef.document;
            if (bufDoc && bufDoc.body) div.ref.innerHTML = bufDoc.body.innerHTML;
            bufRef.location.replace('about:blank');
        }
        loadedFile = loadingFile;
        if ((stick != 1) && !stickTimer) stickTimer = setInterval(myName + '.stickScroll()', 30);
        setTimeout('with(' + myName + ') { scrollTo(0); if (onload) onload() }', 1);
    } 
}

// *** DIV SCROLLING FUNCTIONS ***

function scrScrollTo(pos, isStick) {
    with (this) {
        if (!isDyn || !loaded) return;
        cTop = parseInt(pos);
        if (!isStick) stickTop = cTop;
        divHeight = div.h() + padTop + padBot;
        if (divHeight == 0) divHeight = 1;
        if (checkBounds) {
            if (cTop + cHeight > divHeight) cTop = divHeight - cHeight;
            if (cTop < 0) cTop = 0;
        }
        div.y(eval(divs[0].y) - cTop + padTop);
        div.clip(0, cTop - padTop, cWidth, cTop - padTop + cHeight);



        thmHeight = 22;
        if (thmHeight < minThmHeight) thmHeight = minThmHeight;
        if (thmHeight > barHeight) thmHeight = barHeight;
        thm.h(thmHeight);
        //thm.h(22);



        if (onscroll) onscroll();
        if (activeScr) return;
        var fracDivDown = (cTop / (divHeight - cHeight));
        thm.y(bar.y() + fracDivDown * (barHeight - thmHeight));
    } 
}

function scrScrollBy(amount) {
    with (this) {
        scrollTo(cTop + amount);
        if (loop) setTimeout(myName + '.scrollBy(' + amount + ')', loop);
    } 
}

// *** SCROLL THUMB DRAGGING EVENT HANDLERS ***

function scrThumbDown(evt) {
    with (this) {
        activeScr = this;
        dragOffset = (isIE ? event.offsetY : evt.layerY);
        if (onthumbdown) onthumbdown();
        return false;
    } 
}

function scrThumbMove(evt) {
    if (!activeScr) return true;
    else with (activeScr) {
        if ((cTop + cHeight > divHeight) || (thmHeight == barHeight)) return true;
        var thmTop = (isIE ? document.body.scrollTop + event.clientY : evt.pageY) - dragOffset - bar.y();
        if (thmTop < 0) thmTop = 0;
        if (thmTop + thmHeight > barHeight) thmTop = barHeight - thmHeight;
        thm.y(bar.y() + thmTop);
        stickTop = (divHeight - cHeight) * (thmTop / (barHeight - thmHeight));
        if (stick == 1) scrollTo(stickTop);
        return false;
    }
}

function scrStickScroll() {
    with (this) {
        if (Math.abs(cTop - stickTop) > 2) {
            cTop += (stickTop - cTop) * stick;
            scrollTo(cTop, true);
        }
        else if (cTop != stickTop) {
            cTop = stickTop;
            scrollTo(cTop, true);
        }
    } 
}

function scrThumbUp(evt) {
    if (activeScr) with (activeScr) if (onthumbup) onthumbup();
    activeScr = null;
}

// *** SCROLLBAR BACKGROUND CLICK EVENT HANDLER ***

function scrBarClick(evt) {
    with (this) {
        if (isIE) clickPos = document.body.scrollTop + event.clientY;
        else clickPos = evt.pageY;
        if (clickPos < thm.y()) scrollBy(0 - cHeight);
        if (clickPos > (thm.y() + thmHeight)) scrollBy(cHeight);
        if (isNS4) return document.routeEvent(evt);
    } 
}

// *** LAYOUT HANDLER FOR WINDOW RESIZE ETC ***

function scrLayout() {
    with (this) {

        if (!isDyn || !loaded) return;

        for (var i = 0; i < divs.length; i++) with (divs[i].lyr) {
            x(eval(divs[i].x)); w(Math.max(0, eval(divs[i].w)));
            if (i) { y(eval(divs[i].y)); h(Math.max(0, eval(divs[i].h))) }
        }
        barHeight = eval(divs[1].h);
        cWidth = eval(divs[0].w);
        cHeight = eval(divs[0].h);
        if (onlayout) onlayout();
        scrollBy(0);
    } 
}

// *** ON LOAD: CAPTURE EVENTS & MISC. SETUP ***

function scrSetup(defaultFile) {
    with (this) {
        if (!isDyn) return;
        for (var i = 0; i < divs.length; i++)
            divs[i].lyr = getLyr(divs[i].id, eval(divs[i].par));
        div = divs[0].lyr;
        bar = divs[1].lyr;
        thm = divs[2].lyr;
        if (!isNS4) bufRef = eval('window.' + myName + 'Buf');
        if (isNS4) {
            bar.ref.captureEvents(Event.CLICK);
            thm.ref.captureEvents(Event.MOUSEDOWN);
        }

        bar.ref.onclick = new Function('evt', 'return ' + myName + '.barClick(evt)');
        thm.ref.onmousedown = new Function('evt', 'return ' + myName + '.thumbDown(evt)');

        var noSel = new Function('if (activeScr) return false');
        if (isIE) document.onselectstart = noSel;
        else if (isDOM) document.onselect = noSel;

        loaded = true;
        layout();
        if (onsetup) onsetup();

        var fileName = ''
        var URL = location.search.substring(1);
        if (URL) {
            URL = URL.split('&');
            for (var i = 0; i < URL.length; i++)
                if (URL[i].split('=')[0] == myName) fileName = URL[i].split('=')[1];
        }
        if (fileName.indexOf('.htm') != -1) load(fileName)
        else if (defaultFile) load(defaultFile);
        else fileLoaded();
    } 
}

// *** SCROLLER OBJECT CONSTRUCTOR FUNCTIONS ***

function addProps(obj, data, names, addNull) {
    for (var i = 0; i < names.length; i++) if (i < data.length || addNull) obj[names[i]] = data[i];
}

function DHTMLScroller() {
    var names = ['myName', 'bufRef', 'div', 'bar', 'thm', 'loaded', 'loop', 'divHeight', 'thmHeight',
  'barHeight', 'cHeight', 'cWidth', 'dragOffset', 'onbeforeload', 'onload', 'onscroll', 'onsetup',
  'onlayout', 'onthumbdown', 'onthumbup'];
    addProps(this, arguments, names, true);
    this.cTop = 0;
    this.loadingFile = '';
    this.loadedFile = '';
    this.divs = new Array();
    this.minThmHeight = 20;
    this.padTop = 0;
    this.padBot = 0;
    this.checkBounds = true;
    this.stick = 1;
    this.stickTop = 0;
    this.stickTimer = null;
    this.load = scrLoad;
    this.fileLoaded = scrFileLoaded;
    this.scrollTo = scrScrollTo;
    this.scrollBy = scrScrollBy;
    this.thumbDown = scrThumbDown;
    this.stickScroll = scrStickScroll;
    this.barClick = scrBarClick;
    this.setup = scrSetup;
    this.layout = scrLayout;
}

var activeScr = null;

function ScrDiv() {
    addProps(this, arguments, ['id', 'x', 'y', 'w', 'h', 'par', 'lyr'], true);
}

// *** SCROLLER OBJECT SETUP -- START EDITING HERE, keep reading until bottom of file ***.

var mainDiv = new DHTMLScroller('mainDiv');

with (mainDiv) {

    divs[0] = new ScrDiv('mid-colContent', locHContent, locVContent, widthContent, heightContent);
    divs[1] = new ScrDiv('mainDivBar408', locHBar, locVBar, widthBar, heightBar);
    divs[2] = new ScrDiv('mainDivThumb408', locHThumb, '', widthThumb, '');
    divs[3] = new ScrDiv('scrollUpContent408', locHUpArrows, locVUpArrows, '', '');
    divs[4] = new ScrDiv('scrollDownContent408', locHDownArrows, locVDownArrows, '', '');

    page.minW = pageMinW;
    page.minH = pageMinH;


    onlayout = thumbVis;
}



function thumbVis() {
    with (this)

        if (div.h() > eval(divs[0].h)) {
        divs[2].lyr.vis('visible');
        divs[3].lyr.vis('visible');
        divs[4].lyr.vis('visible');
    }
    else if (isNS4) {
        divs[1].lyr.vis('hide');
        divs[2].lyr.vis('hide');
        divs[3].lyr.vis('hide');
        divs[4].lyr.vis('hide');
    }
    else {
        divs[1].lyr.vis('hidden');
        divs[2].lyr.vis('hidden');
        divs[3].lyr.vis('hidden');
        divs[4].lyr.vis('hidden');
    }
}

/*
function thumbVis() { with (this)
{ 
if (div.h() > eval(divs[0].h)) divs[2].lyr.vis('visible');
else divs[2].lyr.vis('hidden');
}}
*/

window.onresize = function() {
    ns4BugCheck();
    mainDiv.layout();
}

if (isNS4) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);

document.onmousemove = function(evt) {
    var ret = scrThumbMove(evt);
    return (ret ? (isNS4 ? document.routeEvent(evt) : true) : false);
}

document.onmouseup = function(evt) {
    scrThumbUp(evt);
    if (isNS4) return document.routeEvent(evt);
}

var nsWinW = window.innerWidth, nsWinH = window.innerHeight;
function ns4BugCheck() {
    if (isNS4 && (nsWinW != innerWidth || nsWinH != innerHeight)) {
        var fileName = location.href;
        if (fileName.indexOf('?') != -1) fileName = fileName.substring(0, fileName.indexOf('?'));
        location.href = fileName + '?mainDiv=' + mainDiv.loadedFile;
    }
}


