// programtion by adnev@podvodnik.cz

// SETTINGS

overMessage="Click to zoom"
closeMessage="Move out the mouse to close the window"
defaultMessage="Hello"

defaultDelay=5   // if not specified in addTvSet() or addStill()
stopOnMouseOver=1 // 1 = stops if the mouse is over the image

// END OF SETTINGS

ns=(navigator.appName=='Netscape')
ie=(navigator.appName=='Microsoft Internet Explorer')
op=(typeof(window.opera)!='undefined')

function sts(mes) {
  if (typeof mes=='undefined')
    mes=defaultMessage
  var com='window.status="'+mes+'"'
  setTimeout(com,'10')
}

//
// object contruction
//

tvList=[] // global variable used to access different tv sets

function tvSet(name,index,delay) {
  // Constructor
  this.name=name
  this.index=index
  this.delay=delay
  this.timer=0
  this.runFlag=1
  this.stills=[]
  this.currentStill=1
}

function still(url,zoomUrl,zoomWidth,zoomHeight,delay) {
  // Constructor
  this.image=new Image(1,1)
  this.image.src=url
  this.delay=delay
  this.zoomUrl=zoomUrl
  this.zoomWidth=zoomWidth
  this.zoomHeight=zoomHeight
}

function addTvSet(name,delay) {
  // creates a new tv set, adds it to the tvList and sets is as opened (see next comment)
  if (typeof(delay)=='undefined')
    var delay=defaultDelay
  newTv=new tvSet(name,tvList.length,delay)
  tvList[tvList.length]=newTv
  base=newTv
}

function addStill(url,zoomUrl,zoomWidth,zoomHeight,delay) {
  // Add to the last created tv set
  if (typeof(delay)=='undefined')
    var delay=base.delay
  base.stills[base.stills.length]=new still(url,zoomUrl,zoomWidth,zoomHeight,delay)
}


//
// action
//


function tic() {
  for(var i=0;i<tvList.length;i++) {
    var tvSet=tvList[i]
    tvSet.timer+=tvSet.runFlag
    if (tvSet.timer==tvSet.stills[tvSet.currentStill].delay) {
      tvSet.timer=0
      tvSet.currentStill++;
      if (tvSet.currentStill==tvSet.stills.length)
        tvSet.currentStill=0
      document[tvSet.name].src=tvSet.stills[tvSet.currentStill].image.src
    }
  }
}

function zoomStill(tvSetName) {
  var tvSet=tvSetName2tvSet(tvSetName)
  var still=tvSet.stills[tvSet.currentStill]
  zoom(still.zoomUrl,still.zoomWidth,still.zoomHeight)
  sts(closeMessage)
}

function overTv(tvSetName) {
  var tvSet=tvSetName2tvSet(tvSetName)
  tvSet.runFlag=1-stopOnMouseOver
  sts(overMessage)
}

function outTv(tvSetName) {
  var tvSet=tvSetName2tvSet(tvSetName)
  tvSet.runFlag=1
  sts()
}

function tvSetName2tvSet(tvSetName) {
  var i=0
  while (i<tvList.length) {
    if (tvList[i].name==tvSetName) {
      var tvSet=tvList[i]
      i=tvList.length
    }
    i++
  }
  return tvSet
}

function zoom(url,width,height) {
  height+=18
  width+=18
  options="height=" + height + ",width=" + width
  closeMe()
  xx=open("","xx",options)
  ifie=(navigator.appName=="Netscape")? '':' STYLE="margin:9"'
  xx.document.write('<HTML><TITLE>Zoom</TITLE></HEAD><BODY ONBLUR="self.focus()" ONLOAD="self.focus()" BGCOLOR=000000 LINK=000000'+ifie+'><A HREF="javascript:generator.closeMe()" ONMOUSEOUT="generator.closeMe()"><IMG SRC="' + url + '" BORDER=0></A></BODY></HTML>')
  xx.generator=self
  xx.document.close()
  sts(closeMessage)
}

function closeMe() {
  if (typeof xx!='undefined') if (typeof xx.document!='undefined')
    xx.close()
  sts()
}


document.onload=setInterval('tic()','300')