/**
 * 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);
			//window.alert($$('a [name="'+hashEl+'"]'));
			if($$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				ctArea.style.marginTop="0px";
				ctArea.style.paddingTop="15px";
				//window.alert(ctArea.style.minHeight);
				/* if($(hashEl).getHeight() > ctArea.style.minHeight) {
					ctArea.style.minHeight = ($('main').getHeight()-373)+"px";
				} */
				
				//ctArea.style.minHeight = "450px";
				
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop="33px";
				}
			}else if(document.getElementById(hashEl) && !$$('a [name='+hashEl+']')) {
				ctArea = $$('#midCol .ctArea')[0];
				ctArea.style.marginTop="0px";
				ctArea.style.paddingTop="15px";
				/* if($(hashEl).getHeight() > ctArea.style.minHeight) {
					ctArea.style.minHeight = ($('main').getHeight()-373)+"px";
				} */
				//ctArea.style.minHeight = "450px";
				if(navigator.vendor == 'Apple Computer, Inc.') {
					ctArea.style.paddingTop="13px";
				}
			}
			timeOut = setTimeout(setMinHeight450, 1000);
		}
	}catch(e) {window.alert(e)}
}

function setMinHeight450() {
	ctArea = $$('#midCol .ctArea')[0];
	//ctArea.style.minHeight = '450px';
	clearTimeout(timeOut);
}

function elHeight() {
	window.alert($('main').getHeight() + ':'+Position.getWindowSize(window));
}
document.observe('dom:loaded', fixHash);


