//--------------------------------------------------------------------------------------------------
// All material contained within this and associated downloaded pages is the property of 4thorder(TM) 
// Copyright © 2005.  All rights reserved.
//
// Author: Michael Falatine || Authors email: 4thorder@4thorder.us
//
// USAGE: You may use this script for commercial or personal use, however, the copyright is retained-
// by 4thorder (TM).
//
// For other free Scripts visit: http://www.4thorder.us/Scripts/
//---------------------------------------------------------------------------------------------------
// :::::::::::::::::::::::::
// ::: Initialize Page ::::
// :::::::::::::::::::::::::


function InitializePage(ScrollName)
{
// Install Image Viewer HTML file name holderInput element
FirstDIV=document.createElement('DIV')
document.body.appendChild(FirstDIV)
FirstDIV.innerHTML="<INPUT type=hidden id='fileNameHolder_"+ScrollName+"'>"+
"<style> #controls_"+ScrollName+"{background-image:url('http://www.oneaustinrealty.com/js/OARRevamped/images/bottom.png');}</style><DIV id='interface_"+ScrollName+"' style='background-color:"+ImageBorderColor+";'>" + 
"	<DIV id='ViewingArea_"+ScrollName+"'>" + 
"	<TABLE border='0' cellpadding='2'>" + 
"		<TR  id='ImageContainer_"+ScrollName+"'>" + 
"		</TR>" + 
"	</TABLE>" + 
"	</DIV>" + 
"	<DIV id='controls_"+ScrollName+"'>" + 
"		<DIV id='ScrollLeft_"+ScrollName+"'>" + 
"			<div onclick=\"moveLeft('"+ScrollName+"')\" style='height:25px; width:25px;' type='button'></div>" + 
"		</DIV>" + 
"		<DIV id='ScrollRight_"+ScrollName+"'>" + 
"			<div onclick=\"moveRight('"+ScrollName+"')\" style='height:25px; width:25px;' type='button'></div>" + 
"		</DIV>" + 
"	</DIV>" + 
"</DIV>"


if (ImageArray!=null)
	{for (l=0; l<ImageArray.length; l++)
		{
		TDElement=document.createElement("TD");
		TDElement.style.padding = "0px "+ ImageWidth+"px " +"0px "+ImageWidth+"px";
		TDElement.innerHTML="<a href='"+LinkArray[l]+"' ><IMG border='0' src='"+ImageArray[l]+"'><br><p style=\"text-align:center\" class='OARContent'>"+TextArray[l]+"</p></a>"
		document.getElementById('ImageContainer_'+ScrollName).appendChild(TDElement)		
		}
	}

setStyles(ScrollName);
setStylesOnce(ScrollName);

setIDs(ScrollName);
}

function setStylesOnce(ScrollName)
{
document.getElementById('ScrollLeft_'+ScrollName).style.width=40+"px";
document.getElementById('ScrollRight_'+ScrollName).style.width=40+"px";
document.getElementById('ScrollLeft_'+ScrollName).style.height=25+"px";
document.getElementById('ScrollRight_'+ScrollName).style.height=25+"px";

// set z-index
document.getElementById('interface_'+ScrollName).style.zIndex=1;
document.getElementById('ViewingArea_'+ScrollName).style.zIndex=2;
document.getElementById('controls_'+ScrollName).style.zIndex=2;
document.getElementById('ScrollLeft_'+ScrollName).style.zIndex=4;
document.getElementById('ScrollRight_'+ScrollName).style.zIndex=4;


// set positions (left)
document.getElementById('ViewingArea_'+ScrollName).style.left=0+"px";
document.getElementById('controls_'+ScrollName).style.left=0+"px";
document.getElementById('ScrollLeft_'+ScrollName).style.left=13+"px";
document.getElementById('ScrollRight_'+ScrollName).style.left=370+"px";

// set positions (top)
document.getElementById('ViewingArea_'+ScrollName).style.top=0+"px";
document.getElementById('ScrollLeft_'+ScrollName).style.top=10+"px";
document.getElementById('ScrollRight_'+ScrollName).style.top=10+"px";
document.getElementById('controls_'+ScrollName).style.top=ViewingAreaHeight+2+"px";

// set Image Scroller DIVs height Dimensions
document.getElementById('controls_'+ScrollName).style.height=35+"px";
document.getElementById('ViewingArea_'+ScrollName).style.height=ViewingAreaHeight+"px";
document.getElementById('interface_'+ScrollName).style.height=ViewingAreaHeight+35+"px";

// Set Viewer Page position
document.getElementById('interface_'+ScrollName).style.left= PagePositionLEFT+"px";
document.getElementById('interface_'+ScrollName).style.top= PagePositionTOP+"px";
}

function setStyles(ScrollName)
{
// set Image Scroller DIVs width Dimensions and position type
document.getElementById('interface_'+ScrollName).style.position="absolute";
document.getElementById('interface_'+ScrollName).style.width=InterFaceWidth+"px";
document.getElementById('interface_'+ScrollName).style.overflow="hidden";

DIVCol=document.getElementById('interface_'+ScrollName).getElementsByTagName('DIV');
if (DIVCol!=null)
	{for (p=0; p<DIVCol.length; p++)
		{
		DIVCol.item(p).style.position="absolute";
		DIVCol.item(p).style.width=InterFaceWidth+"px";
		if(DIVCol.item(p).id=="ScrollRight")
			{
			DIVCol.item(p).style.width=40+"px";
			DIVCol.item(p).style.textAlign="right";
			}
		}
	}



// text alignment for controller text

// image Viewer Color Scheme


// Image Styles
IMGCol=document.getElementById('interface_'+ScrollName).getElementsByTagName('IMG');
if (IMGCol!=null)
	{for (im=0; im<IMGCol.length; im++)
		{
		IMGCol.item(im).style.borderStyle='solid';
		IMGCol.item(im).style.borderWidth="1px";
		IMGCol.item(im).style.borderColor=ImageBorderColor;
		}
	}

// Button Styles
BTNCol=document.getElementById('interface_'+ScrollName).getElementsByTagName('INPUT');
if (BTNCol!=null)
	{for (p=0; p<BTNCol.length; p++)
		{
		BTNCol.item(p).style.borderStyle='solid';
		BTNCol.item(p).style.borderWidth="1px";
		BTNCol.item(p).style.backgroundColor=ButtonBGColor;
		BTNCol.item(p).style.color=ButtonFontColor;
		BTNCol.item(p).style.borderColor=ButtonBorderColor;
		}
	}

// Table Cell Styles
TDCol=document.getElementById('interface_'+ScrollName).getElementsByTagName('TD');
if (TDCol!=null)
	{for (td=0; td<TDCol.length; td++)
		{TDCol.item(td).style.verticalAlign=ImageValignment;}}
}


// ::::::::::::::::::::::::
// ::: Event Handlers ::
// ::::::::::::::::::::::::



// Set ID's for all table cells
function setIDs(ScrollName)
{
ContainerElement=document.getElementById('ImageContainer_'+ScrollName)
TDCol=ContainerElement.getElementsByTagName('TD');
if (TDCol!=null)
	{	for (i=0; i<TDCol.length; i++)
			{TDCol.item(i).setAttribute('id',i+"_"+ScrollName)}
	}
}

// :::::::::::::::::::::::::
// ::: Scroll Functions ::
// :::::::::::::::::::::::::

function moveLeft(name)
{
ContainerElement=document.getElementById("ImageContainer_"+name);
firstTD=document.getElementById("0_"+name);
dupfirstTD=firstTD.cloneNode(false)
dupfirstTD.innerHTML=firstTD.innerHTML
ContainerElement.removeChild(firstTD);
ContainerElement.appendChild(dupfirstTD);
setStyles(name); setIDs(name);
}

function moveRight(name)
{

TDCol=document.getElementById('interface_'+name).getElementsByTagName('TD');
lastTD=document.getElementById((TDCol.length-1)+"_"+name);
duplastTD=lastTD.cloneNode(false)
duplastTD.innerHTML=lastTD.innerHTML
firstTD=document.getElementById("0_"+name);
ContainerElement=document.getElementById("ImageContainer_"+name);
ContainerElement.insertBefore(duplastTD,firstTD);
ContainerElement.removeChild(lastTD);
setStyles(name); setIDs(name);
}
