
var GAMESYS = GAMESYS || {};
GAMESYS.components = GAMESYS.components || {};


GAMESYS.components.PlaceholderTextBox = function (element, text) {
	
	var me = this;

	// If no text, leave with normal textbox
	if (!text) return;
	
	this._element = $j(element)[0];

	// If element not input, return
	if (this._element.tagName.toLowerCase () != 'input') return;	
	
	// If browser supports placeholder, use that
	if (this._element.placeholder != null) {

		this._element.placeholder = text;
		return;
	}
	

	if (this._element.type.toLowerCase () == 'password') {
		
		var textDiv = $j(document.createElement ('input')).attr ({ type: 'text', value: text, 'class': this._element.className  });

		if (this._element.value) {
			textDiv.hide ().insertAfter (this._element);

		} else {
			$j(this._element).hide ();
			textDiv.insertAfter (this._element);
		}
		
		
		$j(textDiv).bind ('focus', function () {
			textDiv.hide ();
			$j(me._element).show ().focus ();
		});	
			
		$j(this._element).bind ('blur', function () {
			if (!me._element.value) {
				$j(me._element).hide ();
				textDiv.show ();
			}
		});	
		
		
	} else {
		
		var focus = function () { if (me._element.value == text) me._element.value = ''; },
			blur = function () { if (!me._element.value) me._element.value = text; };
		
		$j(this._element).bind ({
			focus: focus,
			blur: blur
		});
		
		blur ();		
	}

};



