﻿var isShowObj = false;
var isShowObjEnd = false;
var maxShowNum = 10;
var nowShowNum = 9;
var vWidth = 450;
var vHeight = 300;
var thisObj = null;
var bigBG = null;
var contentHTML = "";//全局变量定义
//浏览器资料获取，x = w/h/x/y
var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
function IeTest(){return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;}
function MoveObj(obj,x,y){obj.style.left=x+"px";obj.style.top=y+"px";if(arguments.length >= 4){obj.style.width = arguments[3]+"px";obj.style.height = arguments[4]+"px";}}
function GetClientInfo(x){	switch (x)	{case "w":	return ns ? innerWidth : IeTest().clientWidth;	case "h": return ns ? innerHeight : IeTest().clientHeight;	case "x":	return ns ? pageXOffset : IeTest().scrollLeft;	case "y":	return ns ? pageYOffset : IeTest().scrollTop;}}
function Pose(x, y) {	this.x = x;	this.y = y;}
function ShowObj()
{
	if(arguments.length >= 2)//初始化全局变量
	{
		thisObj = $(arguments[0]);		//对象
		bigBG = $(arguments[1]);		//背景
		contentHTML = "loading...<a href='javascript:CloseObj();'>Close</a>";
		var outWinUrl = arguments.length >= 6 ? arguments[5]:"";
		var isApplicationSchool = arguments.length >= 7 ? true:false;
		if(isApplicationSchool)
			PostInfo("/ajax/" + arguments[0] + ".aspx",
				function(data){
					contentHTML = data;
					if(isShowObjEnd && thisObj.innerHTML!=contentHTML){ thisObj.innerHTML=contentHTML;}
				},"id",arguments[5],"name",arguments[6],"url",arguments[7],"x",(new Date()).getTime()+"");//读取内容
		else
			PostInfo("/ajax/" + arguments[0] + ".aspx",
				function(data){
					contentHTML = data;
					if(data+"" == "1" && (outWinUrl.length>1?true:false))
					{
						CloseObj();
						var newWindow = window.open(outWinUrl);
						if(newWindow==null)
						{	location.href = outWinUrl;} //已经登录，跳转
						
					}
					else
					{
						if(isShowObjEnd && thisObj.innerHTML!=contentHTML){ thisObj.innerHTML=contentHTML;}
					}
				},"x",(new Date()).getTime()+"");//读取内容
		maxShowNum = 10;
		nowShowNum = 9;
		if(arguments.length >= 5)
		{
			vWidth = parseInt(arguments[2]);	//宽
			vHeight = parseInt(arguments[3]);	//高
			maxShowNum = parseInt(arguments[4]);	//次数
			nowShowNum = maxShowNum - 1;
		}
		isShowObj = true;
		var nLeft = new Pose(GetClientInfo("x"),GetClientInfo("y"));
		MoveObj(bigBG,0,nLeft.y,GetClientInfo("w"),GetClientInfo("h") + 400);
		if(navigator.Actual_Name == "Microsoft Internet Explorer" && parseInt(navigator.Actual_Version) <= 6)
			{ bigBG.className = "bigBG_b";}
		bigBG.style.display = "block";//背景
		thisObj.innerHTML = "";//去掉内容
		BeginObj();
		thisObj.style.display = "block";//显示
	}
}
function CloseObj()
{
	isShowObj = false;
	isShowObjEnd = false;
	bigBG.style.display = "none";
	thisObj.style.display = "none";//关闭
	thisObj.innerHTML = contentHTML = "";
	thisObj = null;
	bigBG = null;
}
function BeginObj()
{
	var nChat = new Pose(vWidth / maxShowNum * (maxShowNum - nowShowNum),vHeight / maxShowNum * (maxShowNum - nowShowNum));
	var nBody = new Pose(GetClientInfo("w"),GetClientInfo("h"));
	var nLeft = new Pose(GetClientInfo("x"),GetClientInfo("y"));
	var xLeft = new Pose(((nBody.x - vWidth + 20) / 2) + nLeft.x,((nBody.y - vHeight + 30) / 2) + nLeft.y);
	var mLeft = new Pose(xLeft.x + (vWidth - nChat.x) / 2,xLeft.y + (vHeight - nChat.y) / 2);
	if(isShowObj){ MoveObj(thisObj, mLeft.x, mLeft.y, nChat.x, nChat.y);}
	if((nowShowNum--) > 0 )
	{	setTimeout("BeginObj()",10);}//效果
	else
	{	if(isShowObj) {isShowObjEnd = true;thisObj.innerHTML = contentHTML; ObjShow();}}//展示内容
}
function ObjShow()
{
	var nBody = new Pose(GetClientInfo("w"),GetClientInfo("h"));
	var nLeft = new Pose(GetClientInfo("x"),GetClientInfo("y"));
	var mLeft = new Pose(((nBody.x - vWidth + 20) / 2) + nLeft.x,((nBody.y - vHeight + 30) / 2) + nLeft.y);
	bigBG.style.top = nLeft.y - 200; //高
	MoveObj(thisObj, mLeft.x, mLeft.y, vWidth, vHeight);//显示
}
window.onscroll = function ScrollWindow() { if(isShowObj){ ObjShow();}}
window.onresize = function ResizeWindow() { if(isShowObj){ ObjShow();}}//事件响应

//拖动
var thisPose = null,isDown = false;
var tObj = null,mObj = null;
function BeginMove(obj,pObj)
{
	tObj = obj;
	mObj = $(pObj);
	ns ? document.addEventListener("mousemove",MoveIt,true): tObj.setCapture(); //设置鼠标捕捉
	isDown=true;//设置鼠标状态为按下状态
}
var MoveIt = function(a)
{
	if(isDown){
		if(thisPose==null&&mObj!=null)
			{thisPose = new Pose(ns ? parseInt(a.pageX)-parseInt(mObj.style.left) : parseInt(event.clientX)-parseInt(mObj.style.left),ns ? parseInt(a.pageY)-parseInt(mObj.style.top) : parseInt(event.clientY)-parseInt(mObj.style.top));}//获取鼠标相对位置	
	    if(thisPose!=null)
	    {		var tX = new Pose(ns ? a.pageX-thisPose.x : event.clientX-thisPose.x,ns ? a.pageY-thisPose.y : event.clientY-thisPose.y);
		MoveObj(mObj,tX.x,tX.y);}//移动
	}
}
function StopMove()
{
	isDown=false;//松开状态
	thisPose = null;
	ns ? document.removeEventListener("mousemove",MoveIt,true) : tObj.releaseCapture();//释放鼠标捕捉
}
document.onmousemove = function mmMove(){MoveIt();}
document.onmouseup= function noM(){if(isDown){StopMove();}}

//浏览器信息
function Browserinfo(){
	var Browser_Name=navigator.appName;
	var Browser_Version=parseFloat(navigator.appVersion);
	var Browser_Agent=navigator.userAgent;
	
	var Actual_Version,Actual_Name;
	
	var is_IE=(Browser_Name=="Microsoft Internet Explorer");
	var is_NN=(Browser_Name=="Netscape");
	
	if(is_NN){
		if(Browser_Version>=5.0){
			var Split_Sign=Browser_Agent.lastIndexOf("/");
			var Version=Browser_Agent.indexOf(" ",Split_Sign);
			var Bname=Browser_Agent.lastIndexOf(" ",Split_Sign);

			Actual_Version=Browser_Agent.substring(Split_Sign+1,Version);
			Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign);
		}
		else{
			Actual_Version=Browser_Version;
			Actual_Name=Browser_Name;
		}
	}
	else if(is_IE){
		var Version_Start=Browser_Agent.indexOf("MSIE");
		var Version_End=Browser_Agent.indexOf(";",Version_Start);
		Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End);
		Actual_Name=Browser_Name;
		
		if(Browser_Agent.indexOf("Maxthon")!=-1){
			Actual_Name+="(Maxthon)";
		}
		else if(Browser_Agent.indexOf("Opera")!=-1){
			Actual_Name="Opera";
			var tempstart=Browser_Agent.indexOf("Opera");
			var tempend=Browser_Agent.length;
			Actual_Version=Browser_Agent.substring(tempstart+6,tempend);
		}
	}
	else{
		Actual_Name="Unknown Navigator";
		Actual_Version="Unknown Version";
	}

	navigator.Actual_Name=Actual_Name;
	navigator.Actual_Version=Actual_Version;
	
	this.Name=Actual_Name;
	this.Version=Actual_Version;
}
Browserinfo();
