var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
var loginFlag = 0;

function InstantMessage(imid) {
	if(loginFlag == 1) {
		$('imLoader').src = "http://www.topeye.cn:8400/im/html/" + imid + ".html";
		showMsg();
	}
}

function PiledMessage(messageid) {
	loginFlag = 1;
	currentIm = 0;
	imArray = messageid.split(",");
	showDiv();
	$('piledLoader').src = "http://www.topeye.cn:8400/im/html/" + imArray[currentIm] + ".html";
	enableButtons();
}

function onLoginOut() {
	loginFlag = 0;
}

function loadImSwf(url) {
	var flashvars = {};
	var params = {};
	params.allowscriptaccess = "always";
	swfobject.embedSWF(url, "imDiv", "100", "62", "9.0.0", false, flashvars, params);
}

function closeWindow() {
	window.opener = null;
	window.open("", "_self");
	window.close();
	if(!window.event) {
		window.open("about:blank", "_self");
	}
}

function showMsg() {
    try {
		divTop = parseInt($("eMeng").style.top,10);
		divLeft = parseInt($("eMeng").style.left,10);
		divHeight = parseInt($("eMeng").offsetHeight,10);
		divWidth = parseInt($("eMeng").offsetWidth,10);
		docWidth = document.body.clientWidth;
		docHeight = document.body.clientHeight;
		$("eMeng").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
		$("eMeng").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth;
		$("eMeng").style.visibility="visible";
		objTimer = window.setInterval("moveDiv()",1);
		
		//window.setTimeout("closeDiv()", 10000);
    } catch(e){}
}

function resizeDiv() {
    try {
		divHeight = parseInt($("eMeng").offsetHeight,10);
		divWidth = parseInt($("eMeng").offsetWidth,10);
		docWidth = document.body.clientWidth;
		docHeight = document.body.clientHeight;
		$("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10);
		$("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10);
    } catch(e){}
}

function moveDiv() {
    try {
		if(parseInt($("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10))) {
			window.clearInterval(objTimer);
			objTimer = window.setInterval("resizeDiv()",100);
		}
		divTop = parseInt($("eMeng").style.top,10);
		$("eMeng").style.top = divTop - 2;
    } catch(e){}
}

function closeDiv() {
    $('eMeng').style.visibility='hidden';
    if(objTimer) window.clearInterval(objTimer);
}

/*-------------------------------------------
	居中窗口
--------------------------------------------*/

var currentIm, imArray;

function showDiv() {
	$('popDiv').style.display='block';
	$('popIframe').style.display='block';
	$('bg').style.display='block';
}

function closeCenterDiv() {
	$('popDiv').style.display='none';
	$('bg').style.display='none';
	$('popIframe').style.display='none';
}

function previous() {
	currentIm--;
	$('piledLoader').src = "http://www.topeye.cn:8400/im/html/" + imArray[currentIm] + ".html";
	enableButtons();
}

function next() {
	currentIm++;
	$('piledLoader').src = "http://www.topeye.cn:8400/im/html/" + imArray[currentIm] + ".html";
	enableButtons();
}

function enableButtons() {
	if(currentIm == 0) {
		$('previous').disabled = true;
	}else {
		$('previous').disabled = false;
	}
	
	if(currentIm == (imArray.length - 1)) {
		$('next').disabled = true;
	}else {
		$('next').disabled = false;
	}
}

function $(id) {
	return document.getElementById(id);
}