var imagePath;
var imageIdx = 0;
var imageOn = true;

var imageCnt;

var resPath;

function onOffBGImage()
{
	imageOn = imageOn == true ? false : true;
	doBGImageChange();
}

function prevBGImage()
{
	if (imageOn == true)
	{
		if (--imageIdx < 0)
			imageIdx = imageCnt - 1;
		doBGImageChange();
	}
}

function nextBGImage()
{
	if (imageOn == true)
	{
		if (++imageIdx >= imageCnt)
			imageIdx = 0;
		doBGImageChange();
	}
}

function initPage(index, ccWidth)
{
	var galleryName;
	var anobj;

	anObj=document.getElementById("columnCenter");
	if (anObj)
	{	
		anObj.style.width = ccWidth + "px";
	}
	
	resPath = "0400/";

	imageCnt = document.imgList.imgSel.length;

	galleryName = document.paramList.paramSel.options[0].value;
	imagePath = document.paramList.paramSel.options[0].text + "zVQuil3ioRT87D30/" ;

	if (imageOn == true)
	{
		if (imageCnt > 0)
		{
			anObj=document.getElementById("galleryNameBlock");
			if (anObj)
			{	
				anObj.innerHTML = galleryName;
			}
			anObj=document.getElementById("galleryNavigationBlock");
			if (anObj)
			{
				anObj.innerHTML = "View photographs by clicking " +
				'<a href="javascript:prevBGImage();" name="Previous Background Image">Prev</a>' +
				' or <a href="javascript:nextBGImage();" name="Next Background Image">Next</a>';
			}
		}

		imageIdx = index;

		if (imageIdx == -1)
			imageIdx = Math.floor(Math.random() * imageCnt);
		else
		if (imageIdx >= imageCnt)
			imageIdx = imageCnt - 1;
		else
		if (imageIdx < 0)
			imageIdx = 0;

		doBGImageChange();
	}
}

function doBGImageChange()
{
	var urlStr = "";
	var captionStr = "";

	if (imageOn == true)
	{
		urlStr = "url(\"" + imagePath + resPath + document.imgList.imgSel.options[imageIdx].text + "\")";
		captionStr = document.imgList.imgSel.options[imageIdx].value;
	}
	
	if (imageCnt > 0)
	{
		anObj=document.getElementById("galleryMain");
		if (anObj)
		{	
			anObj.style.background = urlStr;
			anObj.style.backgroundRepeat = "no-repeat";
			anObj.style.backgroundPosition = "0px 0px";
		}
	
		galleryCnt = " [" + (imageIdx + 1) + " of " + imageCnt + "] " ;

		anObj=document.getElementById("galleryPhotoCaptionBlock");
		if (anObj)
		{
			anObj.innerHTML = galleryCnt + captionStr;
		}
/*
		anObj=document.getElementById("galleryCount");
		if (anObj)
		{	
			anObj.innerHTML = galleryCnt;
		}
*/
	}
}
