// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

window.addEvent('domready', function(){
  sectionSelectionAccordion = new Accordion('div.ssa-head', 'div.ssa-body', {fade: false, duration: 200}, $('sectionSelectionAccordion'));
  window.ssa = function(index) {
    if(index == -1) index = window.cur_controller_index;
    sectionSelectionAccordion.display(index);
    
    $$('.ssbutton').each(function(but, i) {
      var isCurrent = (i == index);
      
    	but.fx = new Fx.Styles(but, {duration:200, wait:true});
      
      if(isCurrent) { // button to transition to
        but.fx.stop();
    		but.fx.start({
    			'background-color': '#d2c4bd',
    			'padding-left': 20,
    			'border-left-width': 0,
    			'border-right-width': 0
    		});
    		but.isActive = true;
      } else if(but.isActive) { // button to transition from
        but.fx.stop();
    		but.fx.start({
    			'background-color': '#ded9d2',
    			'padding-left': 12,
    			'border-left-width': 0,
    			'border-right-width': 0
    		});
    		but.isActive = false;
      }
    })
  }
  $('sectionNavigation').addEvent('mouseleave', function() { window.ssa(-1); });

  $$('.ssbutton').each(function(but, i) {
//    alert("::" + $(but).getChildren());
    if(but.getChildren()[0].getText() != "") {
      $(but).addEvent('mouseenter', function() { window.ssa(i); });
      $(but).isActive = false
    }
  })
  
  window.ssa(-1);
});