var ImageArray = new Array

window.onload=InitializePage;

function InitializePage()
{
// Install Image Viewer HTML file name holderInput element
FirstDIV=document.createElement('DIV')
document.body.appendChild(FirstDIV)
FirstDIV.innerHTML="<INPUT type=hidden id=fileNameHolder>"+
"<DIV id='interface'>" + 
"	<DIV id='ViewingArea'>" + 
"	<div>" + 
"		<div id='ImageContainer'>" + 
"		</div>" + 
"	</div>" + 
"	</DIV>" + 
"	<DIV id='controls'>" + 
"		<DIV id='Verbiage'>" + 
"		</DIV>" + 
"		<DIV id='ScrollLeft'>" + 
"		</DIV>" + 
"		<DIV id='ScrollRight'>" + 
"		</DIV>" + 
"	</DIV>" + 
"</DIV>"


if (ImageArray!=null)	{for (l=0; l<ImageArray.length; l++)		{		TDElement=document.createElement("DIV");			} 	}

attachEventhandlers();

}


function onclickHandler(e)
{
// Browser compatibility code
	var targ;
	if (!e){var e = window.event;}
	
	if (e.target)
		{	targ = e.target;
			var xpos=(e.pageX); var ypos=(e.pageY);}
	
	else if (e.srcElement)
		{	var xpos=(event.x);	var ypos=(event.y);
			targ = e.srcElement;}

	
}

// Attach event handlers to all images within container
function attachEventhandlers()
{
ContainerElement=document.getElementById('ImageContainer')
TDCol=ContainerElement.getElementsByTagName('DIV');

if (TDCol!=null)
	{for (l=0; l<TDCol.length; l++)
		{
		IMGCol=TDCol.item(l).getElementsByTagName("IMG");
		IMGCol.item(0).style.cursor="hand"
		IMGCol.item(0).setAttribute('id',"Image"+l)
		IMGCol.item(0).onclick=onclickHandler;
		}
	}
}

// Set ID's for all table cells
function setIDs()
{
ContainerElement=document.getElementById('ImageContainer')
TDCol=ContainerElement.getElementsByTagName('DIV');
if (TDCol!=null)
	{	for (i=0; i<TDCol.length; i++)
			{TDCol.item(i).setAttribute('id',i)}
	}
}

// :::::::::::::::::::::::::
// ::: Scroll Functions ::
// :::::::::::::::::::::::::

count = 0;

function disableButton (count, lastID, arrowType) {

if (arrowType == "leftArrow") { 

if  (count == 0) {

document.getElementById(arrowType).style.visibility="hidden"; 
document.getElementById('rightArrow').style.visibility ="visible"; 

document.getElementById('ViewingArea').style.left=0+"px"; 


}
else {
document.getElementById(arrowType).style.visability="visible"; 
document.getElementById('rightArrow').style.visibility ="visible"; 
document.getElementById('ViewingArea').style.left=-20+"px"; 
document.getElementById('interface').style.width=167+"px"; 

}
}



if (arrowType == "rightArrow") {

if  (count == lastID) {
document.getElementById(arrowType).style.visibility="hidden"; 
document.getElementById('leftArrow').style.visibility = "visible"; 
document.getElementById('interface').style.width=175+"px"; 
document.getElementById('ViewingArea').style.left=-30+"px"; 

}
else {
document.getElementById(arrowType).style.visability="visible"; 
document.getElementById('leftArrow').style.visibility ="visible"; 
document.getElementById('ViewingArea').style.left=-20+"px"; 
document.getElementById('interface').style.width=167+"px"; 
}

}}




function moveLeft()
{
if(window.TDCol === undefined || TDCol.length == 0)
{
	setIDs();
}
count++;
ContainerElement=document.getElementById("ImageContainer");
lastTD=document.getElementById(TDCol.length-1);
duplastTD=lastTD.cloneNode(false)
duplastTD.innerHTML=lastTD.innerHTML
firstTD=document.getElementById("0");
dupfirstTD=firstTD.cloneNode(false)
dupfirstTD.innerHTML=firstTD.innerHTML

rightlastID= TDCol.length-3;

if (count <= rightlastID) {ContainerElement.removeChild(firstTD);ContainerElement.appendChild(dupfirstTD); disableButton (count, rightlastID,'rightArrow');} 
setIDs();attachEventhandlers();
}

function moveRight()
{
if(window.TDCol === undefined || TDCol.length == 0)
{
	setIDs();
}
count--;
ContainerElement=document.getElementById("ImageContainer");
lastTD=document.getElementById(TDCol.length-1);
duplastTD=lastTD.cloneNode(false)
duplastTD.innerHTML=lastTD.innerHTML
firstTD=document.getElementById("0");


rightlastID= 0;
if (count>=rightlastID) {ContainerElement.insertBefore(duplastTD,firstTD);ContainerElement.removeChild(lastTD); disableButton (count, rightlastID,'leftArrow');}

setIDs();attachEventhandlers();
}