
var scrollInterval = 0;

var SMALL = '_sm'
var MEDIUM = '_med'
var LARGE = '_lg'

var JPG = '.jpg'

/*
* Change the src of the element 'from' to 'to'.
* @param from - the element to change the src of.
* @param to - the new src to be set for 'from'
*/
function changer(from, to) 
{
	from.src=to;
}

/*
* Change the src of the element with id 'id' to 'to'.
* @param id - the id of the element to change the src of
* @param to - the new src to be set for the element
*/
function changerID(id, to) 
{
	document.getElementById(id).src=to;
}

/*
* Change the src of the image with id 'id' to image with number
* 'newImgID'. Also change the border of the new image to teal
* And the border of the old image to white.
*
* @param id - the id of the image to change the src of
* @param newImgID - the id of the image to change it to
*/
function setNewImg(id, newImgID)
{               
	document.getElementById("s" + currImageNum).style.border="1px solid white"
	document.getElementById(newImgID).style.border="1px solid #339999"
	
	changeImgID(id, newImgID)
}

/*
* Change the src of the image with id 'id' to image with number
* 'newImgNum'.
*
* @param id - the id of the image to change the src of
* @param newImgID - the ID of the image to change it to
*/
function changeImgID(id, newImgID)
{
	document.getElementById(id).src=medImages[parseInt(newImgID.charAt(1))]
	currImageNum = parseInt(newImgID.charAt(1))
}

/*
* Move to the next thumbnail img (could be forward or backward)
* If the max or min is reached, it will roll around. ie 8->0, 0->8
*
* @param dir - the direction to move. 1 is forward, -1 is backward
*/
function nextImg(dir)
{                     
    var c = currImageNum
    
	newImg = c + dir
    
	if(newImg < 0)
		newImg = numImages - 1
		
	if(newImg> numImages -1)
		newImg = 0;
	
	setNewImg('big', "s" + newImg);	
}

function load()
{	
	if(numImages > 0)
	{
		/*
		* Build all the images correct names for sizes
		*/
		for( var i=0; i < numImages; i++)
		{
			smImages[i] = rawImages[i] + SMALL + JPG
			medImages[i] = rawImages[i] + MEDIUM + JPG
			lgImages[i] = rawImages[i] + LARGE + JPG
		}
		
		//load in all the preview images
		for(var j = 0; j < numImages ; j++)
		{
	    	var imgObj = document.getElementById("s" + parseInt(j));
	    	
	    	
	        imgObj.src=smImages[j];
			imgObj.style.border="1px solid white";
	   		
	   		imgObj.onmouseover=function() {setNewImg('big', this.id);}
	    
	    	var aObj = document.getElementById('a' + j)
	    
			aObj.href=lgImages[j];
	   		aObj.title=captions[j];
	        aObj.rel="lightbox[a]";
		}
	
	
	   	for(var m = numImages; m < 8; m++)
	   	{
			//img
	        document.getElementById('s' + m).style.border="0px solid white";
	        //link
	        document.getElementById('a' + m).style.border="0px solid white";
	        document.getElementById('a' + m).style.cursor="default"
	    }
	    
		for(var j = 0; j < numImages ; j++)
		{
			document.getElementById('a' + j).rel="lightbox[NAME_OF_PAGE]";
		} 
		
	    //set 0 as the default image in the big window
	    setNewImg('big', 's0') 
	    
	    preloadImages()
	}
}

/* 
* Preload all the medium images on each page for faster roll-overs.
*/
function preloadImages()
{
	var preloadImages = new Array(numImages);

	for(var i = 0; i < numImages; i++)
	{
		preloadImages[i] = new Image();
		preloadImages[i].src = medImages[i];
	}
	
	var tealLeft = new Image();
	tealLeft.src = "images/arrow_tealleft.gif";
	
	var tealRight = new Image();
	tealRight.src = "images/arrow_tealright.gif";
}

/*
* Scroll the internal iFrame.
* @param dir - The direction to scroll. 0 is up. 1 is down.
*/
function scroll(dir)
{
	//scroll one increment
	window.frames.dmain.scrollDiv(dir);
    
    //make sure any previous intervals are cancelled out.
    //(This deals with the click-and-slide-mouse-off-side problem
    if(scrollInterval !=0)
    	stopInter()
    
    //scroll continuously. setup a timer to do it for us.
    if(dir == 1)
   		scrollInterval = setInterval("window.frames.dmain.scrollDiv(1)", 5)
    else
    	scrollInterval = setInterval("window.frames.dmain.scrollDiv(0)", 5)             
}

/*
* Stop the currently running interval.
* Used to stop mouse-down-continuous-scrolling
*/
function stopInter()
{
    clearInterval(scrollInterval);
    scrollInterval = 0;
} 

addEvent(window, "load", load);

//Event.observe(window, 'load', load, false);