﻿(function($){
    //inline-block 処理
    var ex = {
        inlineBlock : function(targets){
            var ver = parseFloat($.browser.version)
            ,oldIE = $.browser.msie && (ver < 8 || !$.boxModel)
            ,oldMOZ = $.browser.mozilla && ver < 1.9;
            targets.css('display',
                oldIE ? 'inline' : oldMOZ ? '-moz-inline-box' : 'inline-block'
            );
            return targets;
        }
    }
    //place holder 処理
    $.ex = $.ex || {};
    $.ex.placeHolder = function(targets,option){
        var s = $.ex.placeHolder,
        c = $.extend({}, s.defaults,option);
        return targets.each(function(idx){
            var target = targets.eq(idx);   
            //ラベルの生成とスタイルの適用
            var label = $('<div>' + (target.attr(c.labelAttName) || c.label) + '</div>')
                .css({
                    width : target.width(),
                    overflow : 'hidden',
                    position:'absolute',
                    top : c.top + c.topAdjust,
                    left :c.left,
					fontWeight : 'normal',
                    color : c.color
                });
                !c.css || label.css(c.css);
            //inline-block の適用
            ex.inlineBlock(
                target.wrap('<div style="position:relative"/>').parent().append(label)
            );
            //ラベルの表示・非表示イベントの割り当て
            target.bind('focus blur',function(evt){
                s.display(target,label,evt.type == 'focus');
            }),
            label.click(function(){target.focus()})
            s.display(target,label);
        });
    };
    $.ex.placeHolder.display = function(target,label,focus){
        label[!focus && target.val() == '' ? 'show' : 'hide']();
    }
    $.ex.placeHolder.defaults = {
        labelAttName : 'def', //タイトル属性の内容がラベルになる
        label : '', //パラメータによるラベルメッセージの指定
        top : 3, //ラベルの垂直位置調整
        left : 3, // ラベルの水平位置調整
        topAdjust : - ($.browser.opera ? 2 : 0), //表示位置の微調整
        color : '#999999', //ラベルのカラー
		fontWeight : 'normal',
        css : null //ラベルの一括 style 指定
    }
    $.fn.exPlaceHolder = function(option){
        return $.ex.placeHolder(this,option);
    };
})(jQuery);
