// RollOver
$(function () {
    $.rollover = {
        init: function () {
            $('a img,input[type="image"]').not('[src*="_on."]').not("#fontsize_switch a img")
                .bind('mouseover', this.over)
                .bind('mouseout',  this.out)
                .each(this.preload);
        },
        over : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_off.', '_on.'));
        },
        out : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_on.', '_off.'));
        },
        preload : function () {
            new Image().src = this.getAttribute('src').replace('_off.', '_on.');
        }
    };

    $.rollover.init();

    $.fn.formSelector = function(options) {
        return this.each(function(i, e){
            var o = $.extend({}, {
                customTextClass: null,
                customRadioClass: null,
                customCheckboxClass: null,
                customSubmitClass: null,
                customButtonClass: null
            }, options || {});

            $(this)
                .find(":text").addClass(o.customTextClass ? o.customTextClass : "text")
                    .end()
                .find(":radio").addClass(o.customRadioClass ? o.customRadioClass: "radio")
                    .end()
                .find(":checkbox").addClass(o.customCheckboxClass ? o.customCheckboxClass: "checkbox")
                    .end()
                .find(":submit").addClass(o.customSubmitClass ? o.customSubmitClass : "submit")
                    .end()
                .find(":button").addClass(o.customButtonClass ? o.customButtonClass : "button");
        });
    };


    $.fn.opacityOver = function (opts) {
        var o = $.extend({}, { level: .75 }, opts || {});

        return this.hover(function(){
            $(this).css("opacity", o.level);
        }, function(){
            $(this).css("opacity", 1);
        });
    };


    $(function(){
        var $f = $("form");
        // フォームセレクタ（クラスを付与）
        if($f.size() > 0) {
            $f.formSelector();
        }

        // 透明度ロールオーバー
        $(".opacity-over").opacityOver();

        // フォントサイズ
        jQuery.laquu.fss(jQuery("#fontsize_switch"), {
            css_file: false,
            onChange: function(el, elms) {
                var e = jQuery(el).find("img");
                elms.find("img").not(":first").each(function(){
                    var _e = jQuery(this);
                    _e.attr("src", _e.attr("src").replace("_on", "_off"));
                });
                e.attr("src", e.attr("src").replace("_off", "_on"));
            },
            current: "default"
        });
    });
    
    Shadowbox.init();
});
