addLoadListener(function()
{
	if (location.search.indexOf('qaid=') == -1) {
		li = document.getElementById('all_questions').getElementsByTagName('li');
		for (i=0; i<li.length; i++) {
			qaid = li[i].childNodes[0].href.match(/\d+$/);
//			li[i].childNodes[0].onclick = new Function("showAnswer("+qaid+");return false;");
			li[i].childNodes[0].onclick = new Function("javascript:;return false;");
			li[i].childNodes[0].onmouseover = new Function("showQuestion('show',this,"+qaid+")");
//			li[i].onmouseout = new Function("showQuestion('hide',this,"+qaid+")");
		}
		
		bObj = document.getElementsByTagName('body')[0];
		popDiv = document.createElement('div');
		popDiv.setAttribute('id','loading');
		blueBoxObj = document.getElementById('answers').getElementsByTagName('div')[0]
		coors = findPos(blueBoxObj);
		isIE67 = /msie|MSIE 6|MSIE 7/.test(navigator.userAgent);
		ieOffset = (isIE67) ? -40:0;
		popDiv.style.left = coors[0] + (blueBoxObj.offsetWidth - 167)/2 + ieOffset + 'px';
		popDiv.style.top = coors[1] + (blueBoxObj.offsetHeight - 167)/2 - 5 + 'px';
		bObj.insertBefore(popDiv, bObj.nextSibling);
		
		document.getElementById('loading').innerHTML = '<img src="images/answers_loader.gif" alt="" width="66" height="66" />';
	}

/*	winSize = windowSize();
	finalHeight = winSize[1] - (130 + 113 + 32 + 18 + 30 + 38 + document.getElementById('footer').offsetHeight); // window height - everything else above and below the blue box. 130 was a guess.
	
	finalHeight = (finalHeight <= 430) ? finalHeight:430; // Maximum height
	finalHeight = (finalHeight >= document.getElementById('all_questions').offsetHeight) ? finalHeight:document.getElementById('all_questions').offsetHeight; // Minumun height
	
	document.getElementById('answers').getElementsByTagName('div')[0].style.height = finalHeight + 'px';*/
});

function showAnswer(qaid) {
req = createXMLHttpRequest();
if (!req) {
	location.href='waynes-answers.php?qaid='+qaid;
} else {
	document.getElementById('loading').style.display = 'block';
	url = 'waynes-answers-process.php?qaid='+qaid;
	req.open('GET', url, true);
	req.onreadystatechange = handleResponse;
	req.send(null);
	return false;
}
}

function handleResponse() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var response = req.responseText;
			infoSplit = response.split('|');
			document.getElementById('answers').getElementsByTagName('div')[0].scrollTop = 0;
			document.getElementById('answers').getElementsByTagName('div')[0].innerHTML = '<h3>'+infoSplit[0]+'</h3>'+infoSplit[1];
			document.getElementById('loading').style.display = 'none';
		}
	}
}

var curAns = 0;
var curQDiv = null;

function showQuestion(option,obj,qaid) {
qDiv = (obj.parentNode.getElementsByTagName('div').length > 0) ? obj.parentNode.getElementsByTagName('div')[0]:null;
if (option == 'show') {
	if (curAns != qaid) {
		if (curQDiv) {
			curQDiv.style.display = 'none';
		}
		showAnswer(qaid);
		curAns = qaid;
		curQDiv = qDiv;
	}
	
	if (qDiv) {
		qDiv.style.display = 'block';
	}
} else {
	if (qDiv) {
//		qDiv.style.display = 'none';
		curQDiv = qDiv;
	}
}
}

function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
  return [myWidth,myHeight];
}

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
	curleft = obj.offsetLeft
	curtop = obj.offsetTop
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
}
return [curleft,curtop];
}

