var ss_delay = 5;
var ss_d1 = 0;
var ss_d2 = 0;
var ss_first;
function navigate(where)
{
	switch (where)
	{
	  case 'first':
		n = 0;
		break;
	  case 'prev':
		if (--n < 0)
			n = nUrls - 1;
		break;
	  case 'home':
		document.location = home;
		return;
		break;
	  case 'next':
		if (++n >= nUrls)
			n = 0;
		break;
	  case 'last':
		n = nUrls - 1;
		break;
	}
	url = urls[n] + '?sd=' + ss_delay;
	document.location = url;
}
function key(e)
{
	if (!e)
		e = window.event;
	switch (e.keyCode)
	{
	  case 83:
	  	startslideshow();
		break;
	  case 36:
		if (e.ctrlKey)
			navigate('home');
		break;
	  case 37:
		if (e.ctrlKey)
			navigate('first');
		else
			navigate('prev');
		break;
	  case 39:
		if (e.ctrlKey)
			navigate('last');
		else
			navigate('next');
		break;
	}
}
function startslideshow()
{
	url = ss_first + '?sd=' + ss_delay + ',sa=1';
	document.location = url;
}
function initdelay(l)
{
	var delays = [ "3", "5", "10", "20", "60" ];
	obj = document.getElementById(l);
	for (i = 0; i < 5; ++i) {
		entry = document.createElement('option');
		entry.text = delays[i] + " Seconds";
		entry.value = delays[i];
		old = obj.options[i];
		try {
			obj.add(entry,old);
		}
		catch(ex) {
			obj.add(entry,i);
		}
		if (delays[i] == ss_delay)
			obj.selectedIndex = i;
	}
}
function initslideshow(first,d1,d2)
{
	ss_first = first;
	ss_d1 = d1;
	ss_d2 = d2;
	if (document.images)
	{
		 _play0 = new Image(24,24);
		 _play0.src = "images/_play0.gif";
		 _play1 = new Image(24,24);
		 _play1.src = "images/_play1.gif";
	}
	playimg0 = "images/_play0.gif";
	playimg1 = "images/_play1.gif";
	playalt = "Start Slide Show (S)";
	args = getArgs();
	if (args.sd) {
		ss_delay = parseInt(args.sd);
	}
	if (ss_d1)
	{
		initdelay('delay1');
		document.play1.alt = playalt;
	}
	if (ss_d2)
	{
		initdelay('delay2');
		document.play2.alt = playalt;
	}
}
function setdelay(l)
{
	obj = document.getElementById(l);
	i = obj.selectedIndex;
	ss_delay = obj.options[i].value
	switch (l)
	{
	  case 'delay1':
	  	if (ss_d2)
			document.getElementById('delay2').selectedIndex = i;
		break;
	  case 'delay2':
	  	if (ss_d1)
			document.getElementById('delay1').selectedIndex = i;
		break;
	}
}
function setplay(opt)
{
	switch (opt)
	{
	  case 'in':
		if (ss_d1)
			document.play1.src = playimg1;
		if (ss_d2)
			document.play2.src = playimg1;
		break;
	  case 'out':
		if (ss_d1)
			document.play1.src = playimg0;
		if (ss_d2)
			document.play2.src = playimg0;
		break;
	}
}
function load(l)
{
	obj = document.getElementById(l);
	i = obj.selectedIndex;
	obj.selectedIndex = n;
	document.location = urls[i];
}
function initlist(l)
{
	obj = document.getElementById(l);
	for (i = 0; i < nUrls; ++i) {
		start = i * nPerIndex + 1;
		entry = document.createElement('option');
		end = start + nPerIndex - 1;
		if (end > nPages)
			end = nPages;
		entry.text = start.toString(10);
		if (end != start)
			entry.text += '-' + end.toString(10);
		entry.value = i+1;
		old = obj.options[i];
		try {
			obj.add(entry,old);
		}
		catch(ex) {
			obj.add(entry,i);
		}
	}
	obj.selectedIndex = n;
}
function getArgs()
{
	args = new Object();
	query = location.search.substring(1);
	pairs = query.split(",");
	for (i = 0; i < pairs.length; i++) 
	{
		pos = pairs[i].indexOf('=');
		if (pos == -1)
			continue;
		argname = pairs[i].substring(0,pos);
		value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}

