var menusBottomline=new Array();
var menuBottomResetTimer=null;
var menuBottomLastY;
var menuBottomOffset;
var menuBottomToShow=-1; // IE/Mac OSX bugfix only

var isKonqueror=false;
var isMsie=false;
var isMsieMac=false;
var isMsieMacClassic=false;
var isMsieMac50Classic=false;
var isMsieMacOSX=false;
var isNS6=false;
var menuBottomMacIE50Offset=0;
var menuBottomNS4On=false;
var menuBottomMacIE50On=false;
var menuBottomScrollFactor=.3;



if (navigator.userAgent.indexOf('MSIE')>=0) {
    isMsie=true;
}

if (navigator.userAgent.indexOf('Konqueror')>=0) {
    isKonqueror=true;
}

if ((navigator.userAgent.indexOf('MSIE')>=0) && (navigator.platform=='MacPPC')) {
        isMsieMac=true;
        for (var i=0; i<navigator.plugins.length; i++) {
                if (navigator.plugins[i].name.indexOf('Carbon.cfm')>=0) {
                        isMsieMacOSX=true;
                        break
                }
        };
        if (isMsieMacOSX==false) {
                isMsieMacClassic=true;
                if ((isMsieMacClassic) && (navigator.userAgent.indexOf('MSIE 5.0')>=0)) {
                        isMsieMac50Classic=true;
                        // workaround for nested table bug
                        menubarTop-=112;
                        if (menuBottomMacIE50On) menuBottomMacIE50Offset=17
                }
        }
}
else if ((navigator.userAgent.indexOf('Gecko')>-1) && (navigator.userAgent.indexOf('Netscape6')>-1) && (navigator.userAgent.indexOf('compatible')<0)) {
        isNS6=true
}



function menuBottomActivate() {
        menuBottomOffset=menuBottomLineHeight;
        menuBottomLastY=menuGetWinHeight()+menuGetScrollY()-menuBottomOffset;
        menuDivMove(menuBottomDiv,0,menuBottomLastY);
        menuBottomResetTimer=setInterval('menuBottomKeepPos()',20)
}



//function menuGetWinHeight_OLD() {
//        if (self.innerHeight) {
//                return parseInt(self.innerHeight,10)
//        }
//        else if ((document.body) && (document.body.clientHeight)) {
//                return parseInt(document.body.clientHeight,10)
//        }
//        else if (self.height) {
//                return parseInt(self.height,10)
//        }
//        else {
//                return 0
//        }
//}
function menuGetWinHeight() {
	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}



//function menuGetScrollY_OLD() {
//        var y=0;
//        if ((document.body) && (document.body.scrollTop)) y=parseInt(document.body.scrollTop)
//        else if (window.pageYOffset) y=parseInt(self.pageYOffset);
//        return y
//}
function menuGetScrollY(){

	var yScroll = 0;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}



function menuDivMove(d,x,y) {
//		document.getElementById('debug').innerHTML = d + "<br>" + x + "<br>" + y;
        if (document.layers) {
                if (document.layers[d]) document.layers[d].moveTo(x,y);
        }
        else if (document.getElementById) {
                var obj=document.getElementById(d);
                if (obj) {
                        obj.style.left=x+'px';
                        obj.style.top=y+'px'
                }
        }
        else if (document.all) {
                var obj=document.all[d];
                if (obj) {
                        obj.style.left=x+'px';
                        obj.style.top=y+'px'
                }
        }
}

function menuGetCenterX(w) {
        // opera && ns 6.0-6.1 win center fix; include offset for scrollbars
        if (((window.opera)||(isKonqueror)) && (document.body.scrollHeight>document.body.offsetHeight)) w+=16
        else if ((isNS6) && (document.height>menuGetWinHeight())) w+=16;
        return Math.max(0,Math.floor(menuGetWinWidth()-w)/2)
}

function menuBottomKeepPos() {
        var x=0;
        var y=menuGetWinHeight()+menuGetScrollY()-menuBottomOffset;
        var dy=(y-menuBottomLastY)*menuBottomScrollFactor;
//		document.getElementById('debug').innerHTML = 'menuGetWinHeight()=' + menuGetWinHeight() + "<br>menuGetScrollY()=" + menuGetScrollY();
        menuBottomLastY+= (dy > 0)? Math.ceil(dy) : Math.floor(dy);
        if ((window.opera) || (isNS6) || (isKonqueror)) {
                // opera, NS6 center fix
                menuDivMove(menubarDiv,menuGetCenterX(menubarWidth),menubarTop);
                x=menuGetCenterX(menuBottomWidth);
        };
        if (isMsieMac50Classic) menuBottomLastY-=menuBottomMacIE50Offset;
        menuDivMove(menuBottomDiv,x,menuBottomLastY);

}
