/**
 * This fixes the cutting off of the header when a hash is in the url.
 * @author: Tizian Schmidlin <st@cabag.ch>
 */

 // Set the height to fix. This might change from website to website.
var fixHeight = 15;
 
function fixHash() {
	// As some browsers may not support regular expressions, catch it if an error is thrown, else it could kill everything else
	try {
			// Check if there is a # in the href and if it is a non IE or IE >= 8
		if(/[^#]*#.*/.test(window.location.href) && (navigator.appName != 'Microsoft Internet Explorer'  || navigator.userAgent.indexOf('MSIE 8') != -1)) {
			
				// now get the id or anchor name
			hashEl = window.location.href.substring(window.location.href.indexOf('#')+1);
			//window.alert($$('a [name="'+hashEl+'"]'));
				// if it is an anchor
			if($$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				// Remove all top margins
				ctArea.style.marginTop="0px";
				// Replace it by some top padding
				ctArea.style.paddingTop=fixHeight+"px";
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop=(fixHeight-1)+"px";
				}else if (navigator.userAgent.indexOf('MSIE 8') != -1) {
					ctArea.style.paddingTop = (fixHeight-11)+"px";
				}
				// As the anchor check sometimes doesn't work in IE 8, do this
			}else if(document.getElementById(hashEl) && !$$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				
				// Remove all top margins
				ctArea.style.marginTop="0px";
				
				// Replace it by some top padding
				ctArea.style.paddingTop=fixHeight+"px";
					// Actually in Safari, the space isn't the same by 2px
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop=(fixHeight-1)+"px";
				}else if (navigator.userAgent.indexOf('MSIE 8') != -1) {
					ctArea.style.paddingTop = (fixHeight-11)+"px";
				}
			}
		}
	}catch(e) {}
}

//Event.observe(document, 'loaded', fixHash);
//document.observe('domready',fixHash);

