 var floatingMenuId = 'nav';  
 var floatingMenu =
 {

     headerOffset: document.getElementById('header').offsetHeight + document.getElementById('header').offsetTop,
     navOffsetHeight: 10,
     _usefloatMenu: true,
     contentObj: null,
     footerObj: null,
     navOffsetLeft: 0,
     menuOffsetWidth: null,
     posOffsetWidth: 10,
     contentOffsetTop: 0,
     targetX: 0,
     targetY: 0,
     xxcnt: 0,

     hasInner: typeof(window.innerWidth) == 'number',
     hasElement: typeof(document.documentElement) == 'object'
         && typeof(document.documentElement.clientWidth) == 'number',

     menu:
         document.getElementById
         ? document.getElementById(floatingMenuId)
         : document.all
           ? document.all[floatingMenuId]
           : document.layers[floatingMenuId]
 };

 floatingMenu.move = function ()
 {

     if ( floatingMenu.nextY > floatingMenu.contentOffsetTop ){
        var foo = floatingMenu.nextY + floatingMenu.contentOffsetTop;
        if ( foo < floatingMenu.contentOffsetTop ){
            foo = floatingMenu.contentOffsetTop;
        }
        //if ( floatingMenu.xxcnt % 20 == 0 ) console.log("foo="+foo);
        //if ( floatingMenu.xxcnt % 20 == 0 ) console.log("floatingMenu.nextY="+floatingMenu.nextY);
        //if ( floatingMenu.xxcnt % 20 == 0 ) console.log("floatingMenu.contentOffsetTop="+floatingMenu.contentOffsetTop);

        if ( floatingMenu.footerObj  ) {
             var bottom = foo + floatingMenu.navOffsetHeight;
             //if ( floatingMenu.xxcnt % 20 == 0 ) console.log("footer top="+ floatingMenu.footerObj.offsetTop);
             if ( bottom >  floatingMenu.footerObj.offsetTop ){
                 foo = floatingMenu.footerObj.offsetTop - floatingMenu.navOffsetHeight ;
                 foo = foo - 20 ;
                 //if ( floatingMenu.xxcnt % 20 == 0 ) console.log("altering NextY to foo="+foo);
             }
         }

         // i do this little mod thing so the console does not go nuts printing out stuff
         if ( floatingMenu.xxcnt % 20 == 0 ){
            //console.log("foo="+foo);
            floatingMenu.xxcnt++;
         }else{
             floatingMenu.xxcnt++;
         }

         floatingMenu.menu.style.top = foo + 'px';

     }else{
         //if ( floatingMenu.xxcnt++ % 20 == 0 ) console.log("here 2");
         var foo = floatingMenu.nextY + floatingMenu.contentOffsetTop;
         if ( foo < floatingMenu.contentOffsetTop ){
             foo = floatingMenu.contentOffsetTop;
         }
         floatingMenu.menu.style.top = foo + 'px';
         //this little hack i found that is executed only in IE....
        /*@cc_on
           @if (@_win32)
               //floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
           @else
              //do nothing....
           @end
        @*/
     }
     floatingMenu.menu.style.left =  floatingMenu.navOffsetLeft + 'px';
 }

 floatingMenu.computeShifts = function ()
 {
     var de = document.documentElement;

     floatingMenu.shiftX =
         floatingMenu.hasInner
         ? pageXOffset
         : floatingMenu.hasElement
           ? de.scrollLeft
           : document.body.scrollLeft;
     if (floatingMenu.targetX < 0)
     {
         floatingMenu.shiftX +=
             floatingMenu.hasElement
             ? de.clientWidth
             : document.body.clientWidth;
     }

     floatingMenu.shiftY =
         floatingMenu.hasInner
         ? pageYOffset
         : floatingMenu.hasElement
           ? de.scrollTop
           : document.body.scrollTop;
     if (floatingMenu.targetY < 0)
     {
         if (floatingMenu.hasElement && floatingMenu.hasInner)
         {
             // Handle Opera 8 problems
             floatingMenu.shiftY +=
                 de.clientHeight > window.innerHeight
                 ? window.innerHeight
                 : de.clientHeight
         }
         else
         {
             floatingMenu.shiftY +=
                 floatingMenu.hasElement
                 ? de.clientHeight
                 : document.body.clientHeight;
         }
     }
 }

 floatingMenu.calculateCornerX = function(){
     return floatingMenu.navOffsetLeft;
 };

 floatingMenu.calculateCornerY = function()
 {

     if (floatingMenu.targetY != 'center')
         return floatingMenu.shiftY + floatingMenu.targetY;

     var height = parseInt(floatingMenu.menu.offsetHeight);
     // Handle Opera 8 problems
     var clientHeight =
         floatingMenu.hasElement && floatingMenu.hasInner
         && document.documentElement.clientHeight
             > window.innerHeight
         ? window.innerHeight
         : document.documentElement.clientHeight

     var cornerY =
         floatingMenu.hasElement
         ? (floatingMenu.hasInner
            ? pageYOffset
            : document.documentElement.scrollTop) +
           (clientHeight - height)/2
         : document.body.scrollTop +
           (document.body.clientHeight - height)/2;


     return cornerY;
 };

 floatingMenu.doFloat = function()
 {
     var stepX, stepY;

     if ( !floatingMenu._usefloatMenu) { return; }

     floatingMenu.computeShifts();

     var cornerY = floatingMenu.calculateCornerY();

     var stepY = (cornerY - floatingMenu.nextY) * .07;
     if (Math.abs(stepY) < .5) {
         stepY = cornerY - floatingMenu.nextY;
     }

     if (Math.abs(stepX) > 0 || Math.abs(stepY) > 0) {
         //commented out Jul09-2009
         //floatingMenu.nextX += stepX;
         floatingMenu.nextY += stepY;
         floatingMenu.move();
     }

     setTimeout('floatingMenu.doFloat()', 10);
 };

 // addEvent designed by Aaron Moore
 floatingMenu.addEvent = function(element, listener, handler)
 {
     if(typeof element[listener] != 'function' ||
        typeof element[listener + '_num'] == 'undefined')
     {
         element[listener + '_num'] = 0;
         if (typeof element[listener] == 'function')
         {
             element[listener + 0] = element[listener];
             element[listener + '_num']++;
         }
         element[listener] = function(e)
         {
             var r = true;
             e = (e) ? e : window.event;
             for(var i = element[listener + '_num'] -1; i >= 0; i--)
             {
                 if(element[listener + i](e) == false)
                     r = false;
             }
             return r;
         }
     }

     //if handler is not already stored, assign it
     for(var i = 0; i < element[listener + '_num']; i++)
         if(element[listener + i] == handler)
             return;
     element[listener + element[listener + '_num']] = handler;
     element[listener + '_num']++;
 };

 floatingMenu.init = function()
 {
     getSomeInitParams();
     floatingMenu.initSecondary();
     floatingMenu.doFloat();
 };

 // Some browsers init scrollbars only after
 // full document load.
 floatingMenu.initSecondary = function()
 {
     floatingMenu.computeShifts();
     floatingMenu.nextX = floatingMenu.calculateCornerX();
     floatingMenu.nextY = floatingMenu.calculateCornerY();
     floatingMenu.move();
     floatMenuMyInit(); //this function
 }

 if (document.layers)
     floatingMenu.addEvent(window, 'onload', floatingMenu.init);
 else
 {
     floatingMenu.init();
     floatingMenu.addEvent(window, 'onload',
         floatingMenu.initSecondary);
 }
