window.onload = function () {
	fixIe7ZoomBug();
	consultantsDropDownNav();
}

function consultantsDropDownNav() {
	var li = $('whoWeAreConsultants');
	if (!li) return;

	var a		= li.getElementsByTagName('a')[0];
	var ul	= li.getElementsByTagName('ul')[0];

	a.onclick = function () {
		if (hasClass(li, 'expanded')) {
			removeClass(li, 'expanded');
		}
		else {
			addClass(li, 'expanded');
		}
		return false;
	};
}

/*  IE7 has an annoying bug which causes the rendering engine to fail to zoom background images applied to
    the body. Applying an image to the body is the most sensible way to achieve the styling we require, and
    the only workaround is to	create a div element to surround everything and apply a background to this.
    This non-semantic div compromises the integrity of the markup and thus, I have opted to create the
    surrounding div dynamically with JavaScript and apply it only to users browsing in IE7.	*/

function fixIe7ZoomBug() {
	var isIE7 = ((document.all) && (navigator.appVersion.indexOf('MSIE 7.')!=-1));
	if (isIE7) {
		var body = document.getElementsByTagName('body')[0],
			bodyInnerHTML = body.innerHTML,
			surroundingDiv = document.createElement('div');

		// Remove background image and inner HTML from body
		body.style.background = '#F2F2F2';
		body.innerHTML = '';

		// Assign ID to viewport div and append to the DOM
		surroundingDiv.setAttribute('id','viewport');
		body.appendChild(surroundingDiv);

		// Grab viewport within document, style background image and apply HTML
		docSurroundingDiv = document.getElementById('viewport');
		docSurroundingDiv.style.background = '#F2F2F2 url(../images/bg.jpg) repeat-x top';
		docSurroundingDiv.innerHTML = bodyInnerHTML;
	}
}

function $(id) {
	return document.getElementById(id);
}

function addClass(el, className) {
	if (!hasClass(el, className)) el.className += ' ' + className;
}

function addLoadEvent(func) {
	var oldOnload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			func();
		};
	}
}

function hasClass(el, className) {
	var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
	return regex.test(el.className);
}

function removeClass(el, className) {
	var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
	el.className = el.className.replace(regex, ' ');
}

function trim(obj) {
	if (typeof obj === 'object') {
		obj.value = obj.value.replace(/^\s{1,}/, '').replace(/\s{1,}$/, '');
		return obj;
	}
	return obj.replace(/^\s{1,}/, '').replace(/\s{1,}$/, '');
}