    function Becklyn_Accordion ( options )
    {
        this.wrap              = options.wrap || 'becklyn-accordion';
        this.wrapID            = '#' + this.wrap;
        this.headline          = options.headline || 'h2';
        this.speed             = options.speed || 'slow';
        this.activeClass       = options.activeClass || 'active';
        this.autoload          = options.autoload || false;
        this.preselectedFound = false;
		this.lastActive = null;

        this.init();
    }


    Becklyn_Accordion.prototype.init = function ()
    {
        this.handler = $( this.wrapID );

        if (this.handler.length == 0)
        {
            return;
        }

        if (this.autoload)
        {
            this.findPreselectedElement();
            this.registerMouseover();
            this.registerClickHandler();
            this.initHide();
        }
    }

    Becklyn_Accordion.prototype.findPreselectedElement = function ()
    {
        this.preselectedFound = ( this.handler.find( this.headline + "." + this.activeClass ).length > 0 );
    }


    Becklyn_Accordion.prototype.registerClickHandler = function ()
    {
        var oThis = this;
        this.handler.find( this.headline ).click(
            function ()
            {
				if (this != oThis.lastActive)
				{
                	oThis.expandSingle( this );
					oThis.lastActive = this;
				}
            }
        );
    }

    Becklyn_Accordion.prototype.expandSingle = function ( handler )
    {
		if ($(handler).next().get(0).tagName.toLowerCase() != this.headline )
		{
        	this.collapseAll( false );
        	$(handler).next().slideDown( this.speed );
		}
        $(handler).addClass( this.activeClass );
    }


    Becklyn_Accordion.prototype.initHide = function ()
    {
        var skipFirst = (!this.preselectedFound) ? ':gt(0)' : '';
        this.handler.find( this.headline + skipFirst ).next().hide();
    }


    Becklyn_Accordion.prototype.collapseAll = function ()
    {
        this.handler.find( this.headline ).next().slideUp( this.speed );
        this.handler.find( this.headline ).removeClass( this.activeClass );
    }

    Becklyn_Accordion.prototype.registerMouseover = function ()
    {
        this.handler.find( this.headline ).hover(
            function ()
            {
                $(this).css("cursor", "pointer");
            },
            function ()
            {
                $(this).css("cursor", "default");
            }
        );
    }



    $(document).ready(
        function ()
		{
            new Becklyn_Accordion(
                {
                    'headline': 'h4',
                    'autoload': true,
					'wrap': 'content'
                }
            );
        }
    );
    
