//容器垂直水平置中
//使用方法：
//	$("#container").vAlign();
//	$("#container").hAlign();


(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
			var h = $(this).height();
			var oh = $(this).outerHeight();
			var mt = (h + (oh - h)) / 2;
			
			if(h>document.body.clientHeight) {
				$(this).css("margin-top","0");
				$(this).css("top", "0");
			} 
			else {
				$(this).css("margin-top", "-" + mt + "px");	
				$(this).css("top", "50%");
				$(this).css("position", "absolute");		
			};	
		});
	};
})(jQuery);

(function ($) {
	$.fn.hAlign = function() {
		return this.each(function(i){
			var w = $(this).width();
			var ow = $(this).outerWidth();	
			var ml = (w + (ow - w)) / 2;	
			
			if(w>document.body.clientWidth) {
				$(this).css("margin-left","0");
				$(this).css("left", "0");
			} 
			else {
				$(this).css("margin-left", "-" + ml + "px");
				$(this).css("left", "50%");
				$(this).css("position", "absolute");
			};
		});
	};
})(jQuery);
