var accordion;
var accordionTogglers;
var accordionContents;

Fx.Color = Fx.Style.extend({
    initialize: function(el, property, options){
		this.element = $(el);
		this.property = property;
		this.parent(options);

        this.toColor = function(hexToColor) {
          el.effect(property, {duration: 300, transition: Fx.Transitions.linear}).start( el.getStyle(property), hexToColor );
        };
	}
});

window.addEvent('domready', function() {

	accordionTogglers = $$('.leftnav_group_header');
	
	accordionTogglers.each(function(toggler){
		//remember the original color
		toggler.origColor = toggler.getStyle('background-color');
		toggler.origTextColor = toggler.getStyle('color');
		//set the effect
		toggler.fx = new Fx.Color(toggler, 'background-color');
		toggler.fxText = new Fx.Color(toggler, 'color');

        /* Disable Following LINKS */
        if( toggler.getTag() == "a" )
          toggler.addEvent( 'click', function(e) { new Event(e).stop(); return false; });
	});
	
    var szMaxAccContentHeight = 0, szMaxCellHeight = 0;
    leftnav_column_cell = $('leftnav_column');
	accordionContents = $$('.accContent');
    accordionContents.each( function(accContent) {
      if( szMaxAccContentHeight < accContent.offsetHeight ) szMaxAccContentHeight = accContent.offsetHeight;
    });

    szMaxCellHeight = leftnav_column_cell.offsetHeight - szMaxAccContentHeight;
    leftnav_column_cell.setStyle( 'height', szMaxCellHeight );

	accordion = new Fx.Accordion(accordionTogglers, accordionContents,{
        opacity: false,
		//when an element is opened change the background color to blue
		onActive: function(toggler){
			toggler.fx.toColor('#677890');
			toggler.fxText.toColor('#fff');
			toggler.blur();
		},
		onBackground: function(toggler){
			//change the background color to the original (green) 
			//color when another toggler is pressed
			toggler.setStyle('background-color', '');
			toggler.setStyle('color', '');
		}
	});
});
