if (typeof(window.addEventListener)=="undefined") {
	if (window.attachEvent) 	{
		window.addEventListener=function(sEvent, funcHandler, bCapture) {
			window.attachEvent("on"+sEvent,funcHandler);
		}
	} else {
		window.addEventListener=function(sEvent, funcHandler, bCapture) {
			window["on"+sEvent]=funcHandler;
		}
	}
}

function toggleShrink(from,targetID) {
	target=document.getElementById(targetID);
  expdate=new Date(3052,6,6);
	if (target.className.match(/\bexpanded\b/)) {
		target.className=target.className.replace(/\bexpanded\b/,'shrunk');
		document.cookie='shrinkstatus_'+targetID+'=shrunk; expires=Tue, 06 Jun 3052 16:32:00 EST';
	} else if (target.className.match(/\bshrunk\b/)) {
		target.className=target.className.replace(/\bshrunk\b/,'expanded');
		document.cookie='shrinkstatus_'+targetID+'=expanded; expires=Tue, 06 Jun 3052 16:32:00 EST';
	}
	from.blur;
}

function initializeShrinkers() {
	var controlList=document.getElementsByTagName('span');
	for (t=0; t<controlList.length; t++) {
		if (controlList[t].id.indexOf('_sControl')!=-1) {
			controlList[t].className+=' sControl';
			targetID=controlList[t].id.replace(/_sControl/,'');
			controlList[t].innerHTML='<a href="#" onclick="toggleShrink(this,\''+targetID+'\'); return false;"><b></b>'+controlList[t].innerHTML+'<span></span></a>';
		}
	}
}

/* 
	the following fixes Opera being a bit #DDD on loading
	background images
*/

function operaRenderFix() {
	document.body.style.padding="0";
}

function stageTwo() {
	if (navigator.userAgent.indexOf("Opera")>-1) {
		document.body.style.padding="0 1px";
		setTimeout(operaRenderFix,1);
	}
}

function initialize() {
	initializeShrinkers();
	window.addEventListener('load',stageTwo,false); 
}

function lessrows(targetID) {
	var target=document.getElementById(targetID);
	if (target.rows>5) target.rows--;
		
}

function morerows(targetID) {
	var target=document.getElementById(targetID);
	target.rows++;
}

var switchyLastWidth=0;

function quickSwitchy() {
	var change=document.getElementById('widthAdjust');
	var curWidth=document.body.clientWidth;
	if (curWidth!=switchyLastWidth) {
		if (curWidth>1600) {
			change.className='extraWide';
		} else if (curWidth>1152) {
			change.className='wide';
		} else {
			change.className='narrow';
		}
		switchyLastWidth=curWidth;
	}
}


function switchyInitialize() {
	quickSwitchy();
	window.addEventListener('resize',quickSwitchy,false);
}

