﻿var MainDiv=document.getElementById("Adv");
var RollDiv=document.getElementById("RollImages");
var BarDiv=document.getElementById("BarDiv");
var TitleDiv=document.getElementById("TitleDiv");
var Count=RollDiv.innerHTML.toLowerCase().split("<img ").length-1;
var Width=686;
var Height=248;
var numNow=1;
var IsOut=true;
var moveTime;
var scrollTime;
var Opa=0;
var Right=30;
  if(Count>0){
    var TempStr="";
	for(var i=0;i<Count;i++){
	  TempStr+="<div id=\"BarBtn"+(i+1)+"\" class=\"BarBtn\" onmouseover=\"ShowImage(this)\">"+(i+1)+"</div>";
	}
	BarDiv.innerHTML=TempStr;
  }
BarDiv.style.marginLeft=Width-(Right+10)*Count+"px";
BarDiv.style.marginTop=Height-30+"px";
document.getElementById("BarBtn1").className="BarBtn BarBtnOn";
TitleDiv.innerHTML=RollDiv.getElementsByTagName("a")[0].getAttribute("title");
RollDiv.style.left=0;
function Scroll(num)
{ 
 clearTimeout(moveTime);
  if(num) Opa=0;  
  if(100>Opa){
    Opa+=Math.sqrt(100-Opa);
    RollDiv.style.filter="Alpha(Opacity="+Opa+")";
    RollDiv.style.opacity = Opa/100;
    scrollTime=setTimeout("Scroll()",1);  
  }else{    
    clearTimeout(scrollTime);
    moveTime= setTimeout("ShowImage()",5000);	
  }  
}
function ShowImage(obj){
    clearTimeout(moveTime);
    clearTimeout(scrollTime);
		if(obj!=null)
		{	  		  
		  var Val=parseInt(obj.innerHTML);	 
		  if(Val==numNow) return;		  
		  RollDiv.style.filter="Alpha(Opacity=0)";
          RollDiv.style.opacity = 0;
		  RollDiv.style.left=-(Val-1)*Width+"px";		  
		  Scroll(1);
		  document.getElementById("BarBtn"+Val).className="BarBtn BarBtnOn";
		  TitleDiv.innerHTML=RollDiv.getElementsByTagName("a")[Val-1].getAttribute("title");
		  document.getElementById("BarBtn"+numNow).className="BarBtn";
		  numNow=Val;		
		}else{
		  if(IsOut)
		  {
			  if(numNow+1<=Count){
			    RollDiv.style.filter="Alpha(Opacity=0)";
                RollDiv.style.opacity = 0;
		        RollDiv.style.left=-(numNow)*Width+"px";
		        Scroll(1);
				document.getElementById("BarBtn"+(numNow+1)).className="BarBtn BarBtnOn";
				TitleDiv.innerHTML=RollDiv.getElementsByTagName("a")[numNow].getAttribute("title");
				document.getElementById("BarBtn"+numNow).className="BarBtn";  	
				numNow++; 
			  }else{
			    RollDiv.style.filter="Alpha(Opacity=0)";
                RollDiv.style.opacity = 0;
		        RollDiv.style.left=0;
		        Scroll(1);
				document.getElementById("BarBtn1").className="BarBtn BarBtnOn";
				TitleDiv.innerHTML=RollDiv.getElementsByTagName("a")[0].getAttribute("title");
				document.getElementById("BarBtn"+Count).className="BarBtn";
				numNow=1;	
			  }
		  }
		}		
    moveTime= setTimeout("ShowImage()",5000);	    
}
moveTime=setTimeout("ShowImage()",5000);