// JavaScript Document
/**
 * @author Matthew Foster
 * @date	January 17th 2007
 */
 	var FAQBoss = Class.create();

	FAQBoss.prototype = {
						
							initialize : function(container, options){
								var self = this;
								this.options = {
													mouseOver   : self.mouseOver,
													click	    : self.click,
													singularity : true,
													collapseSelf : false
								
											   }
								
								Object.extend(this.options, options || {});
								
								this.container = $(container);	
							
								this.collectQuestions();
							
							},
							attachListeners : function(obj){
								obj.onmouseover = this.options.mouseOver.bindAsEventListener(this);
								obj.onclick		= this.options.click.bindAsEventListener(this);
								
							
							},
							
							collectQuestions : function(){
								
								var arr = $A(document.getElementsByClassName("faq_question", this.container));
								
								try{
									arr.each(this.parseQuestion.bind(this));
									}
								catch(e){
									alert("failed on parsing Each Question" + e.message);
								}
							},
							parseQuestion : function(question){
								
								var nS = $(question).recursivelyCollect('nextSibling');
							
								nS.each(function(node){
											
											if(node.nodeName.toLowerCase() == "p")
												question.answer = node;
										
										}
									);
									
								
								this.attachListeners(question);
							
							},
							mouseOver : function(e){
								return false;
							},
							click : function(e){
								Event.stop(e);
								
								var question = Event.element(e);
								var answer   = question.answer;
								var parent = question.parentNode;
								if(this.options.singularity)
								try{
									this.maintainSingularity(parent);
									}
								catch(e){
									
									return false;
									}
									
								if(Element.hasClassName(parent, "highlight"))
									Element.removeClassName(parent, "highlight");
								else
									Element.addClassName(parent, "highlight");
									
								return false;
									
								
							},
							//changed this to actually be referencing hte parent node of the question and answer. this allows for a more css reliant change.
							maintainSingularity : function(question){
								if(this.singleton && question == this.singleton && this.options.collapseSelf == false)
									throw new { message : "nodes are identical, do not take any action" };
								else if(this.singleton && question == this.singleton && this.options.collapseSelf == true)
									return true;
									
								try{
									Element.removeClassName(this.singleton, "highlight");
									}
								catch(e){}
								
								this.singleton = question;
								
							}
						}
