//generic image preload and rollver script
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Pop up window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// ***************************************************

// *** General page layout methods ***

/**
* This method repositions the footer DIV ('footer-container') to the bottom of the viewport for DIV-layout
* based pages. If the page doesn't use DIV layout, assume it uses table layout; if so, set the body height
* to fill the containing element (i.e. the html element), so that the outer table fills the viewport. The 
* latter method is in JS rather than CSS to ensure layout consistency between the table- and div-based 
* layouts when JS is disabled
*/
var footerContainerInitialOffset;
var repositionFooter = function()
{
     var viewPortHeight;
     var scrollOffsetTop;
     
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
     if (typeof window.innerWidth != 'undefined'){
          scrollOffsetTop = window.pageYOffset;
          viewPortHeight = window.innerHeight
     }else if (typeof document.documentElement != 'undefined' && 
        typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        scrollOffsetTop = document.body.scrollTop;
        viewPortHeight = document.documentElement.clientHeight
     }else{
        // older versions of IE
        scrollOffsetTop = document.body.scrollTop;
        viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
     }
     
    var footerContainer = document.getElementById('footer-container');
    // check we are using div-based layout
    if(footerContainer && document.getElementById('outer-page-container')) {
      //get padding values for the footer container - used to calculate positionning and dimensions
      paddingLeft = getStyle(footerContainer, 'padding-left');
      paddingRight = getStyle(footerContainer, 'padding-right');
      paddingTop = getStyle(footerContainer, 'padding-top');
      removePx = function(str){ if(str.indexOf('px') > -1) return str.substring(0, str.indexOf('px')); else return str; };
      removeAuto = function(str){ if(str.toString().toLowerCase() == 'auto') return 0; else return str; }
      paddingLeft = removeAuto(removePx(paddingLeft));
      paddingRight = removeAuto(removePx(paddingRight));
      paddingTop = removeAuto(removePx(paddingTop));
      //set height offset
      fcHeight = footerContainer.clientHeight;
      footerContainerInitialOffset = (typeof footerContainerInitialOffset == 'undefined') ? footerContainer.offsetTop : footerContainerInitialOffset;
      if(footerContainerInitialOffset > (viewPortHeight - fcHeight)){
        footerContainer.style.top = footerContainerInitialOffset + 'px';
      } else {
        footerContainer.style.top = ((viewPortHeight - fcHeight - 20) + scrollOffsetTop).toString() + 'px';
      }
      //make sure the footer is correctly positioned, and of the correct width
      footerContainer.style.position = 'absolute';
      //correct width is width of the outer container minus the footer-container padding
      footerContainer.style.width = (document.getElementById('outer-page-container').clientWidth - paddingLeft - paddingRight).toString() + 'px';  
    } else {
        /*
        fix to ensure that pages with table layouts fill the viewport when the HTML doctype
        is valid (so that the footer is at the bottom of the viewport, rather than just below 
        the rest of the content) 
        */
      document.getElementsByTagName('body')[0].style.height='100%';
    }
}

// add the footer repositioning code to the window onload and resize events - depends on addEvent() in common.js
//addEvent(window, 'load', repositionFooter);
//addEvent(window, 'resize', repositionFooter);
