
var playPicSlide = 0;
var pausePicSlide = 1;
var playIntervalMode;
var delayPlaySlide = 8000;

// Create picProject object
function picProject(projID,projName)
{
	this.projID = projID;
	this.projName = projName;
	this.picRecord = new Array();
}

// Create picRecord object
function picRecord(record)
{
	this.record = record;
	this.picItem = new Array();
}
// addPicItem function is to add picture attributes
// to picRecord object
function picItem(fpath,fCname,fSname,fcaption,fwidth)
{
	this.fpath = fpath;
	this.fCname = fCname;
	this.fSname = fSname;
	this.fcaption = fcaption;
	this.fwidth = fwidth;
}

function loadProjList(selIndex)
{
	var str = '';
	projListIndex = selIndex;
	if(aPicPhoto.length)
	{
		str += '<select name="selectProjList" onchange="changeProjectList(this)" style="width:100%;">';
		for(var i=0; i<aPicPhoto.length; i++)
		{
			if(selIndex == i)
				str += '<option value="'+i+'" selected>'+aPicPhoto[i].projName+'</option>';
			else
				str += '<option value="'+i+'">'+aPicPhoto[i].projName+'</option>';
		}
		str += '</select>';
	}
	if(projSelectionDivOption)
		projSelectionObj.innerHTML = str;
	
}
function loadDateList(selIndex)
{
	var str = '';
	dateListIndex = selIndex;
	if(aPicPhoto[projListIndex].picRecord.length)
	{
		str += '<select name="selectDateList" onchange="changeDateList(this)">';
		for(var i=0; i<aPicPhoto[projListIndex].picRecord.length; i++)
		{
			if(selIndex == i)
				str += '<option value="'+i+'" selected>'+aPicPhoto[projListIndex].picRecord[i].record+'</option>';
			else
				str += '<option value="'+i+'">'+aPicPhoto[projListIndex].picRecord[i].record+'</option>';
		}
		str += '</select>';
	}
	dateSelectionObj.innerHTML = str;
}
function changeProjectList(projObj)
{
	dateListIndex = 0;
	picListIndex = 0;
	projListIndex = projObj.value;
	loadDateList(dateListIndex);
	loadPicList(picListIndex);
}
function changeDateList(dateObj)
{
	picListIndex = 0;
	dateListIndex = dateObj.value;
	loadPicList(picListIndex);
}
function displayPhoto(fname)
{
	if(clickableImage)
		window.open(progPhotoPath+fname,'_blank','width=800,height=600,resizable=yes,scrollbars=yes');
}
function loadPicList(selIndex)
{
	var strPic = noPhotoValue;
	var strCounter = 'Pic 0 of 0';
	var strDesc = '';
	var clickable = '';
	var curPic = selIndex + 1;
	if(aPicPhoto[projListIndex].picRecord.length && aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length)
		var maxPic = aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length;
	else
		var maxPic = 0;

	picListIndex = selIndex;
	if(maxPic)
	{
		if(clickableImage)
			clickable = ' onclick="displayPhoto(\''+aPicPhoto[projListIndex].picRecord[dateListIndex].picItem[selIndex].fSname+'\')" alt="Click here to display"';
		strPic = '<img src="'+progPhotoPath+aPicPhoto[projListIndex].picRecord[dateListIndex].picItem[selIndex].fSname+'" border="0" width="'+progPhotoWidth+'"'+clickable+'>';
		strCounter = 'Pic ' + curPic + ' of ' + maxPic;
		strDesc = aPicPhoto[projListIndex].picRecord[dateListIndex].picItem[selIndex].fcaption
	}
	photoImageObj.innerHTML = strPic;
	picNumberObj.innerHTML = strCounter;
	descNoteObj.innerHTML = strDesc;
}
function firstLoad(prjIndex)
{
	loadProjList(prjIndex);
	loadDateList(dateListIndex);
	loadPicList(picListIndex);
}
function playPic()
{
	var curPic = picListIndex;
	var maxPic = aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length
	if((curPic+1) < maxPic)
		loadPicList(++curPic);
	else
	{
		window.clearInterval(playIntervalObj);
		playMode = 0;
		stopMode = 1;
	}
}
function NavigatePic(navMode)
{
	var curPic = picListIndex;
	if(aPicPhoto[projListIndex].picRecord.length && aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length)
		var maxPic = aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length;
	else
		var maxPic = 0;
	if(navMode == playButtonVal)
	{
		if(!playMode && maxPic)
		{
			playMode = 1;
			playIntervalObj = window.setInterval(playPic,7000);
		}
		return;
	}
	/*var maxPic = aPicPhoto[projListIndex].picRecord[dateListIndex].picItem.length
	if(navMode == playButtonVal)
	{
		if(!playMode)
		{
			playMode = 1;
			playIntervalObj = window.setInterval(playPic,7000);
		}
		return;
	}*/
	if(navMode == stopButtonVal)
	{
		if(playMode)
		{
			window.clearInterval(playIntervalObj);
			playMode = 0;
			stopMode = 1;
		}
		else
		{
			alert('It is not in the play mode');
		}
	}
	if(navMode == nextButtonVal)
	{
		if((curPic+1) < maxPic)
			curPic++;
		else
			alert('End of list reached');
	}
	if(navMode == lastButtonVal)
	{
		if((curPic+1) < maxPic)
			curPic = maxPic -1;
		else
			alert('End of list reached');
	}
	if(navMode == prevButtonVal)
	{
		if(curPic > 0)
			curPic--;
		else
			alert('Beginning of list reached');
	}
	if(navMode == firstButtonVal)
	{
		if(curPic > 0)
			curPic = 0;
		else
			alert('Beginning of list reached');
	}
	if(curPic != picListIndex)
	{
		loadPicList(curPic)
		picListIndex = curPic;
	}
}



