var SC = {
	isIE : function(){
		var aNUT = navigator.userAgent.toLowerCase();
		return ((aNUT.indexOf("msie") != -1) && (aNUT.indexOf("opera") == -1) && (aNUT.indexOf("omniweb") == -1));
	},
	Lang : function(){
		var xLang;
		var sGET = location.search;
		sGET = sGET.replace('?','');
		sGET = sGET.split('/');
		for(i=0; i<sGET.length; i++){
			if(sGET[i].slice(0,1) == 'l'){
				xLang = sGET[i].slice(1);
			}
		};
		var strCheck = function(str){
			if(str == null) { return false; }
			var strFormat = "0123456789";
			for(var i=0;i<str.length;i++){
				if(strFormat.indexOf(str.substr(i,1)) == -1){
					return false;
				}
			}
			return true;
		};
		if(strCheck(xLang) == false) xLang = 1;
		return xLang;
	},
	couplet : function(){
		if(arguments.length>=1)	this.objID = document.getElementById(arguments[0]);
		if(arguments.length>=2)	this.divTop = arguments[1];
		if(arguments.length>=3) this.divPlane = arguments[2];
		if(arguments.length>=4)	this.scrollDelay = arguments[4];
		if(arguments.length>=5) this.waitTime = arguments[5];
		if(!this.objID){
			alert("对象名【"+ arguments[0] +"】无效，对联无法初始化，请检查对象名称是否正确！");
			this.objID = null; return;
		}else{
			this.objID.style.position = "absolute";
			this.objID.style.display = "block";
			this.objID.style.zIndex = 9999;
		}
		if("" == this.objID.style.top){
			if(isNaN(this.divTop)){
				alert("对象垂直位置(top)参数必须为数字。"); return;
			}else{
				this.objID.style.top = this.divTop+"px";
			}
		}
		if("" == this.objID.style.left && "" == this.objID.style.right){
			if(isNaN(this.divPlane)){
				alert("对象水平位置(left||right)参数必须为数字。"); return;
			}
			if(this.divPlane>0) this.objID.style.left = this.divPlane+"px";
			if(this.divPlane<0) this.objID.style.right = Math.abs(this.divPlane)+"px";
		}
		if(this.scrollDelay<15 || isNaN(this.scrollDelay)) this.scrollDelay = 10; 
		if(this.waitTime<500 || isNaN(this.waitTime)) this.waitTime = 500; 
		if(arguments.length>=1) this.start();
	},
	start : function(){
		if(null == this.objID) return;
		var objCouplet = this;
		timer = this.scrollDelay;
		objCouplet.lastScrollY = 0;
		objCouplet.timerID = null;
		objCouplet.startID = function(){
			if("block" == objCouplet.objID.style.display){
				objCouplet.run();
			}else{
				clearInterval(objCouplet.timerID);
			}
		}
		objCouplet.Begin = function(){
			objCouplet.timerID = setInterval(objCouplet.startID,timer);
		}
		setTimeout(objCouplet.Begin,this.waitTime);
	},
	run : function(){
		if(document.documentElement && document.documentElement.scrollTop){
			uu_scrY = parseFloat(document.documentElement.scrollTop);
		}else if(document.body){
			uu_scrY = parseFloat(document.body.scrollTop);
		}
		uu_divX = parseFloat(this.objID.style.top.replace("px",""));
		uu_curTop = .1 * (uu_scrY - this.lastScrollY);
		uu_curTop = uu_curTop>0?Math.ceil(uu_curTop):Math.floor(uu_curTop);
		this.objID.style.top = parseFloat(uu_divX + uu_curTop) + "px";
		this.lastScrollY += uu_curTop; 
	},
	float : function(){
		$.getScript("./config/communication.php",function(){
			var xTop = Communication['Top']; 
			var xAlign = Communication['Align']; 
			var xLevel = Communication['Level']; 
			if(Communication['isOpen'] == 0) return false; 
			if(SC.Lang() == 1){ 
				var topimg = "images/qq_top.gif";
				var bttimg = Communication['Align'] == 0 ? "images/qq_left.gif" : "images/qq_right.gif";
			} else {
				var topimg = "images/qq_top_en.gif";
				var bttimg = Communication['Align'] == 0 ? "images/qq_left_en.gif" : "images/qq_right_en.gif";				
			}
			var boardDiv = '<div id="xMyQQ"><table id="Uphold" width="118" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="' + topimg + '" /></td></tr>';
			boardDiv += '<tr><td background="images/qq_bg.gif" align="center">';
			boardDiv += '<table border="0" cellpadding="0" cellspacing="0" align="center">';
			for(i=0; i < (Communication['Code'].length); i++){
				boardDiv += '<tr><td style="padding:6px 0;" align="center">' + Communication['Code'][i] + '</td></tr>';
			};
			boardDiv += '</table>';
			boardDiv += '</td></tr>';
			boardDiv += '<tr><td><img src="images/qq_bottom.gif" width="118" height="25" /></td></tr></table>';
			boardDiv += '<table id="Shrink" width="33" border="0" cellpadding="0" cellspacing="0">';
			boardDiv += '<tr><td><img src="' + bttimg + '" /></td></tr></table></div>'; 
			$(document.body).append(boardDiv); 
			$("#xMyQQ").css("position","absolute");
			$("#xMyQQ").css("top",xTop);
			if(xAlign == 0){
				$("#xMyQQ").css("left",xLevel);
			} else {
				$("#xMyQQ").css("right",xLevel);
			};
			$("#xMyQQ").css("z-index",9999);
			if(xAlign == 1) xLevel = "-" + xLevel;
			SC.couplet("xMyQQ",xTop,xLevel); 
			if(Communication['isOpen'] == 1){ 
				var xSpeed = SC.isIE() ? 300 : 200; 
				$("#Uphold").hide(); 
				$("#Shrink").mouseover(function(){ 
					$("#Shrink").hide(); 
					$("#Shrink").hide(function(){ 
						$("#Uphold").show(xSpeed); 
					});
				});
				$("body").click(function(){ 
					$("#Uphold").hide();
					$("#Uphold").hide(function(){ 
						$("#Shrink").show(xSpeed); 
					});
				});
			} else { 
				$("#Shrink").hide(); 
			} 			
			return true;
		});		
	}
};
$(document).ready(function(){
	SC.float(); 
	jQuery.getScript('js/gbtobig.js'); 
});
