
window.onload = addEvents;

var previousPiece;
var currentPiece = 0;
var n;
function displayNone(m) {
	var previousObject = document.getElementById(m);
	previousObject.style.visibility = "hidden";
}
function addEvents() {
	if (document.getElementById('faqList')) {
		var linkList = document.getElementById('inlineLinkList');
		linkList.style.display = "none";
		var articlesList = document.getElementById('faqList');
		var thisArticle = articlesList.getElementsByTagName('li');
		var sectionHeading = articlesList.getElementsByTagName('h2');
		var articlesSection = articlesList.getElementsByTagName('p');
		//alert(articlesList.childNodes.length);
		var k = 0;
		for (var i = 0; i < articlesList.childNodes.length;i++) {
			if (articlesList.childNodes[i].nodeName.toUpperCase() == "LI") {
				if (k.toString().length < 2) {
					n = ("0" + String(k));
				}
				else {
					n = k;
				}
				var contContainer = document.createElement("div");
				contContainer.innerHTML = articlesList.childNodes[i].innerHTML;
				var thisHeading = contContainer.getElementsByTagName('h2')[0];
				var endOfHeading = contContainer.innerHTML.toLowerCase().lastIndexOf("</h2>");
				var thisBody = contContainer.innerHTML.substring(endOfHeading + 5);
				articlesList.childNodes[i].innerHTML = '<div>'+thisBody+'</div>';
				var cDiv = articlesList.childNodes[i].getElementsByTagName('div')[0];
				var initialHeight = cDiv.offsetHeight;
				var oldInner = articlesList.childNodes[i].innerHTML;
				articlesList.childNodes[i].innerHTML = '<a style="cursor:pointer;" id="at'+n+'" rel="'+initialHeight+'" onclick="showHide(' + n + ',' + initialHeight + ')"><h2>'+thisHeading.innerHTML+'</h2></a>' + oldInner;
				cDiv = articlesList.childNodes[i].getElementsByTagName('div')[0];
				cDiv.style.height = '0px';
				cDiv.style.width = '428px';
				cDiv.style.overflow = 'hidden';
				cDiv.id = 'effectId' + n;
				displayNone(cDiv.id);
				k++;
			}
		}
	}
	if (location.hash) {
		var thisSectionNum;
		if (location.hash.substring(7).length == 1) {
		 	thisSectionNum = "0"+location.hash.substring(7);
		}
		else {
			thisSectionNum = location.hash.substring(7);
		}
		var thisSection = document.getElementById("at"+thisSectionNum);
		showHide(thisSectionNum, Number(thisSection.rel));
	}
}
function jumpScroll(yOffset) {
	//alert(yOffset);
   	window.scroll(0,yOffset); // horizontal and vertical scroll targets
}
function setWindowLoc(n) {
	//alert('move');
	var el = document.getElementById('faqNum'+n);
	location.hash = 'faqNum'+n;
}
function showHide(i, initialHeight) {
	if (i != Number(previousPiece) || previousPiece == undefined) {
		if (previousPiece != undefined) {
			if (previousPiece.toString().length < 2) {
				n = ("0" + String(previousPiece));
			}
			else {
				n = previousPiece;
			}
			var previous = document.getElementById('effectId' + n.toString());
			var blindOut = new Spry.Effect.Blind(previous, {duration: 500, from: '100%', to: '0%', toggle: false});
			window.setTimeout('displayNone("effectId' + n.toString() + '")',500);
		}
		if (i.toString().length < 2) {
			n = ("0" + String(i));
		}
		else {
			n = i;
		}
		var next = document.getElementById('effectId'+n);
		next.style.visibility = "visible";
		var thisParent = next.parentNode.getElementsByTagName('a')[0];
		thisParent.id = 'faqNum'+n;
		window.setTimeout('setWindowLoc(' + n + ')',500);
		
		var blindIn = new Spry.Effect.Blind(('effectId'+n), {duration: 500, from: '0%', to: (initialHeight+20)+'px', toggle: false});
		
		previousPiece = n;
	}
}
function openFromRight(openNum) {
	var thisSection = document.getElementById("at"+String(openNum));
	showHide(String(openNum), Number(thisSection.rel));
}
