/*
This script is Copyright 2004 Joshua Paine of <http://fairsky.us/>.
The latest version should be available at
<http://demo.fairsky.us/javascript/presenter.html>

You are hearby granted permission to reuse this code on any website
provided that you agree to the following:

For all uses of this code:
--This notice must remain unaltered.

For all public uses of this code, where public is understood to mean
available to the general public on the Internet or through any
members-only service where the conditions of membership and technological
features do not exclude the possibility of a large number of people having
access to the given instance of use of this code:
--You will contact Joshua Paine with a link to your use of
  the code within two weeks of your use becoming public via at least one
  of the methods offered at <http://fairsky.us/contact>.
--Joshua Paine may, at his discretion, post links to your use of the code 
  in any such places as he may write about the code or users of the code.

*/

gPage = 0;
gClickAction = null;
gFsAutoLoop = false;

function setup()
{
	var c;
	if(window.location.search && window.location.search.length > 1)
	{
		var search = window.location.search.substring(1);
		var q = search.split('&');
		window.GET = new Object();
		for(var x=0; x<q.length; x++)
		{
			if(q[x])
			{
				c = q[x].split('=');
				if(!c[1]) c[1] = '';
				eval('window.GET.'+c[0]+'=c[1];');
			}
		}
		if(window.GET.page) gPage = 1*window.GET.page;
	}
	var children = document.body.childNodes;
	var child;
	var ds = new Array();
	for(var i=0; i<children.length; i++)
	{
		child = children[i];
		if(child.tagName && child.tagName.toLowerCase()=='div') ds[ds.length] = child;
	}
	if(!ds[gPage]){ gPage = 0; }
	var d = ds[gPage];
	d.style.visibility = 'visible';
	if(gPage+1 < ds.length) gClickAction = clickNext;
	else gClickAction = clickLast;
	d.onclick = gClickAction
	if(document.getElementsByName('FairSky.Presenter.AutoLoop') && 
		document.getElementsByName('FairSky.Presenter.AutoLoop')[0] &&
		document.getElementsByName('FairSky.Presenter.AutoLoop')[0].content=='true') gFsAutoLoop = true;
	aaRegx = /FairSky\.Presenter\.AutoAdvance:([0-9]+)/;
	var aaDetails = d.className.match(aaRegx);
	if(aaDetails && aaDetails[1])
	{
		setTimeout('gClickAction();',1000*aaDetails[1]);
	}
	else
	{
		autoAdvance = document.getElementsByName('FairSky.Presenter.AutoAdvance');
		if(autoAdvance && autoAdvance.length)
		{
			autoAdvance = autoAdvance[autoAdvance.length-1].content;
			if(autoAdvance > 0) setTimeout('gClickAction();',1000*autoAdvance);;
		}
	}
}

function clickNext()
{
	window.location.href = "?page="+(gPage+1);
}

function clickLast()
{
	if(gFsAutoLoop || confirm('Return to beginning of card?')) window.location.href = "?page=0";
}

window.onload = setup;