/**
 * @author Kris Kelly, Heehaw Ltd 2009
 */
YAHOO.namespace('Cactus.Questions.Vars','Cactus.Questions.Funcs','Cactus.Questions.Handlers','Cactus.Questions.Elements','Cactus.Questions');var Y=YAHOO,E=Y.util.Event,D=Y.util.Dom,C=Y.Cactus,CQ=C.Questions,CQH=CQ.Handlers;CQ.init=function(){CQ.Vars.heights=[];CQH.handleQuestionClick=function(event,answer){if(event!=null){E.stopEvent(event);}
var question=this;if(D.hasClass(question,"question_toggle_show")){var anim=new Y.util.Anim(answer,{height:{to:CQ.Vars.heights[question.id]}},0.5,Y.util.Easing.easeOut);anim.onStart.subscribe(function(){D.setStyle(answer,"overflow","hidden");});anim.onComplete.subscribe(function(){D.setStyle(answer,"overflow","visible");D.removeClass(question,'question_toggle_show');D.addClass(question,'question_toggle_hide');});}else{var answer=D.get(answer);var height=answer.offsetHeight;CQ.Vars.heights[question.id]=height;var anim=new Y.util.Anim(answer,{height:{to:0}},0.5,Y.util.Easing.easeIn);anim.onStart.subscribe(function(){D.setStyle(answer,"overflow","hidden");});anim.onComplete.subscribe(function(){if(D.hasClass(question,'question_toggle_hide')){D.removeClass(question,'question_toggle_hide');}
D.addClass(question,'question_toggle_show');});}
anim.animate();};CQ.Funcs.toggleAnswer=function(answer){if(D.hasClass(answer,"hidden")){}else{}};CQ.Funcs.addToggleButton=function(question,answer){var btn=document.createElement('A');D.addClass(btn,'question_toggle_hide');btn.appendChild(document.createTextNode('comment on this story'));D.generateId(btn,'btn_');btn.href="#";question.appendChild(btn);E.addListener(btn,"click",CQH.handleQuestionClick,answer);CQH.handleQuestionClick.call(btn,null,answer);};CQ.Funcs.initQuestions=function(){var containers=D.getElementsByClassName("expander","div"),questions,answers,i;for(i=0;i<containers.length;i++){questions=D.getElementsByClassName("question","h5",containers[i]);answers=D.getElementsByClassName("answer","div",containers[i]);if(questions.length>0&&answers.length>0){CQ.Funcs.addToggleButton(questions[0],answers[0]);}}};CQ.Funcs.initQuestions();};E.addListener(window,"load",CQ.init);