/*
 * Authors: Spencer Shimko <sshimko@tresys.com>
 *
 * Copyright 2008 Tresys Technology
 */

/* use scriptaculous' appear effect to show hide element i 
 * i = element id 
 */
function toggleShowHide(i)
{
        var e = document.getElementById(i)
        if (e.style.display == 'none') {
		new Effect.toggle(e, 'appear');
        } else {
		new Effect.toggle(e, 'appear');
        }

}

/* use scriptaculous' appear effect to show element i 
 * i = element id 
 */
function show(i)
{
        var e = document.getElementById(i)
        if (e.style.display == 'none') {
		new Effect.toggle(e, 'appear');
        } 
}

/* use scriptaculous' appear effect to hide element i 
 * i = element id 
 */
function hide(i)
{
        var e = document.getElementById(i)
        if (e.style.display != 'none') {
		new Effect.toggle(e, 'appear');
        } 
}

/* toggle bg position between two positions 
 * use it onclick so you can pass the same values each time 
 * i = element ID, pos1 = bg position 1, pos2 = bg position 2
 */
function toggleBGPos(i, pos1, pos2)
{
       var e = document.getElementById(i)
        if (e.style.backgroundPosition == pos1) {
                e.style.backgroundPosition = pos2;
        } else {
                e.style.backgroundPosition = pos1;
        }

}

/* swap between two classes 
 * i = element id, c1 = class 1, c2 = class 2
 */
function toggleClass(i, c1, c2)
{
       var e = document.getElementById(i)
        if (e.className == c1) {
                e.className = c2;
        } else {
                e.className = c1;
        }

}

/* get a list of child anchor nodes of element i then 
 * try to find an element linking to our current URL
 * i = element id, c = class to set on the anchor element if found
 */
function findAndSetCurrentURLClass(i,c)
{
	var e = document.getElementById(i)
	var url = document.location.toString();
        if (url.match('#')) {
        	url = url.split('#')[0]; 
	}
	var a = e.getElementsByTagName("a");
	for (x=0; x < a.length; x++) {
		if (a[x].toString().match(url)) {
			a[x].className = c;
		}
	}
}

/* get a list of child anchor nodes of element i then 
 * try to find an element linking to our current URL
 * i = element id, i_new = new id
 */
function findAndSetCurrentURLID(i,i_new)
{
	var e = document.getElementById(i)
	var url = document.location.toString();
        if (url.match('#')) {
        	url = url.split('#')[0]; 
	}
	var a = e.getElementsByTagName("a");
	for (x=0; x < a.length; x++) {
		if (a[x].toString().match(url)) {
			a[x].id = i_new;
		}
	}
}

function showIDIfAnchored(a,i) 
{
        var url = document.location.toString();
        if (url.match('#')) {
                var anchor = url.split('#')[1]; 
                if (anchor.match(a)) {
                        var e = document.getElementById(i);
                        e.style.display = 'block';
		}
	}
}

function hideIDIfAnchored(a,i) 
{
        var url = document.location.toString();
        if (url.match('#')) {
                var anchor = url.split('#')[1]; 
                if (anchor.match(a)) {
                        var e = document.getElementById(i);
                        e.style.display = 'none';
		}
	}
}

function bgPosIfAnchored(a,i,p)
{
        var url = document.location.toString();
        if (url.match('#')) {
                var anchor = url.split('#')[1]; 
                if (anchor.match(a)) {
                        var e = document.getElementById(i);
                        e.style.backgroundPosition = p;
		}
	}
} 

function setClassIfAnchored(a,i,c)
{
        var url = document.location.toString();
        if (url.match('#')) {
                var anchor = url.split('#')[1]; 
                if (anchor.match(a)) {
                        var e = document.getElementById(i);
                	e.className = c;
		}
	}
}
