var old = (window.onload) ? window.onload : function () {};
window.onload = function ()
{
	old();
	if (!document.getElementById) return;

	//add listener to "external" class a hrefs
	for(var i = 0; i < document.links.length; i++)
	{
		if(document.links[i].className == 'external')
		{
			document.links[i].onclick = newWindow;
		}
		if(document.links[i].className == 'stylesheet')
		{
			document.links[i].onclick = changeStyle;
		}		
	}
	Element.cleanWhitespace('content');
	init();
}

function newWindow()
{
	newWindow = window.open(this,"","")
	return false;
}

function changeStyle()
{
	setActiveStyleSheet(this.getAttribute("title"));
}

function init(){


	var stretchers = document.getElementsByClassName('stretcher'); //div that stretches
	var toggles = document.getElementsByClassName('display'); //h3s where I click on

	//accordion effect
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: true, duration: 400}
	);

	//hash function
	
	function checkHash(){
		var found = false;
		toggles.each(function(h3, i){
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(stretchers[i]);
				found = true;
			}
		});
		return found;
	}
	
	if (!checkHash()) myAccordion.showThisHideOpen(stretchers[0]);
}