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

biggest=0
ieBorder=0
totalWidth=0
hs5Timer=null

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

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

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

}

function initHS5(){
	scrollBox=document.getElementById("scroll_box")
	scroll1=document.getElementById("scroller1")
	for(var k=0;k<hs5Arr.length;k++){

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

		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<hs5Arr.length;l++){ // vertically center images
		document.getElementById("pic"+l).style.marginBottom = (biggest-document.getElementById("pic"+l).offsetHeight)/2+"px"
	}

	if(scrollBox.currentStyle&&!window.opera&&document.compatMode!="CSS1Compat"){
		ieBorder=parseInt(scrollBox.currentStyle.borderWidth)*2
	}

	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= 0+"px" //-scroll1.offsetHeight+"px"
	scroll2.style.width=totalWidth+"px"

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

	scrollHS5()
}

function scrollHS5(){
	clearTimeout(hs5Timer)
	scroll1Pos=parseInt(scroll1.style.left)
	scroll2Pos=parseInt(scroll2.style.left)
	scroll1Pos-=speed
	scroll2Pos-=speed
	scroll1.style.left=scroll1Pos+"px"
	scroll2.style.left=scroll2Pos+"px"
	hs5Timer=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(scrollBox.style.width)){
			scroll1.style.left=scroll2Pos+ (-scroll1.offsetWidth)+"px"
		}

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

}

st=null
function pause(){
	clearTimeout(hs5Timer)
	clearTimeout(st)
}

function reStartHS5(){
	clearTimeout(st)
	st=setTimeout("scrollHS5()",100)
}

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(displayEl.filters){displayEl.filters.alpha.opacity=fadeValue}
	else{displayEl.style.opacity=(fadeValue/100)-0.1}

	if(fadeValue<minFadeValue){
		fadeValue=minFadeValue
		fadeStep= -fadeStep
		displayEl.src=hs5Arr[picNum][1]
	}

	if(fadeValue>=100){
		fadeValue=100
		fadeStep= -fadeStep
		fading=0
		clearTimeout(fadeTimer)
	}
}

window.onload = function()
{
	initHS5();
}
