/**
 * 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+']')) {
				if(document.getElementById('midCol')) {
					ctArea = $$('#midCol .ctArea')[0];
				} else if (document.getElementById('midColNoRight')) {
					ctArea = $$('#midColNoRight .ctArea')[0];
				}
				
				ctArea.style.marginTop="10px";
				ctArea.style.paddingTop="26px";
				//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+']')) {
				
				if(document.getElementById('midCol')) {
					ctArea = $$('#midCol .ctArea')[0];
				} else if (document.getElementById('midColNoRight')) {
					ctArea = $$('#midColNoRight .ctArea')[0];
				}
				
				ctArea.style.marginTop="10px";
				ctArea.style.paddingTop="26px";
				/* 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', function(ev) {
		fixHash();
		$$('a').each( 
			function(el) {
				if(/[^#]*#.*/.test($(el).href)) {
					Event.observe($(el), 'click',
						function(ev) {
							fixHash();
						}
					);
				}
			}
		);
});


