/*
 * 	exPlaceHolder 0.1.1 - jQuery plugin
 *	written by Cyokodog	
 *
 *	Copyright (c) 2010 Cyokodog (http://d.hatena.ne.jp/cyokodog/)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
(function($){

	var ex = {
		inlineBlock : function(targets){
			var ver = parseFloat($.browser.version)
			,oldIE = $.browser.msie && (ver < 9 || !$.boxModel)
			,oldMOZ = $.browser.mozilla && ver < 1.9;
 			targets.css('display',
				oldIE ? 'inline' : oldMOZ ? '-moz-inline-box' : 'inline-block'
			);
			return targets;
		}
	}

	$.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,
					color : c.color
				});
				!c.css || label.css(c.css);
			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 : 'title',
		label : '',
		top : 6,
		left : 5,
		topAdjust : - ($.browser.opera ? 2 : 0),
		color : '#a0a0a0',
		css : null
	}
	$.fn.exPlaceHolder = function(option){
		return $.ex.placeHolder(this,option);
	};

})(jQuery);

