﻿/**
* @author Vladimir Yunev
* @desc Create accordion on dl-elements with jQuery
* @version 1.0
* @example
* $("dl-element").accordion();
* @license free
**/
jQuery.fn.accordion = function() {
    function update(dl,active) {
	
        var div = $("dt.active", dl).next().children("div")
        div.show(1000); 
        $.scrollTo(active, 1800,{offset:{top:-37}});		
    }

    return this.each(function() {
        var active = $("dt.active", dl)
	var dl = $(this)

        $("dd div", dl).hide(1000)

        $("dt", dl).click(function() {
            
            if (!active.hasClass("active")) {
                active = $(this)
                active.addClass("active");

                update(dl,$(this));
            }
            else
            {
          	active.next().children("div").hide()

            	if(!$(this).hasClass("active"))
            		$(this).addClass("active");
            	
            	active.removeClass("active")
            	active=$(this)
            	update(dl,$(this))
            }
        });
    });
};
