﻿
$.showBox =
{
    imgBox: function(_this, setting) {
        $.showBox.def(_this, setting);
        _this.find(setting.button).click(
            function() {
                if ($(this).attr(setting.selectedButtonAttr) == setting.selectedButtonAttrValue && setting.ishide) {
                    $.showBox.hide(_this, setting);
                }
                else {
                    $.showBox.hide(_this, setting);
                    $(this).attr(setting.selectedButtonAttr, setting.selectedButtonAttrValue);
                    $(this).parents(setting.buttonBox).find(setting.selectedBox).show();
                }
            });
    },
    hide: function(_this, setting) {
        _this.find(setting.button).attr(setting.buttonAttr, setting.titleAttrValue);
        _this.find(setting.box).hide();
    },
    def: function(_this, setting) {
        $.showBox.hide(_this, setting);
        _this.find(setting.button)[0].src = setting.selectedButtonAttrValue;
        _this.find(setting.box + ":first").show();
    }


}


 $.fn.showBox = function(options) {

        var defaults = {
            button: '.askbox span img',  //链接按钮
            buttonAttr: 'src',    //按钮一般属性
            titleAttrValue: 'images/comm/dot/dot13.gif', //按钮一般属性属性值
            selectedButtonAttr: 'src', //选中属性
            selectedButtonAttrValue: 'images/comm/dot/dot14.gif', //选中属性值
            buttonBox: '.askbox',
            box: '.ansbox', //展示框
            selectedBox: '~.ansbox', //选中
            ishide:true
            
        };

        var opt = $.extend(defaults, options);

        return this.each(function(){

        $.showBox.imgBox($(this), defaults);
        });
}






