
/* Script by: www.jtricks.com  
 * Version: 20071127  
 * Latest version:  
 * www.jtricks.com/javascript/navigation/fixed_menu.html  
 */ 
 function fixedDiv(element) {
this.fixedMenuId = element;   
  
 this.fixedMenu =    
{   
    hasInner: typeof(window.innerWidth) == 'number',   
    hasElement: document.documentElement != null  
       && document.documentElement.clientWidth,   
  
    menu: document.getElementById   
        ? document.getElementById(this.fixedMenuId)   
        : document.all   
          ? document.all[this.fixedMenuId]   
          : document.layers[this.fixedMenuId]   
};   
  
this.computeShifts = function()   
{   
    this.fixedMenu.shiftX = this.fixedMenu.hasInner   
        ? pageXOffset   
        : this.fixedMenu.hasElement   
          ? document.documentElement.scrollLeft   
          : document.body.scrollLeft;   
    if (this.fixedMenu.targetLeft > 0)   
        this.fixedMenu.shiftX += this.fixedMenu.targetLeft;   
    else  
    {   
        this.fixedMenu.shiftX +=    
            (this.fixedMenu.hasElement   
              ? document.documentElement.clientWidth   
              : this.fixedMenu.hasInner   
                ? window.innerWidth - 20   
                : document.body.clientWidth)   
            - this.fixedMenu.targetRight   
            - this.fixedMenu.menu.offsetWidth;   
    }   
  
    this.fixedMenu.shiftY = this.fixedMenu.hasInner   
        ? pageYOffset   
        : this.fixedMenu.hasElement   
          ? document.documentElement.scrollTop   
          : document.body.scrollTop;   
    if (this.fixedMenu.targetTop > 0)   
        this.fixedMenu.shiftY += this.fixedMenu.targetTop;   
    else  
    {   
        this.fixedMenu.shiftY +=    
            (this.fixedMenu.hasElement   
            ? document.documentElement.clientHeight   
            : this.fixedMenu.hasInner   
              ? window.innerHeight - 20   
              : document.body.clientHeight)   
            - this.fixedMenu.targetBottom   
            - this.fixedMenu.menu.offsetHeight;   
    }   
};   
  
this.moveMenu = function()   
{   
    var temp = (this.fixedMenu)? this:this.floatingContainer;
    temp.computeShifts();   
    
    if (temp.fixedMenu.currentX != temp.fixedMenu.shiftX   
        || temp.fixedMenu.currentY != temp.fixedMenu.shiftY)   
    {   
        temp.fixedMenu.currentX = temp.fixedMenu.shiftX;   
        temp.fixedMenu.currentY = temp.fixedMenu.shiftY;   
  
        if (document.layers)   
        {   
            temp.fixedMenu.menu.left = 9+temp.fixedMenu.currentX;   
            temp.fixedMenu.menu.top = -163 +temp.fixedMenu.currentY;   
        }   
        else  
        {   
            temp.fixedMenu.menu.style.left =  temp.fixedMenu.currentX + 'px';   
            temp.fixedMenu.menu.style.top =   temp.fixedMenu.currentY + 'px';  
            temp.fixedMenu.menu.style.right = ''; 
            temp.fixedMenu.menu.style.bottom = ''; 
            
            //panelDimension = 'panelDimension :('+temp.fixedMenu.menu.style.left+','+temp.fixedMenu.menu.style.top+') ('+temp.fixedMenu.menu.style.right+','+temp.fixedMenu.menu.style.bottom+')';
            //alert(panelDimension);
            //update the position again, so that in the current visible screen , 
            //the tab is at the same position(in the previous visible screen) as it was  before the scroll
            temp.fixedMenu.menu.style.left =  '';   
            temp.fixedMenu.menu.style.top =   '';  
            temp.fixedMenu.menu.style.right = temp.fixedMenu.targetRight; 
            temp.fixedMenu.menu.style.bottom = temp.fixedMenu.targetBottom;           
        }   
    }   
  
    //temp.fixedMenu.menu.style.right = '';   
    //temp.fixedMenu.menu.style.bottom = '';   
    
    
};   
  
this.floatMenu = function()   
{   
    this.moveMenu();   
    setTimeout('this.floatMenu()', 20);   
};   
  
// addEvent designed by Aaron Moore   
this.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 = 0; i < element[listener + '_num']; 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']++;   
};   
  
this.supportsFixed = function()   
{   
    var testDiv = document.createElement("div");   
    testDiv.id = "testingPositionFixed";   
    testDiv.style.position = "fixed";   
    testDiv.style.top = "0px";   
    testDiv.style.right = "0px";   
    document.body.appendChild(testDiv);   
    var offset = 1;   
    if (typeof testDiv.offsetTop == "number"  
        && testDiv.offsetTop != null    
        && testDiv.offsetTop != "undefined")   
    {   
        offset = parseInt(testDiv.offsetTop);   
    }   
    if (offset == 0)   
    {   
        return true;   
    }   
  
    return false;   
};   
  
this.init = function()   
{	
    var temp = (this.fixedMenu)? this:this.floatingContainer;
    if (temp.fixedMenu.menu == null) {
        temp.fixedMenu.menu= document.getElementById   
            ? document.getElementById(temp.fixedMenuId)   
            : document.all   
              ? document.all[temp.fixedMenuId]   
          : document.layers[temp.fixedMenuId] 
          }
    if (temp.supportsFixed())   
        temp.fixedMenu.menu.style.position = "fixed";   
    else  
    {   
        var ob =    
            document.layers    
            ? temp.fixedMenu.menu    
            : temp.fixedMenu.menu.style;   
  
        temp.fixedMenu.targetLeft = parseInt(ob.left);   
        temp.fixedMenu.targetTop = parseInt(ob.top);   
        temp.fixedMenu.targetRight = parseInt(ob.right);   
        temp.fixedMenu.targetBottom = parseInt(ob.bottom);   
  
        if (document.layers)   
        {   
            menu.left = 0;   
            menu.top = 0;   
        }   
        temp.floatMenu();   
    }   
};   
  

}