var startnum = 0;
var endnum = 1;
var resolution = "small_";
var curnum = startnum;
var folder = "";
var slidetime = 0;
var mode = "idfilm";
function db(m)
{
alert(m);
}



function tomode(newmode)
{
document.getElementById(mode).innerHTML = "&nbsp;";	
mode = newmode;
document.getElementById(mode).innerHTML = "&gt;";	
}

function setModeSlide()
{
tomode("idslide");
printimage();
slidetime = 5000;
setTimeout("movetimed()",slidetime);
}


function setModeFilm()
{
tomode("idfilm");
slidetime = 0;
printimage();
}


function setModeThumb()
{
tomode("idthumb");
slidetime = 0;
printthumbs();
}


function setresolution(res)
{
document.getElementById('id'+resolution).innerHTML = "&nbsp;";	
document.getElementById('id'+res).innerHTML = "&gt;";	
resolution = res;
movepic(0);
}





function movefirst()
{
db('enter movefirst()');
curnum = startnum;
movepic(0);
db('exit movefirst()');
}



function movelast()
{
curnum = endnum;
movepic(0);
}



function movetimed()
{
//db('enter movetimed()');
if( slidetime != 0 )
{
 movepic(1);
 setTimeout("movetimed()",slidetime);
}
//db('exit movetimed()');
}




function setslides(timing)
{
 slidetime = timing.value;
}



function movepic(incr)
{
//db('enter movepic('+incr+')');
curnum = curnum + incr;
if( curnum < 0 )
{
curnum = desc.length - 1;
}
if( curnum >= desc.length )
{
curnum = 0;
}
updateAll();
}


function printimage()
{
var h = '<img src="' + folder + resolution + desc[curnum][0] + '" onclick="movepic(1);" title="click for next"/><br><br>'+desc[curnum][1];
var preload = curnum + 1;
if( preload >= desc.length ) preload = 0;
h = h + '<img src="' + folder + resolution + desc[preload][0] + '" height="1" width="1">';
document.getElementById('picmain').innerHTML = h;
}


function printthumbs()
{
//db('enter printtumbs()');
var h = "";
var idx;
for(idx=0; idx < desc.length; idx++)
{
h = h + '<img width="100" height="100" style="border-Color:#EEEEEE" border="5" src="' + folder + '/thumb_' + desc[idx][0] + 
    '" align="top" onclick="moveabsthumb(' + idx + 
    ');"  title="' + (idx+1) + ') ' + desc[idx][1] + '"> \n';
}
document.getElementById('picmain').innerHTML = h;
}



function nextpic()
{
movepic(1);
}

function prevpic()
{
movepic(-1);
}


var filmstrips = ["picsfilmbkwd2","picsfilmbkwd1","picsfilmcurrent","picsfilmfwd1","picsfilmfwd2"];


function updateLeft()
{
	var fidx = 0;
	for(var idx = -2; idx < 3; idx++)
	{
		var pidx = curnum + idx;
		if( pidx < 0 )
		{
			pidx = pidx + desc.length;
		}
		else if( pidx >= desc.length)
		{
		 pidx = pidx - desc.length;
		}
		document.getElementById(filmstrips[fidx]).src = folder + "thumb_" + desc[pidx][0];
		document.getElementById(filmstrips[fidx]).title =  desc[pidx][1];
		fidx++;
	}
}

function updateAll()
{
updateLeft();
printimage();
}


function moveabsthumb(pnum)
{
setModeFilm();
moveabs(pnum);
}


function moveabs(pnum)
{
curnum = pnum;
movepic(0);
}

function setTitle(title)
{
document.getElementById('picstitle').innerHTML = title;
}



function setup(directory,max)
{
//db('called setup() 001');
endnum = startnum+max;
var urlquery=location.href.split("?");
if(urlquery.length > 1 )
{
	var rnurlterms=urlquery[1].split("=");
	if( rnurlterms.length > 1 )
	{
	   var arg = parseInt(rnurlterms[1]);
	   if( arg <= max && arg >= 0 )
	   {	     
         curnum = arg;	   	 
	   }
	}
}
folder = directory;
setModeFilm();
updateAll();
}