/**
 * jquery.simple_accordion.js
 * Copyright (c) qript (http://www.qript.co.jp/)
 * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
 * 
 * @author hibibi (http://hibibi.org/)
 * 
 * @projectDescription jQuery plugin for simple accordion.
 * 
 * @param activeClass	クリックしたトリガーにつくクラスです。初期状態でこのクラスをつけると開いた状態になります。
 * @param speed		開閉時のスピードです。初期値は「fast」が代入されています。
 * @param trigger	クリックするエリアにつけるクラス名です。
 * 
 **/

(function($){
    
    
    $.fn.simple_accordion=function(config){
        //デフォルトの値
        var defaults={
            activeClass:'active',
            speed:'fast',
            trigger:'.trigger'
        };
        //コンフィグで渡された値をマージ
        var options=$.extend(defaults, config);
        //functionの中からthisを参照するためにhomeに代入
        var home = this;
        //triggerを探す
        var trigger = this.find(options.trigger);
        //#リンクの無効化
        
        trigger.children('a').click(function(e) { 
            e.preventDefault();
        });
        //HTML上にactiveがある場合は、それを開く
        trigger.each(function(i){
            if(!$(this).children('a').hasClass(options.activeClass)){
                $(this).next().hide(0);
            }
        });
        //各トリガーをクリックした時の挙動
        trigger.click(function(){
            var handle = this;
            trigger.each(function(i){
                if(this == handle){
                    $(this).next().slideToggle(options.speed);
                    $(this).children('a').toggleClass(options.activeClass);
                }else{
                    $(this).next().slideUp(options.speed);
                    $(this).children('a').removeClass(options.activeClass);
                }
            });
        });
        return this;
    };
    
})(jQuery);


