var xmlHttp;

var currentNum=1;						//当前第几张图片
var isRun=false;							//是否自动执行滚动

var isOneOrTwo;							//图片id是one结尾当前为显示状态，值为true;
var sourceUrl="";						//上一张图片
var isFirst=true;
var isNotCol=false;

var current=0;							//当前第几张图片
var picNodes;							//xml结点数组

var picIsChange=false;							//图片正在改变

//暂停滚动
function stopImgChange(){
	
	isRun=false;
	
}
//开始滚动
function playImgChange(){

	if(!isRun&&!picIsChange){
		isRun=true;
		newsIndexImgChange();
	}
	else{
		setTimeout("playImgChange()", 5000);
	}
	
}


function priorImgChange(){
	isNotCol=true;
	runImgChangeNotCol('prior');
	
}

function nextImgChange(){
	isNotCol=true;
	runImgChangeNotCol('next');

}


//上一张或下一张，不循环
function runImgChangeNotCol(otype){


		 if(isRun)  {
		 	
		 	if(otype=='prior')
		 		current=current-1;
		 	
		 	else
		 		current=current+1;
		 		
		 		
		 	if(current<0)	current=picNodes.length-1;
		 	
		 	if(current>=picNodes.length) current=0;
		 	
		 	
		 	var node=picNodes[current];

        	      		
        		var rImgUrl=node.getAttribute("path");	//图片链接地址
        		
        					
        		var rUrl=node.getAttribute("url")			//页面地址

        		var info=node.getAttribute("info");			//当前显示的页
        		
        		        		        		        
        		var linkOne=document.getElementById("linkone");
        
        		var linkTwo=document.getElementById("linktwo");
        	

        		
        
	        		if(isOneOrTwo){
	        			isOneOrTwo=false;
	        			
	       				document.images['oDIVone'].src=rImgUrl;		
	       				
	        			linkOne.href=rUrl;
	        			
	        			linkOne.title=info;
	        			
	        			document.images['oDIVtwo'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVone'].src;
	        			        			
	        			oTransContainer.filters[0].Apply();
	
	        			document.images['oDIVone'].style.display = "";
	       				document.images['oDIVtwo'].style.display = "none"; 
	
	        			oTransContainer.filters[0].Play(duration=2);
	        		}
	        		
	        		else{
	        			isOneOrTwo=true;
	        			document.images['oDIVtwo'].src=rImgUrl;		
	       				
	        			linkTwo.href=rUrl;
	        			
	        			linkTwo.title=info;
	        			
	        			document.images['oDIVone'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVtwo'].src;
	        			        			
        				oTransContainer.filters[0].Apply();

        				document.images['oDIVtwo'].style.display = "";
       					document.images['oDIVone'].style.display = "none"; 

        				oTransContainer.filters[0].Play(duration=2);
        		
        			}
		 	
		 			
		 }
		
    


}

//图片渐变改变
function runImgChange(){

	if(isRun){
				
				picIsChange=true;
				if(current>=picNodes.length) current=0;
	
				var node=picNodes[current];

        	      		
        		var rImgUrl=node.getAttribute("path");	//图片链接地址
        		
        					
        		var rUrl=node.getAttribute("url")			//页面地址

        		var info=node.getAttribute("info");			//当前显示的页
        		
        		        		        		        
        		var linkOne=document.getElementById("linkone");
        
        		var linkTwo=document.getElementById("linktwo");
        	

        		
        
	        		if(isOneOrTwo){
	        			isOneOrTwo=false;
	        			
	       				document.images['oDIVone'].src=rImgUrl;		
	       				
	        			linkOne.href=rUrl;
	        			
	        			linkOne.title=info;
	        			
	        			document.images['oDIVtwo'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVone'].src;
	        			        			
	        			oTransContainer.filters[0].Apply();
	
	        			document.images['oDIVone'].style.display = "";
	       				document.images['oDIVtwo'].style.display = "none"; 
	
	        			oTransContainer.filters[0].Play(duration=2);
	        		}
	        		
	        		else{
	        			isOneOrTwo=true;
	        			document.images['oDIVtwo'].src=rImgUrl;		
	       				
	        			linkTwo.href=rUrl;
	        			
	        			linkTwo.title=info;
	        			
	        			document.images['oDIVone'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVtwo'].src;
	        			        			
        				oTransContainer.filters[0].Apply();

        				document.images['oDIVtwo'].style.display = "";
       					document.images['oDIVone'].style.display = "none"; 

        				oTransContainer.filters[0].Play(duration=2);
        		
        			}
        			
        			current=current+1;
		 
	
		 
		 if(isRun)  
		 		setTimeout("runImgChange()", 5000);
		 else	
		 		picIsChange=false;
	}
	else{
		picIsChange=false;
	}
	  
}

//开始调用ajax
function newsIndexImgChange(){


createXMLHttpRequest();
	var url = "/news/ibPicImage.do" ;
	
	 xmlHttp.onreadystatechange = newsIndexhandleImgChange;
     xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function newsIndexhandleImgChange(){

	if(xmlHttp.readyState == 4) {
        	if(xmlHttp.status == 200) {
       			
        		var xmlDoc=xmlHttp.responseXML;

        		picNodes=xmlDoc.getElementsByTagName("list");
        		
				


					
					setTimeout("runImgChange()", 100);


        		
       	 	}
    
    　　
    	}

}


 
function indexImgChange(otype){
	createXMLHttpRequest();
//alert(otype);
	
	var url = "/idio/indexPhotoChange.do?" ;
		
	url=url+"otype="+otype+"&currentNum="+currentNum+"&userId="+userId;
		

   
    xmlHttp.onreadystatechange = indexhandleImgChange;
     xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

}


function indexhandleImgChange(){

	if(xmlHttp.readyState == 4) {
        	if(xmlHttp.status == 200) {
       		
        		var xmlDoc=xmlHttp.responseXML;

        		var node=xmlDoc.getElementsByTagName("photo")[0];

        		var rImgUrl=node.getAttribute("imgUrl");	//图片链接地址
        		
        		var otype=node.getAttribute("otype")			//操作类型
			
        		var rUrl=node.getAttribute("url")			//页面地址

        		var rNum=node.getAttribute("Num");			//当前显示的页
        		
        		var error=node.getAttribute("error");		//错误
        		
        		currentNum=rNum;
        
        		var linkOne=document.getElementById("linkone");
        
        		var linkTwo=document.getElementById("linktwo");
        	
        		if(error==null){	//如果没有错误
        
	        		if(isOneOrTwo){
	        			isOneOrTwo=false;
	        			
	       				document.images['oDIVone'].src=rImgUrl;		
	       				
	        			linkOne.href=rUrl;
	        			
	        			document.images['oDIVtwo'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVone'].src;
	        			        			
	        			oTransContainer.filters[0].Apply();
	
	        			document.images['oDIVone'].style.display = "";
	       				document.images['oDIVtwo'].style.display = "none"; 
	
	        			oTransContainer.filters[0].Play(duration=2);
	        		}
	        		
	        		else{
	        			isOneOrTwo=true;
	        			document.images['oDIVtwo'].src=rImgUrl;		
	       				
	        			linkTwo.href=rUrl;
	        			
	        			document.images['oDIVone'].src=sourceUrl;		
	       				
						sourceUrl=document.images['oDIVtwo'].src;
	        			        			
        				oTransContainer.filters[0].Apply();

        				document.images['oDIVtwo'].style.display = "";
       					document.images['oDIVone'].style.display = "none"; 

        				oTransContainer.filters[0].Play(duration=2);
        		
        			}
        		
        		
        			if(!isNotCol){	//如果不循环状态没有打开
        				if(isRun)  	setTimeout('runImgChange("'+otype+'")', 5000);
        			
        			}
        			else{			//如果不循环状态已经打开，本次不循环，但下次还是循环
        				isNotCol=false;
        			}
				}
       	 	}
    
    　　
    	}

}
