// JavaScript Document
//powerby lirense.com xiaoan
var $xxWin=function(id){return document.getElementById(id);};
var isIe=(document.all)?true:false;
var actWin;
var actTop;
function xx_addEvent(obj,name,handler,useCapture){
	if(window.event){obj.attachEvent('on' + name,handler);}
	else{obj.addEventListener(name,handler,useCapture);}
}
function loadEvent(){
	xx_addEvent($xxWin('xxTop'),'mouseover',changCss,false);
	xx_addEvent($xxWin('xxTop'),'mouseout',_changCss,false);
	xx_addEvent($xxWin('xxTop'),'click',getTop,false);
	xx_addEvent($xxWin('xxWin'),'click',showMsgBox,false);
}
function changCss(){
	$xxWin('xxTop').className = 'Lpic1';
}
function _changCss(){
	$xxWin('xxTop').className = 'Lpic';
}
function getTop(){
	actTop = setInterval(SubTop,5);		
	//document.documentElement.scrollTop=0;
}
function SubTop(){
	var xxHeight = document.documentElement.scrollTop;
	if(xxHeight<=0){clearTimeout(actTop);}
	else{document.documentElement.scrollTop = xxHeight - 20;}
}
function showMsgBox(){
	xxsetcookieToday();
	closeWindow();
	var xxMsg=document.createElement("div");
	xxMsg.id="xxMsg";
	xxMsg.className="msgWin";
	xxMsg.style.cssText=(isIe)?"filter:alpha(opacity=90);":"opacity:0.9;";
	//if(isIe) {xxMsg.filters.alpha.opacity=90;}
	//else {xxMsg.style.opacity=0.90;} 
	document.body.appendChild(xxMsg);
	var mesW=document.createElement("div");
	mesW.id="msgWin";
	mesW.innerHTML='<div class="msgHead"><span class="XmsgUID">今日推荐</span><span class="Xclose" onmouseover=this.className="XcloseHover" onmouseout=this.className="Xclose" onclick="DecClose()"></span><span class="XsetSys" onmouseover=this.className="XsetSysHover" onmouseover=this.className="XsetSYs" onclick="xxSystemSet()"></span></div><div class="txtCont" id="txtCont"></div>';
	xxMsg.appendChild(mesW);
	xxgetdata();
	actWin=setInterval(AddWinHeight,10);
}
function xxSystemSet(){
	if($xxWin('xxMsg')!=null){
		var xxSysbox=document.createElement("civ");
		xxSysbox.className="xxSysbox";
		xxSysbox.id="xxSysbox";
		xxSysbox.innerHTML="<div class='Syscontent'><form><span><input type='radio' value='1' name='xxSysboxValue' id='xxSysboxValue1' > 每天自动显示一次</span><span><input type='radio' value='0' name='xxSysboxValue' id='xxSysboxValue2' checked> 不自动显示</span><span class='xxbutton '><input type='button' value='确定' class='xxbtn' onclick='xxsetcookie()'><input type='button' value='取消' class='xxbtn' onclick='xxcloseSysWin()'></span></form></div>";
		$xxWin('xxMsg').appendChild(xxSysbox);
	}
}
function xxsetcookie(){
	//获取当前时间
	var date=new Date();
	var expireDays=365;
	//将date设置为expireDays天以后的时间
	date.setDate(date.getDate()+expireDays);	
	var Syskey;
	if($xxWin('xxSysboxValue2').checked==true) Syskey=0;
	else Syskey=1;
	//如果加上pathIE下存在BUG，无法写入cookie
	document.cookie="xxsyskey="+ Syskey +";expires="+ date.toGMTString() + ";path=/";
	xxcloseSysWin();
}
function xxsetcookieToday(){
	//获取当前时间
	var date=new Date();
	var expireDays=1;
	//将date设置为expireDays天以后的时间
	date.setDate(date.getDate()+expireDays);	
	document.cookie="xxsyskeyToday=1;expires="+date.toGMTString() + ";path=/";
	xxcloseSysWin();
}
function xxgetcookie(c_name){
	var namecookies=document.cookie;
	var c_start = namecookies.indexOf(c_name + "=");
	if(c_start != -1){
		c_start = c_start + c_name.length + 1;
		var c_end   = document.cookie.indexOf(";",c_start);
		if (c_end == -1)
		{
			c_end = document.cookie.length;
		}
		return document.cookie.substring(c_start,c_end);	
	}
}
function xxcloseSysWin(){
	if($xxWin('xxSysbox')!=null) $xxWin('xxSysbox').parentNode.removeChild($xxWin('xxSysbox'));
}
function closeWindow(){
	if($xxWin('xxMsg')!=null){
		$xxWin('xxMsg').parentNode.removeChild($xxWin('xxMsg'));
	}
	if($xxWin('msgWin')!=null){
		$xxWin('msgWin').parentNode.removeChild($xxWin('msgWin'));
	}
}
function AddWinHeight(){
	var iHeight = parseInt($xxWin('xxMsg').offsetHeight);
	if(iHeight>=242){clearTimeout(actWin);}
	else{
		if($xxWin('xxMsg')!=null){
			$xxWin('xxMsg').style.height = iHeight + 5 + "px";
		}
	}
}
function DecWinHeight(){
	var iHeight = parseInt($xxWin('xxMsg').offsetHeight);
	if(iHeight<= 0){
		clearTimeout(actWin);
		closeWindow();
	}
	else{
		if($xxWin('xxMsg')!=null){
			$xxWin('xxMsg').style.height = iHeight - 2 + "px";
		}
	}
}
function DecClose(){
	//actWin=setInterval(DecWinHeight,10);
	closeWindow();
}
function loadReg(){
	loadEvent();
	if(xxgetcookie('xxsyskey')!=0) 
	{
		//判断今天是否已显示
		if(xxgetcookie('xxsyskeyToday')!=1){
			showMsgBox();
		}
	}
}
//解决load问题
if(document.all){
	window.attachEvent("onload",loadReg);
}
else{
	window.addEventListener("load",loadReg,false);
}
