/* 
  ------------------------------------------------
  PVII Equal CSS Columns scripts -Version 2
  Copyright (c) 2005 Project Seven Development
  www.projectseven.com
  Version: 2.1.0
  ------------------------------------------------
 */
var footerElement = null;

function P7_colH2(){ //v2.1.0 by PVII-www.projectseven.com
    var i;  // Coutner variable
    var oh; // Temp storage for offset height
    var h=0; // Tallest element
    var tg;
    var el;
    var np;  // Difference between the height of an element and the tallest element.
    var dA=document.p7eqc;  // Array of document elements
    var an=document.p7eqa;
    
    if(dA&&dA.length){
        
        // Set the padding of each of the target elements to nothing.
        for(i=1;i<dA.length;i+=2){
            dA[i+1].style.paddingBottom='';
        }
        

        // Start the height as the height of the viewport
        h=getWindowHeight()-4;
        
        // Remove the top of the lowest element in the element list
        var lowestElementTop = 0;
        var currElementTop = 0;
        for(i=1;i<dA.length;i+=2){
            currElementTop = getElementTop(dA[i]);
            lowestElementTop = (currElementTop>lowestElementTop) ? currElementTop : lowestElementTop;
        }    

        h -= lowestElementTop; 

        // Footer needs to be absolute on FF
        if(document.addEventListener) footerElement.style.position = "absolute";
        
        // Remove the height of the footer
        h -= footerElement.offsetHeight;
      
        if(document.addEventListener) footerElement.style.position = "relative";
        
        // Find the tallest element.
        for(i=1;i<dA.length;i+=2){
            oh=dA[i].offsetHeight;
            h=(oh>h)?oh:h;
        }
        
        for(i=1;i<dA.length;i+=2) {
            // If the height of the element isn't as tall as the highest element.
            oh=dA[i].offsetHeight;
            if(oh<h) {
                // Height difference
                np=h-oh;
             if(!an&&dA[0]==1){
                 P7_eqA2(dA[i+1].id,0,np);
             }
             else{
                 dA[i+1].style.paddingBottom=np+"px";
             }
            }
        }
        document.p7eqa=1;
        document.p7eqth=document.body.offsetHeight;
        document.p7eqtw=document.body.offsetWidth;
    }
}

function P7_eqT2(){ //v2.1.0 by PVII-www.projectseven.com
    if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){
        P7_colH2();
    }
}
function P7_equalCols2(){ //v2.1.0 by PVII-www.projectseven.com
    var c,e,el;
    if(document.getElementById){
        document.p7eqc=new Array();
        document.p7eqc[0]=arguments[0];
    
        // Modified - Get Footer
        footerElement = document.getElementById(arguments[0]);

        // Modified - Arguments Length = 2
        for(i=2;i<arguments.length;i+=2){
            el=null;
            c=document.getElementById(arguments[i]);
            if(c){
                e=c.getElementsByTagName(arguments[i+1]);
                if(e){
                    el=e[e.length-1];
                    if(!el.id){
                        el.id="p7eq"+i;
                    }
                }
            }
            if(c&&el){
                document.p7eqc[document.p7eqc.length]=c;
                document.p7eqc[document.p7eqc.length]=el;
            }
        }
        setInterval("P7_eqT2()",10);}
}

function P7_eqA2(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
    var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
    g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
    setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
}


/*
 * This function is taken from Bobby van der Sluis' article.
 * It has been modified to make it work properly in Firefox and Opera.
 */
function getWindowHeight() {
    var windowHeight=0;
    
    // DOM Complient browsers like Firefox use the innerHeight proerty to store the window height.
    if (typeof(window.innerHeight)=='number') {
        windowHeight = window.innerHeight;
        
        // The Horizontal scrollbar is part of the viewport for Firefox and Opera
        // So, if the horizontal scrollbar is in place then it needs to be removed from the total height.
        
        // Determine if the bottom scrollbar is in place
        // It will be in place if any of the element right edge are greater than the windows width
        // Go through each element and see if any of their right edges is past the edge of the viewport.
        var allElements = document.all || document.body.getElementsByTagName("*");
        var windowWidth = window.innerWidth + 4;
        
        for (var i = 0; i < allElements.length; i++) {
            // Using text nodes causes a problem in Opera so exclude them.
            if(allElements[i].nodeType != 3 && getRight(allElements[i]) > windowWidth) {
                // Remove scrollbar height from windowHeight
                windowHeight -= 20;
                break;
            }
        }
    }
    
    // Non-standard browsers like Internet Explorer use the clientHeight proerty to store the window height.
    // Also IE6 places this proerty on the document.documentElement when a <!DOCTYPE> is used so this needs to be taken into account as well.
    else if (document.documentElement && document.documentElement.clientHeight) {
        windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
    }
    return windowHeight;
}


/*
 * This is a utility function that gets the top y cordinate of the input element.
 */
function getElementTop(element) { 
    // Top of element.
    var y = 0;
    
    // Total width of all borders.
    var borderTopWidth = 0;
    
    // Element style.
    var style = (window.getComputedStyle) ? window.getComputedStyle(element, null) : element.currentStyle;
    
    // Itterate through the offsertParents of the element to use their offsets so the position isn't just relative to parents.
    for(var e = element; e; e=e.offsetParent) {
        y += e.offsetTop;
        
        // Also add any borders to the offset.
        //if(style.borderTopWidth) borderTopWidth += parseInt(style.borderTopWidth) || 0;
    }
    
    // Check if any of the ancestors of the element have scrollbars.  Subtract from the total offset.
    for(e=element.parentNode; e && e != document.body; e=e.parentNode) {
        // Scrolls.
        if(e.scrollTop) y -= e.scrollTop;
    }
      
    return (y + borderTopWidth);
}


/*
 * This is a utility function that returns the xcordinate of the right side of the input element.
 */
function getRight(element) {
    // The right point on the element is its left point plus its width.
    return getLeft(element) + element.offsetWidth;
}

/*
 * This is a utility function that gets the left x cordinate of the input element.
 */
function getLeft(element) { 
    
    // Left of element.
    var x = 0;
    
    // Total width of all borders.
    var borderLeftWidth = 0;
    
    // Element style.
    var style = (window.getComputedStyle) ? window.getComputedStyle(element, null) : element.currentStyle;
    
    // Itterate through the offsertParents of the element to use their offsets so the position isn't just relative to parents.
    for(var e = element; e; e=e.offsetParent) {
        x += e.offsetLeft;
        
        // Also add any borders to the offset.
        //if(style.borderLeftWidth) borderLeftWidth += parseInt(style.borderLeftWidth) || 0;
    }
    
    // Check if any of the ancestors of the element have scrollbars.  Subtract from the total offset.
    for(e=element.parentNode; e && e != document.body; e=e.parentNode) {
        // Scrolls.
        if(e.scrollLeft) x -= e.scrollLeft;
    }
    
    return (x + borderLeftWidth);
}

