/**
  * Coded By Cedric Michaux :: LBi (cedric.michaux@lbigroup.be)
  * Exclusively for the new shurgard's website
  * This script uses the Prototype library
  *
  * (c) 2007 Cedric Michaux
  */
  
Event.onDOMReady(function(){
	
	faqAnswers = $$(".faqQuestions .faqAnswer");
	for(i = 0; i < faqAnswers.length; i++){
		faqAnswers[i].style.display = "none";
		faqAnswers[i].isOpen = false;
	}
	
	faqLinks = $$(".faqQuestions .arrowLink");
	for(i = 0; i < faqLinks.length; i++){
		id = faqLinks[i].id.substring(0, faqLinks[i].id.lastIndexOf("-"));
		faqLinks[i].href = "#"+id+"-box";
		faqLinks[i].compId = id;
		faqLinks[i].onclick = function(){
			/*console.log(
				"Clickeeeeeeee: " + this.id + "\n" +
				"isOpen: " + this.isOpen + "\n"
			);*/
			
			if(this.isOpen){
				$(this.compId + "-answer").style.display = "none";
				$(this.compId + "-link").className = "arrowLink";			
				this.isOpen = false;
			}
			else{
				/*if(document.lastFaqItem != null){
					$(document.lastFaqItem.compId + "-answer").style.display = "none";
					$(document.lastFaqItem.compId + "-link").className = "arrowLink";
					document.lastFaqItem.isOpen = false;
				}*/
				$(this.compId + "-answer").style.display = "block";
				$(this.compId + "-link").className = "arrowLinkOpened";			
				this.isOpen = true;
				document.lastFaqItem = this;
			}
		}
	}
	
	// Find the fragment of the FAQ to open.
	openId = (window.location.hash).substring(1);
	//console.log(window.location.hash);
	if (openId != '') {
		$(openId + "-answer").style.display = "block";
		$(openId + "-link").className = "arrowLinkOpened";
		$(openId + "-link").isOpen = true;
	}
});

document.lastFaqItem = null;
