﻿

if (window.addEventListener) { 
    window.addEventListener("load", Menu_Adjust, false);    
}
else {
    if (window.attachEvent) {
       window.attachEvent("onload", Menu_Adjust);
    }
    else {
        try {
           window.onload = Menu_Adjust();           
        }
        catch (ex) { }
    }
}

/*
    Q&D !
*/
function Menu_Adjust() {
    var objPageTopMenu = document.getElementById('PageTopMenu');
    var objMenu = document.getElementById('Menu');
    var objMenuFirstNav = document.getElementById('M_0');
    var obj = document.getElementById('jsPosCalc');

    //var objPosOffset = findPos(objPageTopMenu)[0];
    var objPosStart = findPos(objMenuFirstNav)[0]; // objPosOffset + 10 + 50;
    var objPosEnd = findPos(obj)[0];

    var objWidth = objPosEnd - objPosStart;

    var objPosLeft = parseInt((830 - objWidth) / 2);
    objMenu.style.marginLeft = 40 + objPosLeft + 'px';

    if (document.getElementById('isIE6').value == '1') {
        enableMenuIE6();
    }
}

function enableMenuIE6() {
    if (document.all && document.getElementById) {
        try {
            var navRoot = document.getElementById("Menu");
            var aLiEl = navRoot.getElementsByTagName("li");
            for (i = 0; i < aLiEl.length; i++) {
                var node = aLiEl[i];
                node.onmouseover = function () {
                    this.className += " over";
                }
                node.onmouseout = function () {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
        catch (e) {alert("2");}
    }
}


// Twitter+FB
function changeLinkImage(objID, sAction) {
    var obj = document.getElementById(objID);
    if (sAction == '1') {
        obj.src = obj.src.replace(/.png/, '_hover.png');
    }
    else {
        obj.src = obj.src.replace(/_hover.png/, '.png');
    }
}


/*
A general purpose fct for getting an elements position.
*/
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            if (obj.id == 'bodyID') { break; }
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else if (window.opera) {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.scrollHeight;

    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}


