var ROOT = 'http://192.168.1.103/wanyan/WebRoot/';

//ROOT = CTX+'/';

;(function($) {
	
	$.InSightCN =  { 
		//START 浏览器检测
		userAgent : navigator.userAgent.toLowerCase(),
		
		Mozilla : $.browser.mozilla,	//判断是否Mozilla浏览器
		
		Safari : $.browser.safari,		//判断是否Safari浏览器
		
		Opera : $.browser.opera,		//判断是否Opera浏览器
		
		IECheck: {		//判断IE版本
			IE : $.browser.msie,
			IE8 : $.browser.msie && /MSIE\s(8\.)/.test(navigator.userAgent),
			IE7 : $.browser.msie && /MSIE\s(7\.)/.test(navigator.userAgent),
			IE6 : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)
		},
		
		
		getVersion: function() {		//获得浏览器版本信息
			return $.browser.version;
		}, //END 浏览器检测
		
		
		
		x_center : function() {		//页面的中心点--x
			var x = ($.InSightCN.getPageWidth() - $.InSightCN.getPageScroll()[0])/2;
			return x > 0 ? x : 0;
		},
		
		y_center : function() {		//页面的中心点--y
			var y = ($.InSightCN.getPageHeight() - $.InSightCN.getPageScroll()[1])/2;
			return y > 0 ? y : 0;
		},
		
		getPageScroll : function() {	//获得浏览器滚动条的宽和高
			return [
				self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft,
				self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop
			];
		},
		
		getPageWidth : function() {	//获得浏览器的页面宽度
			return self.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
		},
		
		getPageHeight : function() {	//获得浏览器的页面高度
			return self.innerHeight ||  (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
		},
		
		/*
		 *	@param boxObj, 滚动的盒子对象
		 *	@param duration, true则平滑滑动，false则直接设置css
		 *
		*/
		boxScroll : function(boxObj, duration) {		//盒子随滚动条上下滚动
			boxObj.each(function() {
				var box = $(this);
				//若该盒子是在有上下滑动后出现的，则top应先减去滚动条的高度
				var top = box.offset().top - $.InSightCN.getPageScroll()[1] >= 0 ? box.offset().top - $.InSightCN.getPageScroll()[1] : 0;
			
				$(window).scroll(function (){
					var offsetTop = top + $(window).scrollTop();
					if(duration) {
						box.animate({'top' : offsetTop}, {duration:500, queue:false});
					} else {
						box.css({'top' : offsetTop});
					};
				}); 
			});
		},
		
		/*
		 *	@param boxObj, 待关闭的盒子对象
		 *	@param clickObj, 关闭按钮对象
		 *	@param duration, 是否渐隐关闭 true|false
		 *
		*/
		close : function(boxObj, clickObj, duration) {		//关闭盒子对象
			clickObj.click(function() {  
				boxObj.each(function() {					
					if(duration) {
						//IE6特殊情况，若存在.pngFix-bg
						if(boxObj.next('.pngFix-bg').is(':visible')) {
							boxObj.next('.pngFix-bg').fadeOut(function() {
								$(this).remove();
							});
						};
						$(this).fadeOut(function() {
							$(this).remove();
						});
					} else {
						//IE6特殊情况，若存在.pngFix-bg
						if(boxObj.next('.pngFix-bg').is(':visible')) {
							boxObj.next('.pngFix-bg').remove();
						};
						//背景shadow
						if($('#shadow:visible')) {
							$.InSightCN.shadow.close();
						};
						$(this).remove();
					};
				});
				
				return false;
			});
		},
		
		
		
		/*
		 *	@param opacity, 背景shadow的透明度
		 */
		shadow: {	//背景shadow
			create : function(opacity) {	//背景shadow
				var $shadow = $('<div id="shadow"></div>')
				$shadow.css({
					'position': $.InSightCN.IECheck.IE6 ? 'absolute' : 'fixed',
					'top': 0,
					'left': 0,
					'width': $.InSightCN.getPageWidth(),
					'height': $.InSightCN.getPageHeight(),
					'z-index': 5,
					'background': '#000',
					'opacity': opacity ? opacity : 0
				}).appendTo('body');		
				//$.InSightCN.IECheck.IE6 ? $.InSightCN.boxScroll('#shadow') : false;
			},
			
			close : function(timer) { 
				if(!timer) {
					timer = 500;
				};
				$('#shadow').fadeOut(timer, function() {
					$(this).remove();
				});
			}
		},
		
				
		/*
		 *	@param txtArr, 长度为4，依次为title, content, okBtn的text, cancleBtn的text
		 *	@param callbackArr, 长度为2，分别为两个btn的回调函数回调函数
		 */
		confirmBox: function(txtArr, callbackArr) {
			$.InSightCN.shadow.create(0.3);
			
			var $confirmBox =  $('<div id="confirmBox"></div>');
			
			$confirmBox.appendTo('body').css({
				'position': $.InSightCN.IECheck.IE6 ? 'absolute' : 'fixed'				
			}).append('<h3></h3>').find('h3').text(txtArr[0])
			.end().append('<div id="content"></div>').find('#content').html(txtArr[1])
			.end().append('<button id="okBtn">'+txtArr[2]+'</button>');
			
			if(txtArr[3]) {
				$confirmBox.append('<button id="cancleBtn">'+txtArr[3]+'</button>');
			};
			
			$confirmBox.css({
				'top': ($.InSightCN.getPageHeight() - $confirmBox.outerHeight())/2,
				'left': ($.InSightCN.getPageWidth() - $confirmBox.outerWidth())/2
			});
			
			//$.InSightCN.IECheck.IE6 ? $.InSightCN.boxScroll('#confirmBox') : false;
			
			$('#confirmBox').find('#okBtn').click(function() {																 
				confirmClose();
				if(callbackArr[0]) callbackArr[0]();
			}).end().find('#cancleBtn').click(function() {
				confirmClose();
				if(callbackArr[1]) callbackArr[1]();
			});
			
			var confirmClose = function() {
				$('#confirmBox').remove();
				$.InSightCN.shadow.close();
			};
		}
		
		
		
				
	};
	
	
	
})(jQuery);