/**
 * This fixes the cutting off of the header when a hash is in the url.
 * @author: Tizian Schmidlin <st@cabag.ch>
 */

var timeOut = null;
 
function fixHash() {
  // As some browsers may not support regular expressions, catch it if an error is thrown, else it could kill everything else
  try {
    
    if(/[^#]*#.*/.test(window.location.href) && (navigator.appName != 'Microsoft Internet Explorer'  || navigator.userAgent.indexOf('MSIE 8') != -1)) {
      hashEl = window.location.href.substring(window.location.href.indexOf('#')+1);
      if($$('a [name='+hashEl+']')) {
        ctArea = $$('#midCol .ctArea')[0];
        ctArea.style.marginTop="0px";
        ctArea.style.paddingTop="56px";
        
        if(navigator.vendor == 'Apple Computer, Inc.') {
          ctArea.style.paddingTop="56px";
        }
      }else if(document.getElementById(hashEl) && !$$('a [name='+hashEl+']')) {
        ctArea = $$('#midCol .ctArea')[0];
        ctArea.style.marginTop="0px";
        ctArea.style.paddingTop="56px";
        if(navigator.vendor == 'Apple Computer, Inc.') {
          ctArea.style.paddingTop="56px";
        }
      }
      timeOut = setTimeout(setMinHeight450, 1000);
    }
  }catch(e) {window.alert(e)}
}

function setMinHeight450() {
  ctArea = $$('#midCol .ctArea')[0];
  clearTimeout(timeOut);
}

function elHeight() {
  window.alert($('main').getHeight() + ':'+Position.getWindowSize(window));
}
document.observe('dom:loaded', fixHash);

