'使用三步走：
'第一步：建立类对象，如 set xxx=new ImageChange；
'第二步：根据需求定义并填充数组，数组为一维，每个数组元素值得格式为：“图片地址（相对）|超级链接|ALT鼠标停留显示”，如：“a.jpg|http://www.baidu.com|百度链接”
'第三步：调用Initialize函数初始化对象。格式为：xxx.Initialize(当前对象的对象名字符串，容纳图片的对象，图片宽，图片高，第二步中定义的图片信息数组）



Dim intZIndex    '累加每个标签层的zIndex，即重叠次序
intZIndex=500    

Function ImgChangePub(objImageChange)   'window的setInterval必须调用全局函数，此即为该函数。参数为传入的Class ImageChange对象
   call objImageChange.ImgChangeFunc()
End Function

Class ImageChange
  Dim intX,intY,strArrImagesPub,imgArrPub,intCount,intPreCount,intervalID
  Dim strObj,strContainer,oContainer,oImg,oLink,oLabel

  Private Sub Class_Initialize
     intX=0
     intY=0
  End Sub
  
  Private Sub Class_Teminate
  
  End Sub
   
  Public Function Initialize(strObjName,strContainerName,intImgWidth,intImgHeight,strArrImages) 'strObjName是本类的对象的名称
     Dim i,j,tempArr,strHtml,intL,intU
     strObj=strObjName
     strContainer=strContainerName
     intL=Lbound(strArrImages)
     intU=Ubound(strArrImages)
     intX=intU-intL
     intY=2
     Redim strArrImagesPub(intX,intY)
     For i=0 to intX
        tempArr=Split(strArrImages(i+intL),"|")
        For j=Lbound(tempArr) to Ubound(tempArr)
           strArrImagesPub(i,j)=tempArr(j)        '分解传入的信息，并存入新数组
        Next
     Next
     Redim imgArrPub(intX)
     For i=0 to intX
        If strArrImagesPub(i,0)<>"" Then
           Set imgArrPub(i)=document.createElement("img")
           imgArrPub(i).src=strArrImagesPub(i,0)   '创建img对象数组，并预先加载img数据
        End If
     Next
     
     Set oContainer=document.getElementById(strContainer)
     Set oLink=document.createElement("a")         '创建超级链接对象，并将其插入oContainer中
     oLink.id=strObj&"Link"
     oLink.href=strArrImagesPub(0,1)
     oLink.target="_blank"
     Call oContainer.insertAdjacentElement("beforeEnd",oLink)
     
     set oImg=document.createElement("img")   '创建img对象，并将其插入超级链接对象oLink中
     With oImg
     .id=strObj&"Image"
     .border=0
     .src=strArrImagesPub(0,0)
     .width=intImgWidth
     .height=intImgHeight
     .style.filter="revealTrans(duration=1,transition=23);"
     End With
     Call oLink.insertAdjacentElement("beforeEnd",oImg)
     
     Set oLabel=document.createElement("div")    '创建标签对象，使其浮动于document.body之上，便于使其定位
     With oLabel
     .id=strObjName&"Label"
     .align="left"
     .style.position="absolute"
     intZIndex=intZIndex+1        '该数据为全局数据
     .style.zIndex=intZIndex
     strHtml=strHtml&"<table border=0><tr>"
     For i=0 to intX
        strHtml=strHtml& "<td><div style='border:1px solid #FFFFFF; width: 15px; height: 15px; z-index: 1; padding-left:4px; padding-right:4px; padding-top:0px; padding-bottom:0px; background-color: #FFFFFF' id='"&strObjName&"Label"&CStr(i)&"' onmousemove="""&strObj&".Label_MouseOver()"" onmouseout="""&strObj&".Label_MouseOut()"" onclick="""&strObj&".LabelChanging("&cstr(i)&")"">"
        strHtml=strHtml&"<p align='center' style='line-height:70%'><font color='#000000' size='1'>"&cstr(i+1)&"</font></div></td>" 
     Next
     strHtml=strHtml&"</tr></table></div>"
     .innerHtml=strHtml
     End With
     Call document.body.insertAdjacentElement("beforeEnd",oLabel)

     Call SetPosition() '设置label相对于img的位置
     
     intPreCount=0
     intCount=0
     window.clearInterval intervalID
     Call ImgChangeFunc()
     intervalID=window.setInterval("ImgChangePub("&strObjName&")",4000)
  End Function

  Private Function SetPosition()
     rctImg=oImg.getClientRects()
     oLabel.style.left=rctImg.left
     oLabel.style.top=rctImg.bottom-25+document.body.scrollTop
  End Function
  
  
  Public Function LabelChanging(ID)
     Dim obj
     Set obj=document.getElementById(strContainer&"label"&cstr(ID))
     intCount=ID
     Call ImgChangeFunc()
  End function
  
  Public Function ImgChangeFunc()
     intCount=intCount mod (intX+1)
     oImg.filters.revealTrans.transition=23
     oImg.filters.revealTrans.apply
     oImg.filters.revealTrans.play
     oImg.src=imgArrPub(intCount).src
     oImg.alt=strArrImagesPub(intCount,2)
     oLink.href=strArrImagesPub(intCount,1)
     document.getElementById(strObj&"label"&cstr(intPreCount)).style.backgroundColor="#ffffff"
     document.getElementById(strObj&"label"&cstr(intCount)).style.backgroundColor="#ff0000"
     intPreCount=intCount
     intCount=intCount+1
  End Function
  
  Public Function Label_MouseOver()
     If intervalID<>0 Then 
        document.body.style.cursor="hand"
        window.clearInterval(intervalID)
        intervalID=0
     End If
  End Function
  
  Public Function Label_MouseOut()
     document.body.style.cursor="auto"
     window.clearInterval intervalID
     intervalID=window.setInterval("ImgChangePub("&strObj&")",4000)
  End Function
End Class