var needHintImg = [];
var animeIdArr = [];
var needHide = true;
// ajax异步从 需要遮罩的图片 中筛选出有导视的列表
function ajaxCheckCanPreview(url,pars,method,obj,asynchronous) {
	var xmlHttp;
	if (window.ActiveXObject) {  
		try {  
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  
		} catch(e) {  
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
		} 
	} else if (window.XMLHttpRequest) {  
		xmlHttp = new XMLHttpRequest();  
	}
	if(method.toLowerCase() == "get") {  
		url = url;  
		xmlHttp.open("GET",url,asynchronous);  
		xmlHttp.send(null);  
	} else {  
		xmlHttp.open("POST",url,asynchronous);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  
		xmlHttp.send(pars);  
	}	    
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)  {
			  checkResultCSV = xmlHttp.responseText;
			  generateDiv(checkResultCSV);			   
		}  
	}
}

function autoHintImg() {	
	// 检索需要遮罩的符合条件的图片对象
	//alert('start ge cover');
	for (i in document.images) {
		if (document.images[i]['animeId'] && document.images[i].width>=1 && document.images[i].height>=1) {
			needHintImg.push(document.images[i]);
			animeIdArr.push(document.images[i]['animeId']);			
		}
	}
	animeIdCSV = animeIdArr.join(',');
	//alert('needCoverAnime:'+animeIdCSV);
	generateDiv();
}

nn = 0;

function generateDiv() {	

	for (index=0; index<needHintImg.length; index++) {
		needHintImg[index].setAttribute('id', 'img_hint_anime_'+needHintImg[index]['animeId']+'_'+index);
		needHintImg[index].setAttribute('imgSeries', ''+index);
		
		hintCoverWidth = 236;
		hintCoverHeight = 130;
		var hintCover = document.createElement('<div>');
		hintCover.setAttribute('id', 'hint_anime_'+needHintImg[index]['animeId']+'_'+index);		
		hintCover.setAttribute('coverSeries', ''+index);	
		hintCover.innerHTML = '<img src=http://misc.web.xunlei.com/anime_v2/img/indicator.gif align=absmiddle> Loading...';
		hintCover.style.position = 'absolute';
		hintCover.style.zIndex = index+1000;
		hintCover.style.width = hintCoverWidth+"px";
		hintCover.style.height = hintCoverHeight+"px";
		hintCover.style.filter = "alpha(opacity=90)";
		hintCover.style.opacity = 0.9;
		hintCover.style.backgroundColor = "#FFFFFF";
		hintCover.style.fontSize = "12px";
		hintCover.style.padding = "3px";
		hintCover.style.border = "1px solid #A9C9EA";
		hintCover.style.display = 'none';		
		
		hintCover.onmouseover = function () {
			needHide = false;
			this.style.display = 'block';
			var p = getPosition( $('img_'+this.id) );

			var temp = this.id.split('_');
			tempanimeId = temp[2];
			
			this.style.top = p.Top + $('img_'+this.id).height + 6 + "px";
	    		this.style.left = p.Left + 1 + "px";
			 
		}
		hintCover.onmouseout = function () {
			this.style.display = 'none';		
		}
		
		needHintImg[index].onmouseover = function () {
			this.style.borderColor = '#666';
			$('hint_anime_'+this.animeId+'_'+this.imgSeries).style.display = 'block';
			var p = getPosition(event.srcElement);
	    		$('hint_anime_'+this.animeId+'_'+this.imgSeries).style.top = p.Top + this.height + 6 + "px";
	    		$('hint_anime_'+this.animeId+'_'+this.imgSeries).style.left = p.Left + 1 + "px";			
			if ( $('hint_anime_'+this.animeId+'_'+this.imgSeries).innerHTML.indexOf('Loading') ) {
				//Ajax('/interface/ajaxGetAnimeHintInfo/'+this.animeId+'?debug=false','','POST',$('hint_anime_'+this.animeId+'_'+this.imgSeries),1);
				Ajax('/ajaxGetAnimeInfo/'+this.animeId+'.html',rand(99999),'GET',$('hint_anime_'+this.animeId+'_'+this.imgSeries),1);
			}
			if(nn != 0 && nn!=this.animeId+'_'+this.imgSeries){
				$('hint_anime_'+nn).style.display = 'none';
				nn = 0;
			}
			nn = this.animeId+'_'+this.imgSeries;
		}
		needHintImg[index].onmouseout = function () {
			this.style.borderColor = '#D6D6D6';
			needHide = true;
			setTimeout('delayHide("hint_anime_'+this.animeId+'_'+this.imgSeries+'")', 180);
		}		
		hintCover = document.getElementsByTagName('body')[0].insertAdjacentElement('beforeend', hintCover);
	}
}

function delayHide(obj) {
	if (needHide){
		$(obj).style.display = 'none';
	}		
}

function getPosition (o) {
	var p = {Top: 0, Left: 0};
   	while (!!o) {
        	p.Top += o.offsetTop;
        	p.Left += o.offsetLeft;
        	o = o.offsetParent;
    	}
    	return p;
}

function changeplaycurrent(obj,lorr) {
	obj.style.backgroundColor = '#000000';
	obj.style.border = '0px';
}

function changeplayblur(obj,lorr) {
	if (lorr) {
		obj.style.backgroundColor = '#20A2EE';
	} else {
		obj.style.backgroundColor = '#66CC33';
	}
	
	obj.style.border = '0px';
}


var coverJSLib = document.createElement("script");
coverJSLib.src = "/js/cover.js";
document.getElementsByTagName("head")[0].appendChild(coverJSLib);
var commonJSLib = document.createElement("script");
commonJSLib.src = "http://misc.web.xunlei.com/anime_v2/js/common.js";
document.getElementsByTagName("head")[0].appendChild(commonJSLib); 

function openPreviewLayer(animeId, animeTitle) {
	if (typeof(kkp)!='undefined') {
		kkp.pause();		
		kkp.show(false);
	}
	if (typeof(normalmode)!='undefined') {
		normalmode();
	}
	maskCover(710,500,animeTitle+' - 精彩导视');
	document.getElementById('msgbody').innerHTML='<center><br><br><img src=/images/anime_loading.gif><br><br><br>正在载入导视及子集列表，稍等片刻....<br><br><br></center>';
	setTimeout('ajaxGetContent('+animeId+')',1000);
	return false;
}

function ajaxGetContent(animeId) {
	Ajax('/Anime2segment/ajaxGetSegmentByAnimeFrame/'+animeId,'','POST',document.getElementById('msgbody'),1);
}
 