/*
 * jquery.placeholder - A plugin for select fields
 * Written by Ben McFarlin (ben dot mcfarlin AT blinkcorp DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 11/23/2009
 * there is no placeholder support in ie or firefox so we must add it
 * 
 * @author Ben McFarlin
 * @version 1.0.0
 */
(function($) {
	$.fn.placeholder = function(settings) {
		var config = {};
		if (settings) $.extend(config, settings);

		return this.each(function(i, self) {
			switch($(self).tagName()){
				case 'input':
					if(jQuery.browser.msie || jQuery.browser.mozilla){
						$(self).after($('<span>').css({position:'absolute',display:'inline-block','margin-left':'4px','margin-top':'2px','text-indent':($(self).val() == '')?'0':'-10000px',top:$(self).position().top,left:$(self).position().left,color:'#737373'}).html($(self).attr('placeholder')));
			      $(self).focus(function(){$(self).next().css('text-indent', '-10000px');});
			      $(self).blur(function(){if($(self).val() == '') {$(self).next().css('text-indent', '0');}});
						$(self).next().click(function(){$(self).focus();});
					}
				break;
				case 'select':
					//$(self).prepend($('<option>').attr('value','').html($(self).attr('placeholder')));
          //alert($(self).outerHTML());
          //$(self).find('option').each(function(i, o){
          //  alert($(this).attr('selected'));
          //});
          
          //var selected = $(self).find('option[selected]');
          
					$(self).html($('<option>').attr('value','').html($(self).attr('placeholder')).outerHTML() + $(self).html());
					$(self).css('color', ($(self).val() == '')?'#737373':'#313131').children('option').each(function(i, option){$(option).css('color', ($(option).attr('value') == '')?'#737373':'#313131');});
					$(self).change(function(){$(self).css('color', ($(self).val() == '')?'#737373':'#313131');});
					$(self).val('');

				break;
			}
			return $(self);
			// ok you need to get the placeholder text
			// then create the div
			// then append it after the element
			// position it
		});
		
		function trace(s){
			if(window.console) window.console.log(s);
		}
	};
 })(jQuery);




