(function($)
{project.AccordionBehaviour=function(dom_element,options)
{var that=this;this.dom_element=dom_element;this.position=0;options=options||{};options.first_open=typeof options.first_open!=='undefined'?options.first_open:true;options.all_closable=typeof options.all_closable!=='undefined'?options.all_closable:true;options.animate=typeof options.animate!=='undefined'?options.animate:true;this.options=options;this.button_elements=this.dom_element.find(".accordion_button");this.body_elements=this.dom_element.find(".accordion_body");this.body_element_heights=[];this.button_elements.each(function(pos,button_dom_element)
{button_dom_element=$(button_dom_element);var body_dom_element=$(that.body_elements[pos]);var accordion_button_id="accordion_button_"+project.getNextIdSequence();var accordion_body_id="accordion_body_"+project.getNextIdSequence();button_dom_element.addClass("cursor");button_dom_element.attr({"id":accordion_button_id,"role":"button","aria-controls":accordion_body_id,"tabindex":0});body_dom_element.attr({"id":accordion_body_id,"aria-labelledby":accordion_button_id});that.body_element_heights.push(body_dom_element.outerHeight());button_dom_element.bind('mouseup',function()
{if(that.position!=pos)
{that.setPosition(pos);}
else if(that.options.all_closable)
{that.setPosition(-1);}});button_dom_element.bind('keyup',function(event)
{if(event.keyCode===13)
{event.stopPropagation();event.preventDefault();if(that.position!=pos)
{that.setPosition(pos);}
else if(that.options.all_closable)
{that.setPosition(-1);}}});});if(that.options.first_open)
{this.setPosition(0);}
else
{this.setPosition(-1);}};project.AccordionBehaviour.prototype.setPosition=function(position)
{var that=this;this.position=position;this.body_elements.each(function(pos,body_dom_element)
{body_dom_element=$(body_dom_element);button_dom_element=$(that.button_elements[pos]);if(that.position===pos)
{body_dom_element.attr('aria-expanded',true);button_dom_element.attr('aria-expanded',true);button_dom_element.addClass('active');body_dom_element.animate({"height":that.body_element_heights[pos]},{"duration":that.options.animate?500:1,"queue":false});button_dom_element.find('input').attr('checked','checked');}
else
{body_dom_element.attr('aria-expanded',false);button_dom_element.attr('aria-expanded',false);button_dom_element.removeClass('active');body_dom_element.animate({"height":0},{"duration":that.options.animate?500:1,"queue":false});button_dom_element.find('input').attr('checked',false);}});};JsBehaviourToolkit.registerHandler('accordion',project.AccordionBehaviour);})(jQuery);
