if( typeof MooTools != "undefined" &&  typeof RegisterFunctions != "undefined" ){
    var CustomAccordian = new Class({
            options:{
                open: null,
                openClassName: 'caOpen',
                delay: 500,
                duration: 250
            },
            initialize: function(id,handle,options){
                this.setOptions(options);
                this.container = $(id);
                if(!this.options.open){
                	this.options.open = this.container.getFirst();
                }
                this.components = this.container.getChildren();
                this.initComponents(handle);
            },
            initComponents: function(handle){
                this.components.each(function(el){
                    this.closeComponent(el);
                    
                    el.addEvent('mouseenter',function(){
                            this.openComponent(el,handle);
                    }.bind(this));
                }.bind(this));
                if($(this.options.open)){
                    (function(){this.openComponent($(this.options.open),handle)}.bind(this)).delay(this.options.delay);
                }
            },
            openComponent: function(el,handle){
                var content = $E('.content',el);
                var currentHeight = el.getStyle('height');
                var previousOpen;
                //check to see if an open elment exists already
                this.components.each(function(panel){
                    if(panel.hasClass(this.options.openClassName)){
                        previousOpen = panel;
                        if(panel != el){
                            this.closeComponent(panel,handle);
                        }
                    }
                    
                }.bind(this));
                this.handle = $E(handle,el);
                var handleHeight = this.handle.getStyle('height');
                el.addClass(this.options.openClassName);
                
                this.handle.setStyle('background-position','bottom left');
                var contentHeight = content.getStyle('height');
                var currentHeight = el.getStyle('height');
                
                this.openEffect = new Fx.Style(el,'height',{duration: this.options.duration});
                
                if(previousOpen === el){
                    this.openEffect.stop();
                }
                else{
                    this.openEffect.start(currentHeight,contentHeight.toInt() + handleHeight.toInt());
                }
            },
            closeComponent: function(el, handle){
                
                if(this.handle){
                    el.removeClass(this.options.openClassName);
                    this.handle.setStyle('background-position','top left');
                }
                if(this.openEffect){
                    this.openEffect.stop();
                }
                this.closeEffect = new Fx.Style(el,'height',{duration: this.options.duration});
                this.closeEffect.stop();
                var currentHeight = el.getStyle('height');
                this.closeEffect.start(currentHeight,23);
            }
    });
    CustomAccordian.implement(new Events, new Options);
}

