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