///////////////////////////////////////////////////////////////////
///																///
///	tk.esterni, this is a gallery box application				///
///	developed by triknine										///
///																///
///////////////////////////////////////////////////////////////////

/// THIS IS A GALLERY MENU GLOBAL VARS
var thesearefaqs_UElements = new Array();

function thesearefaqsElement(id,reference,question,answer) {
	this.id = id;
	this.thesearefaqs_UElements_ID = (thesearefaqs_UElements.length);
	this.reference = reference;
	this.question = question;
	this.answer = answer;
	this.isFaqs_UElements = true;
	this.children = new Array();
	this.parent = null;
	this.isOpen = false;
	this.containers = new Array();
	this.container = null;
	this.contents = new Array();
	this.parentContainer = null;
	thesearefaqs_UElements.push(this);
	
	this.add = function (element, isOpen) {
	 	if (element.isFaqs_UElements==true) {
	 	 	element.parent = this;
	 	 	element.isOpen = isOpen;
	 	 	this.children.push(element); return true;
		} else {return false;}
	}
	
	this.render = function(obj) {
	 	var children = this.children.length;
		var br = document.createElement("br");
		var i = 0;
		for (i=0;i<children;i++) {
		 	var container = document.createElement("div");
		 	var element = document.createElement("span");
			var link = document.createElement("a");
			link.setAttribute("href","javascript:thesearefaqs_UElements["+this.children[i].thesearefaqs_UElements_ID+"].openOrClose()");
			var question = document.createTextNode(this.children[i].question);
			link.appendChild(question);
			element.appendChild(link);
			var answer = document.createElement("div");
			var answerT = document.createTextNode(this.children[i].answer);
			answer.appendChild(answerT);
			this.children[i].contents.push(answer);
			container.appendChild(element);
			if (this.children[i].isOpen) container.appendChild(answer);
			this.children[i].render(container);
			if (this.isOpen) obj.appendChild(container);
			this.containers.push(container);
		}
		this.parentContainer = obj;
	}
	
	this.openOrClose = function () {
	 	if (this.isOpen) {
	 	 	if (this.contents.length>0) {
	 	 		this.isOpen = false;
	 	 		//return this.parentContainer.firstChild.innerHTML;
				for (j=0;j<this.contents.length;j++) {
				 	this.parentContainer.removeChild(this.contents[j]);
				}}	
		} else {
		 	if (this.contents.length>0) this.isOpen = true;
		 	for (j=0;j<this.contents.length;j++) { 	
			 	this.parentContainer.appendChild(this.contents[j]);
			}
		}
	}
	
	
}