(function($) {
    var lasttarget = "";
    var first = null;
    $.fn.extend({
        accordion: function() {
            return this.each(function() {
                if ($(this).data('accordiated'))
                    return false;
                $.each($(this).children('li').children('div'), function() {
                    $(this).data('accordiated', true);
                    $(this).addClass('def');
                    $(this).hide();
                    first = $(this);
                });
                $.each($(this).children('li').children('a.title'), function() {
                    $(this).hover(
						function(e) {
						    activate(e.target);
						    $(this).addClass('over');
						},
						function(e) {
						    $(this).removeClass('over');
						}
					);
                });


                var active = false;
                if (location.hash)
                    active = $(this).find('a[href=' + location.hash + ']')[0];

                if (active) {
                    activate(active, 'toggle', 'parents');
                    $(active).parents().show();
                }

                function activate(el, effect, parents) {
                    if (lasttarget != el.href && el.href != undefined) {
                        $(el)[(parents || 'parent')]('li').toggleClass('active').siblings().removeClass('active').children('div.def').slideUp('fast');
                        $(el).siblings('div.def')[(effect || 'slideToggle')]((!effect) ? 'fast' : null);
                        lasttarget = el.href;
                    }
                }

                if (first != null) {
                    activate($(this).find('a[href=#1]')[0]);
                }

            });
        }
    });

})(jQuery);


