(function($){
	$.fn.tipText = function (opts) {
			var __ele = $(this);
			opts = $.extend({
				tipAttr: 'tipText',
				tipColor: '#cccccc',
				defaultColor: '#000000',
				form:null
			}, opts || {});
			
			$(opts.form).submit(function(){
				if($(__ele).val() == $(__ele).attr(opts.tipAttr)){
					$(__ele).val('');
				}
			});
	
			$(__ele).blur(function () {
				if ($.trim($(this).val()).length == 0 || $(this).val() == $(this).attr(opts.tipAttr)) {
					with ($(this)) {
						css('color', opts.tipColor);
						val(attr(opts.tipAttr));
					}
				} else {
					$(this).css('color', opts.defaultColor);
				}
			});
	
			$(__ele).focus(function () {
				$(this).css('color', opts.defaultColor);
				if ($.trim($(this).val()).length == 0 || $(this).val() == $(this).attr(opts.tipAttr)) {
					$(this).val('');
				}
			});
	
			$(__ele).blur();
	};
	
	$.fn.popup = function (opts) {
			var __ele = $(this);
			opts = $.extend({
				closeBtn: '.close'
			}, opts || {});
	
			$(opts.closeBtn).click(function () {
				close();            
				return false;
			});
	
			var _mask = $('<div></div>');
			$(_mask).css("background", "#000000")
					   .css("filter", "alpha(opacity=0.5)")
					   .css("opacity", "0.5")
					   .css("width", "100%")
					   .css("height", $(document).height() + "px")
					   .css("position", "absolute")
					   .css("left", "0px")
					   .css("top", "0px")
					   .css("z-index", "9998");
			$('body').append(_mask);
			
			$(__ele).css("display", "block");
	
			function redraw() {
				var dw = $("body").width();
				var dh = $(document).height();
				var wh=$(window).height();
				var st=$('body')[0].scrollTop;
				var w = $(__ele).width();
				var h = $(__ele).height();
				$(__ele).css("left", (dw - w) / 2 + "px")
						.css("top", (wh - h) / 2+st + "px")
						.css("position", "absolute")
						.css("z-index", "9999");
	
				$(_mask).css("width", "100%")
						.css("z-index", "9998")
						.css("height", $(document).height() + "px")
			}
	
			function close() {
				$(_mask).remove();
				$(__ele).css("display", "none");
			}
			$(window).resize(function () {
				redraw();
			});
			redraw();
	};
})(jQuery);


