jQuery.fn.extend({
	//元素居中插件
	center:function(){
		var w=$(this).width();
		var h=$(this).height();
		var cliHeight=$(document).cliHeight();
		var docHeight=(cliHeight/2-h/2)+$(document).getScrollTop();
		var docWidth=$(document).docWidth()/2-w/2;
		$(this).css({position:'absolute',top:docHeight,left:docWidth});
	},
	//弹出窗口插件
	window:function(data,options,callback){
		options=options||{};
		callback=callback||function(){};
		if(jQuery.isFunction(options)){
			callback=options;
			options=null;
		};
		var defaults={
			url:false,
			name:'window',
			title:$(this).text(),
			modal:true,
			width:'auto',
			height:'auto'
		};
		var url=options.url||defaults.url;
		var name=options.name||defaults.name;
		var title=options.title||defaults.title;
		var modal=options.modal||defaults.modal;
		var width=options.width||defaults.width;
		var height=options.height||defaults.height;
		if($('#'+name).length>0)$('#'+name).remove();
		if(modal){
			var w=$(document).docWidth();
			var h=$(document).docHeight();
			$('body').append('<div id="modal-'+name+'" class="modal"></div>');
			$('#modal-'+name).css({width:w,height:h,opacity:0.1}).show();
		};
		$('body').append('<div id="'+name+'" class="window"><div class="dropshadow"><div class="handle"><span><input type="image" src="/images/close.gif" alt="关闭">'+title+'</span></div><div class="content">Loading...</div></div></div>');
		$('#'+name).show().css({width:width,height:height}).draggable({handle:'.handle'}).find('.handle input[type=image]').click(function(){
			$('#'+name).close();
		});
		$('#'+name).center();
		if(url){
			$.get(data,function(d){
				$('#'+name).find('.content').html(d).selectFormat();
				$('#'+name).find('input[type=text]:first').select();
				$('#'+name).find('textarea[type=fckeditor]').addClass('fckeditor').each(function(){
					var w=$(this).width();
					var h=$(this).height();
					$(this).fck({path:'/fckeditor/',toolbar:'Asia',width:w,height:h});
				});
				$('button[type=submit]').css({fontWeight:'bold'}).attr('disabled',true);
				$('#'+name).find(':input,iframe').bind('propertychange',function(){
					$('button:disabled').attr('disabled',false);
				});
				$('#'+name).find('.handle').css({width:$('#'+name).width()-8});
				$('#'+name).center();
				callback.apply(this);
			});
		};
	},
	close:function(){
		$('.window').remove();
		$('.modal').remove();
	},
	//获取网页可见区域高度
	docHeight:function(){
		if ($.browser.msie && $.browser.version<7){
			var scrollHeight=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
			var offsetHeight=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);
			if(scrollHeight<offsetHeight){
				return $(window).height();
			}else{
				return scrollHeight;
			};
		}else{
			return $(document).height();
		};
	},
	//获取网页可见区域宽度
	docWidth:function(){
		if ($.browser.msie&&$.browser.version<7) {
			var scrollWidth=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth);
			var offsetWidth=Math.max(document.documentElement.offsetWidth,document.body.offsetWidth);
			if (scrollWidth<offsetWidth){
				return $(window).width();
			}else{
				return scrollWidth;
			};
		} else {
			return $(document).width();
		};
	},
	//获取滚动条高度
	getScrollTop:function(){
		IeTrueBody=function(){
			return (document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;
		};
		return $.browser.msie?IeTrueBody().scrollTop:window.pageYOffset;
	},
	//内容可视区域高度
	cliHeight:function(){
		return document.documentElement.clientHeight;
	}
});