var theatermodenow = false;
var theatermodesave = false;
function theatermode(notfirst){
	var notfirst = notfirst ? 1 : 0;
	//遮罩背景设置  
	var sWidth,sHeight; 
	sWidth = screen.availWidth; 
	if(screen.availHeight > document.body.scrollHeight){
		sHeight = screen.availHeight;	//少于一屏
	}else{
		sHeight = document.body.scrollHeight;	//多于一屏 
	}
	//创建遮罩背景 	
	var maskObj = document.createElement("div"); 
	maskObj.setAttribute('id','maskdiv'); 
	maskObj.style.position = "absolute"; 
	maskObj.style.top = "0"; 	
	maskObj.style.left = "0"; 
	maskObj.style.backgroundColor = '#000000'; 
	maskObj.style.filter = "Alpha(opacity=65);"; 
	maskObj.style.opacity = 0.7; 
	maskObj.style.width = sWidth + "px";
	maskObj.style.height = sHeight + "px";
	maskObj.style.zIndex = "10000"; 
	document.body.appendChild(maskObj);	
	//移动屏幕到页顶
	//document.documentElement.scrollTop = 0;
	//隐藏滚动条	
	document.body.style.overflowX = 'hidden';//ff
	document.getElementsByTagName('html')[0].style.overflowX = 'hidden';//ie
	
	/*
	var msgObj = document.createElement("div")
	msgObj.setAttribute("id","colsetheater");
	msgObj.style.position ="absolute";
	msgObj.style.top = "0px";
	msgObj.style.left = (screen.availWidth - 100) + "px";
	msgObj.style.width = "80px";
	//msgObj.style.height = msgh + "px";
	msgObj.style.fontSize = "12px";
	msgObj.style.background = '#FFF';
	msgObj.style.border = "1px solid #A9C9EA"; 
	msgObj.style.zIndex = "10001";
	msgObj.innerHTML = "&nbsp;<a href='javascript:void(null)' onclick='normalmode(1)'>关闭剧场模式</a>";
	document.body.appendChild(msgObj);
	*/
	
	theatermodenow = true;
	
	document.getElementById('theatermodehint').innerHTML = '<span  style="color:#4976AD;font-size:14px;font-weight:bold;cursor:hand;"></span>';
	reservY = currentY;
	reservX = currentX;
}


function normalmode(forcecomeback) {
	var forcecomeback = forcecomeback ? forcecomeback : 0;
	if (forcecomeback) {
		document.body.removeChild(document.getElementById("maskdiv")); 
		//document.body.removeChild(document.getElementById("colsetheater")); 
		theatermodenow = false;
	}
	clearInterval(intervalclock);		
	clocknow = 2;
	document.getElementById('theatermodehint').innerHTML = '<span style="color:#4976AD;font-size:14px;font-weight:bold;"><a href="javascript:void(null)" onMouseUp="gototheater()" style="color:#72B729"><img src="/img/theatre.gif" align="absmiddle" style="padding-right:3px">剧场模式</a></span>';	
	theatermodesave = false;
	if (typeof(kkp)!='undefined') {
		kkp.show(true);		
	}
}
//拖动窗口
var currentY,currentX,reservY,reservX,stopY=0,stopX=0;
var intervalclock;
var clocknow = 2;
  
function moveMouse(e) {
	var e = e || window.event;
	if (document.all) {
		currentX = e.clientX;
		currentY = e.clientY;	
	} else {
		currentX = e.pageX;
		currentY = e.pageY;	
	}	
	//document.getElementById('xyinfo').innerHTML = currentX+','+currentY;
	if (currentX-stopX>=10 || stopX-currentX>=10 || currentY-stopY>=10 || stopY-currentY>=10) {
		clocknow = 2;
		stopX = currentX;
		stopY = currentY;
	}
	if (currentX-reservX>=10 || reservX-currentX>=10 || currentY-reservY>=10 || reservY-currentY>=10) {
		
	} else {
		return false;
	}
	if (theatermodenow) {
		document.body.removeChild(document.getElementById("maskdiv")); 
		//document.body.removeChild(document.getElementById("colsetheater")); 
		theatermodenow = false;
		document.getElementById('theatermodehint').innerHTML = '<span style="font-size:12px;color:#727272;"><strong>3</strong>秒后..进入剧场模式，<a href="javascript:void(null)" onMouseUp="normalmode()" style="text-decoration:underline">取消</a></span>';
		clearInterval(intervalclock);
		intervalclock = setInterval('updateClock()', 1000);
		return false;
	}  
	//event.cancelBubble=true;
}   

function gototheater() {
	theatermodenow = false;
	theatermodesave = true;
	document.getElementById('theatermodehint').innerHTML = '<span style="font-size:12px;color:#727272;"><strong>3</strong>秒后..进入剧场模式，<a href="javascript:void(null)" onMouseUp="normalmode()" style="text-decoration:underline">取消</a></span>';
	clearInterval(intervalclock);
	intervalclock = setInterval('updateClock()', 1000);
}
function updateClock() {
	if (clocknow>0 && !theatermodenow) {
		document.getElementById('theatermodehint').innerHTML = '<span style="font-size:12px;color:#727272;"><strong>'+clocknow+'</strong>秒后..进入剧场模式，<a href="javascript:void(null)" onMouseUp="normalmode()" style="text-decoration:underline">取消</a></span>';
		clocknow--;
	} else {		
		clearInterval(intervalclock);
		clocknow = 2;
		theatermode(1);
	}
	//document.getElementById('ueid_1').parentNode.nextSibling.style.left = '0px';
	//alert(document.getElementById('ueid_1').parentNode.nextSibling.style.left);
}

function saveTheatermode() {
	if (theatermodesave) {
		writeCookieWithDomain('theatermode', 1, 24*30*6, 'anime.xunlei.com');
	} else {
		writeCookieWithDomain('theatermode', 0, 0, 'anime.xunlei.com');
	}
}

document.onmousemove = moveMouse;

