/*
Presenter
FairSky Pages Component
-----------------------
Copyright 2004 Joshua Paine
Created by Joshua Paine of FairSky Networks <http://fairsky.us/>
Contact at <http://fairsky.us/contact>
Updated 2004-05-18

The latest version should be available at
<http://demo.fairsky.us/javascript/presenter.html>

You may copy, reuse, or produce derivative works of this code
only under the terms of the Linky License v0.1 or later.
The Linky License can be found at <http://fairsky.us/linky>.
The main points of the license are:
	1) Do not alter or remove this notice.
	2) Notify me of your usage through one of the means listed
	   at <http://fairsky.us/contact>.
*/

gPage = 0;
gClickAction = null;
gFsAutoLoop = false;

function fspPresenterSetup()
{
	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('Fsp.Presenter.AutoLoop') && 
		document.getElementsByName('Fsp.Presenter.AutoLoop')[0] &&
		document.getElementsByName('Fsp.Presenter.AutoLoop')[0].content=='true') gFsAutoLoop = true;
	aaRegx = /Presenter\.AutoAdvance:([0-9]+)/;
	var aaDetails = d.className.match(aaRegx);
	if(aaDetails && aaDetails[1])
	{
		setTimeout('gClickAction();',1000*aaDetails[1]);
	}
	else
	{
		autoAdvance = document.getElementsByName('Fsp.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 the beginning of the presentation?')) window.location.href = "?page=0";
}

document.register('body','Presenter',fspPresenterSetup,'load',false);