/*
Reveal/Hide
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-29

The latest version should be available at
<http://demo.fairsky.us/javascript/reveal_hide.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>.
*/

var gViewRadios = new Array();

function clickReveal(e)
{
	var id = revealHideGetId(this);
	var n = document.getElementById(id);
	if(n)
	{
		if(n.style.display!='none')
		{
			this.hideTarget = clickHide;
			this.hideTarget();
		}
		else
		{
			revealRadio(n);
			n.style.display = 'block';
			revealHideChain(n);
		}
	}
	return false;
}

function clickHide(e)
{
	var id = revealHideGetId(this);
	var n = document.getElementById(id);
	if(n)
	{
		n.style.display = "none";
		revealHideChain(n);
	}
	return false;
}

function revealHideChain(n)
{
	if(n.style.display == 'none' && n.visibilityChain){ for(var x=0; x<n.visibilityChain.length; x++){ n.visibilityChain[x].style.display = 'none'; revealHideChain(n.visibilityChain[x]); } }
	else if(n.visibilityChain){ for(var x=0; x<n.visibilityChain.length; x++){ n.visibilityChain[x].style.display = 'block'; revealHideChain(n.visibilityChain[x]); } }
}

function revealRadio(n)
{
	var radio, x;
	if(n.visRadio)
	{
		radio = gViewRadios[n.visRadio];
		for(x=0; x<radio.length; x++)
		{
			if(radio[x].style.display != 'none')
			{
				radio[x].style.display = 'none';
				revealHideChain(radio[x]);
			}
		}
	}
}

function loadReveal()
{
	var id, winId, n;
	id = revealHideGetId(this);
	winId = revealHideGetId(window.location);;
	if(n = document.getElementById(id))
	{
		if(id==winId || n.className.indexOf('Fsp.ViewDefault')!=-1)
		{
			n.style.display = "block";
			revealHideChain(n);
		}
		else
		{
			n.style.display = "none";
			revealHideChain(n);
		}
	}
}

function loadViewChain()
{
	var c, id, t;
	c = this.className;
	id = /ViewChain:(\S+)\b/.exec(c);
	if(id && id[1])
	{
		id = id[1];
		t = document.getElementById(id); 
		if(t) 
		{
			if(!t.visibilityChain) t.visibilityChain = new Array();
			t.visibilityChain[t.visibilityChain.length] = this;
		}
	}
}

function loadViewRadio()
{
	var c, radio, r;
	c = this.className;
	radio = /ViewRadio:(\S+)\b/.exec(c);
	if(radio && radio[1])
	{
		radio = radio[1];
		if(!gViewRadios[radio]) gViewRadios[radio] = new Array();
		r = gViewRadios[radio];
		r[r.length] = this;
		this.visRadio = radio;
	}
}

function revealHideGetId(a)
{
	var pound, id;
	pound = a.href.indexOf('#');
	id = a.href.substring(pound+1);
	return id;
}

document.register('*','ViewChain',loadViewChain,'load',false);
document.register('*','ViewRadio',loadViewRadio,'load',false);
document.register('a','Reveal',clickReveal,'click',true);
document.register('a','Reveal',loadReveal,'load',false);
document.register('a','Hide',clickHide,'click',true);
