// プラグインは以下のものをクロスブラウザ対応（topを変更するだけ）
// http://d.hatena.ne.jp/cyokodog/20090310/jQueryPlaceFolder01
// placeholder 属性に対応済みのブラウザを除く方法は以下を参照
// 判別しないと２重に表示される
// http://terkel.jp/archives/2010/07/html5-placeholder-fix-with-jquery/
// placeholder 属性を持つ全要素に適用させる例
//jQuery(function($j){
//	var supportsInputAttribute = function (attr) {
//		var input = document.createElement('input');
//		return attr in input; // 引数で指定された属性がサポートされていれば true を返す
//	};
//	// placeholder 属性に対応済みのブラウザでは何もしない
//	if (!supportsInputAttribute('placeholder')) {
//		// placeholder 属性を持つ全ての要素に jQuery.placeHolder() を適用
//		$j('[placeholder]').each(function(){
//			$j(this).placeHolder({
//				text:$j(this).attr('placeholder')
//			})
//		})
//	}
//});

(function($j){
	var placeHolder = function(target,cfg){
		var isOP=(window.opera)?true:false;
		var topPixel = -1;
		var isIE7_ = false;
		var isIE8 = false;
		if (!jQuery.support.htmlSerialize) {
			if(jQuery.support.style){
				isIE8 = true;
			} else {
				isIE7_ = true;
			}
		}
		if (isIE8) {
			topPixel = -9;
		} else if (isIE7_) {
			topPixel = 7;
		} else if (isOP) {
			topPixel = 5;
		}
		var o=this;
		var c=o.cfg=$j.extend({
			target:target,
			text:'input here...',
			top:topPixel,
			left:4,
			labelCSS:null //追加
		},cfg);
		o._build();
	};
	$j.extend(placeHolder.prototype,{
		_build:function(){
			var o=this,c=o.cfg;
			c.container=c.target
				.wrap('<span style="position:relative;"/>')
				.parent();
			c.label=c.container
				.append('<div class="placeHolder-label" \
							style="position:absolute;color:#aaa;">'+
					c.text+'</div>')
				.find('> :last-child')

//IE6 の場合 body{font-size:80%} とか input{font-size:80%} とかしてると
//$('input').css('font-size')ででかい値が px 単位で取れてしまい
//プレースホルダの文字がばかでかくなってしまう。
//   http://h2ham.seesaa.net/article/106524977.html
//で、currentStyle.fontSizeの値をあてるとbody{font-size:80%}の相対的な
//サイズになるので今度は小さくなる。
//input要素自体のサイズを変更することはあまり無いと思うのでここでは何も
//せず、パラメータで上書き可能にする

				.css({
//				  'font-size':c.target.css('font-size'),	 //削除
					'font-family':c.target.css('font-family'),
					top:c.top,
					left:c.left
				});

			if(c.labelCSS)c.label.css(c.labelCSS);  //追加

			c.label.click(function(){
				o.toggleLabel(true);
				c.target.focus();
			});
			c.target.focus(function(){o.toggleLabel(true)});
			c.target.blur(function(){o.toggleLabel(false)});
			o.toggleLabel();
		},
		toggleLabel : function(isFocus){
			var o=this,c=o.cfg;
			c.label[isFocus||c.target.val()!=''?'hide':'show']();
			return o;
		}
	});
	$j.fn.placeHolder = function(cfg){
		var o=this;
		return o.each(function(idx){
			new placeHolder(o.eq(idx),cfg);
		})
	}   
})(jQuery);

