/**
 * This fixes the cutting off of the header when a hash is in the url.(mootools-version)
 * @author: Michael Bossart <mb@cabag.ch>
 */

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

window.addEvent('domready', 
	function(e) {
		fixHash();
	}
);

