// ----------------------------------------------------------------------------
// Use a stub object to prevent errors in IE from using console.log() etc.
// ----------------------------------------------------------------------------

(function(){
	// Prevent stray debugging calls from erroring when firebug isn't present
	if (!('console' in window) || !('firebug' in console)) {
		var names = ['log','debug','info','warn','error','assert','dir','dirxml','group','groupEnd','time','timeEnd','count','trace','profile','profileEnd'];
		window.console = window.console || {};
		for (var i=0; i<names.length; ++i) {
			window.console[names[i]] = window.console[names[i]] || function(){};
		}
	}
})();


// ----------------------------------------------------------------------------
// Extensions to the prototype framework (inspired by jQuery 1.2.3)
// Allows for showing and hiding of elements that have been hidden via an 
// external CSS declaration, rather than an inline "display:none;"
// ----------------------------------------------------------------------------

Element.addMethods({
	visible: function(element) {
		return $(element).getStyle('display') != 'none';
	},
	show: function(element){
		$(element).setStyle({ display: $(element).oldblock || '' });
		if ($(element).getStyle('display') == 'none') {
			var newElement = document.createElement($(element).tagName);
			$$('body').first().insert({bottom: newElement});
			$(element).setStyle({ display: $(newElement).getStyle('display')});
			$(newElement).remove();
			if ($(element).getStyle('display') == 'none') $(element).setStyle({ display: 'block'});
		}
		return element;
	},
	hide: function(element){
		$(element).oldblock = $(element).oldblock || $(element).getStyle("display");
		$(element).setStyle({display: 'none'});
		return element;
	}
});

// ----------------------------------------------------------------------------
// Instantly hide elements with a class of 'jsHide' (for JS-fallback content)
// ----------------------------------------------------------------------------

(function(){
	// See: http://yuiblog.com/blog/2007/06/07/style/
	function addCss(cssCode) {
		var styleElement = document.createElement("style");
		styleElement.type = "text/css";
		if (styleElement.styleSheet) {
			styleElement.styleSheet.cssText = cssCode;
		} else {
			styleElement.appendChild(document.createTextNode(cssCode));
		}
		document.getElementsByTagName("head")[0].appendChild(styleElement);
	}
	addCss(".jsHide { display:none; }");
})();


// --------------------------------------------------------------------------------
// Legacy functions carried over from ITL site, made redundant by Prototype
// --------------------------------------------------------------------------------

function toggleElement(id) {
	if (o = document.getElementById(id)) {
		o.style.display = (o.style.display) ? '':'none';
	}
	return false;
}

function addLoadEvent(newonload) {
	if (typeof window.onload != 'function') {
		window.onload = newonload;
	} else {
		var oldonload = window.onload;
		window.onload = function() {
			oldonload();
			newonload();
		}
	}
}

