$(function(){
	var TFTSwapper = function(opts){
		
		this.user_toggle = function(node){
			if(node.attr('value').length > 0 && node.attr('value') == 'username') node.attr('value', '');
			else if(node.attr('value').length == 0) node.attr('value', 'username');
		}
		
		this.init_type_swap = function(node){
			this.swap = function(s_node, h_node){
			
				//alert(typeof s_node);
			
				h_node.hide();
				s_node.show();		
			}
			var id       = node.attr('id');
			var txt_node = $('#' + id + '_text');
			
			node.hide();
			txt_node.show();
			
			txt_node.focus(function(){
				obj.swap(node, $(this));
				node.focus();
			});
			
			node.blur(function(){
				// don't swap if there's a value
				if($(this).attr('value').length > 0) return false;
				obj.swap(txt_node, $(this));
			});
		}
		
		var obj      = this;
		var defaults = {};	
		
		// merge options with defaults
		this.opts = $.extend({}, defaults, opts);
		
		// bind execution events
		$("#txtToolUserName").bind({
			focusin:  function(){ obj.user_toggle($(this)); },
			focusout: function(){ obj.user_toggle($(this)); }
		});		

		// automatize first swap
		obj.init_type_swap($("#txtToolPass"));
		
	};
	
	// extends jquery
	$.extend({
		tft_swapper: function(opts){
			var tft_swapper = new TFTSwapper(opts);
		}
	});
});

// autolaunch when included
$(function(){
	$.tft_swapper({});
})
