// JavaScript Document

//Jeff
// www.huntingground.freeserve.co.uk

//myImages=[
//["thumb1.jpg","bigpic1.jpg","Alt Text 1"],
//]

dir=0 // 0 = left 1 = right
speed=4
imageSize=100  // % set to zero to use fixedWidth and fixedHeight values
//fixedHeight=75 // set a fixed height
//fixedWidth=75 // set a fixed width
spacerWidth=10 // space between images
dualFade=0 // 0 = fades in, 1 = fades out then in

biggest=0
ieBorder=0
totalWidth=0
hs3Timer=null

lastN=0
count=0
fading=0
fadeStep = 2
fadeSpeed=10
minFadeValue=0

preload=new Array()
for(var i=0;i<myImages.length;i++){
preload[i]=[]

for(var j=0;j<2;j++){
preload[i][j]=new Image()
preload[i][j].src=myImages[i][j]
}

}

function initHS5(){
scroll1=document.getElementById("scroller1")
//alert(preload[0][0].src)
for(var k=0;k<myImages.length;k++){

//scroll1.innerHTML+='<img id="pic'+k+'" src="'+preload[k][0].src+'" alt="'+myImages[k][2]+'" text="'+myImages[k][2]+'" onclick="initFade('+k+')">'
scroll1.innerHTML+='<img id="pic'+k+'" src="'+preload[k][0].src+'" alt="'+myImages[k][2]+'" title="'+myImages[k][2]+'">'

if(imageSize!=0){ // use percentage size
newWidth=preload[k][0].width/100*imageSize
newHeight=preload[k][0].height/100*imageSize
}
else{ // use fixed size
newWidth=fixedWidth
newHeight=fixedHeight
}

document.getElementById("pic"+k).style.width=newWidth+"px"
document.getElementById("pic"+k).style.height=newHeight+"px"

if(document.getElementById("pic"+k).offsetHeight>biggest){
biggest=document.getElementById("pic"+k).offsetHeight
}

document.getElementById("pic"+k).style.marginLeft=spacerWidth+"px"

totalWidth+=document.getElementById("pic"+k).offsetWidth+spacerWidth

}

totalWidth+=1

for(var l=0;l<myImages.length;l++){ // vertically center images
document.getElementById("pic"+l).style.marginBottom = (biggest-document.getElementById("pic"+l).offsetHeight)/2+"px"
}

if(document.getElementById&&document.all){
ieBorder=parseInt(document.getElementById("scrollbox").style.borderTopWidth)*2
}

document.getElementById("scrollbox").style.height=biggest+ieBorder+"px"

scroll1.style.width=totalWidth+"px"

scroll2=document.getElementById("scroller2")
scroll2.innerHTML=scroll1.innerHTML
scroll2.style.left= (-scroll1.offsetWidth)+"px"
scroll2.style.top= -scroll1.offsetHeight+"px"
scroll2.style.width=totalWidth+"px"

if(dir==1){
speed= -speed
}

scrollHS5()
}

function scrollHS5(){
if(paused==1){return}
clearTimeout(hs3Timer)

scroll1Pos=parseInt(scroll1.style.left)
scroll2Pos=parseInt(scroll2.style.left)

scroll1Pos-=speed
scroll2Pos-=speed

scroll1.style.left=scroll1Pos+"px"
scroll2.style.left=scroll2Pos+"px"

hs3Timer=setTimeout("scrollHS5()",50)

if(dir==0){
if(scroll1Pos< -scroll1.offsetWidth){
scroll1.style.left=scroll1.offsetWidth+"px"
}

if(scroll2Pos< -scroll1.offsetWidth){
scroll2.style.left=scroll1.offsetWidth+"px"
}
}


if(dir==1){
if(scroll1Pos>parseInt(document.getElementById("scrollbox").style.width)){
scroll1.style.left=scroll2Pos+ (-scroll1.offsetWidth)+"px"
}

if(scroll2Pos>parseInt(document.getElementById("scrollbox").style.width)){
scroll2.style.left=scroll1Pos+ (-scroll2.offsetWidth)+"px"
}
}

}

paused=0
function pause(){
clearTimeout(hs3Timer)
}


function initFade(n){
count=n
if(lastN==n||fading==1){return}
if(dualFade==0){fadeValue=0}
else{fadeValue=100}
picNum=n
lastN=n
fadePic()
}

function fadePic(){
displayEl=document.images["bigpic"]
fading=1
fadeValue -= fadeStep
fadeTimer=setTimeout("fadePic()",fadeSpeed)
if("filters" in document.body && "alpha" in document.body.filters){displayEl.filters.alpha.opacity=fadeValue}
else{displayEl.style.MozOpacity=(fadeValue/100)-0.1}
if(fadeValue<minFadeValue){ // for fade out first
fadeValue=minFadeValue
fadeStep= -fadeStep
displayEl.src=myImages[picNum][1]
}
if(fadeValue>=100){ // fade in
fadeValue=100
fadeStep= -fadeStep
fading=0
clearTimeout(fadeTimer)
}
}
