// JavaScript Document


/*
 * Function to show/hide an element by ID
 * @param hide_elem
 *     returns the ID of the element to hide
 */
 
function show_hide_id(hide_elem) {
	
	elem_to_hide = document.getElementById(hide_elem);
	
	if (elem_to_hide != null) { // ensure the list exists...
		if (elem_to_hide.style.display == 'none') {
			elem_to_hide.style.display = 'block'; // show it
		}
		else {
			elem_to_hide.style.display = 'none'; // hide it
		}
	}
}

/*
 * Function for image rollovers
 * @param elem
 *     returns the anchor element
 */ 
function swap(root, elem) {
	if(root == '/')
		root = '';
	cur_src = elem.firstChild.src;
	cur_src = cur_src.substring(cur_src.lastIndexOf('/')+1);

	if (cur_src.indexOf('h_') == -1 && cur_src.indexOf('a_') == -1) {
		elem.firstChild.src = root + '/i/nav/' + 'h_' + cur_src;
		
	}
	else if(cur_src.indexOf('a_') == -1){
		elem.firstChild.src = root + '/i/nav/' + cur_src.substring(2);
	}
}
/*
 * Function to show/hide elements for recurrance scheduler
 * @param elem
 *     returns the element to show
 */
 
function show_recurrance(elem) {
	
	elem_to_show = document.getElementById(elem);
	
	// start by hiding all elements
	document.getElementById('daily').style.display = 'none';
	document.getElementById('weekly').style.display = 'none';
	document.getElementById('monthly').style.display = 'none';
	
	elem_to_show.style.display = 'block'; // show it
}

/*
 * Function to show one element while hiding others in an array
 * Using this on the tabbed sub menu control
 */

function show_hide_group(show_elem,arr_to_hide,arr_tabs_to_hide,tab_to_show) {
	
	var show_this = document.getElementById(show_elem);
	
	if (show_this != null) {
		if (show_this.style.display == 'none') {
			show_this.style.display = '';
			tab_to_show.className = 'selected';
		}
	}
	
	//loop through items to hide them
	for (var i = 0; i < arr_to_hide.length; i++) {
		var hide_this = document.getElementById(arr_to_hide[i]);
		if (hide_this != null) {
			if (hide_this.style.display == '') {
				hide_this.style.display = 'none';
			}
		}
	}
	
	//loop through tabs to hide them
	for (var i = 0; i < arr_tabs_to_hide.length; i++) {
		var hide_this = document.getElementById(arr_tabs_to_hide[i]);
		if (hide_this != null) {
			if (hide_this.className == 'selected') {
				hide_this.className = '';
			}
		}
	}
}


//This function is used to display the News by default
//on all the news pages. It's called in the html in a script block,
//and calls the show_hide_group function above when the page is loaded.
function ShowNewsTab() {
	var newsBlock = document.getElementById('news_tab');
	var	hide_these = new Array('blog_box','action_box');
	var hide_tabs = new Array('action_tab','blog_tab');
	show_hide_group('news_box',hide_these,hide_tabs,newsBlock);
}

//This function is used to display the Blog tab by default
//on all the blog pages. It's called in the html in a script block,
//and calls the show_hide_group function above when the page is loaded.
function ShowBlogTab() {
	var blogBlock = document.getElementById('blog_tab');
	var	hide_these = new Array('news_box','action_box');
	var hide_tabs = new Array('action_tab','news_tab');
	show_hide_group('blog_box',hide_these,hide_tabs,blogBlock);
}


/* FOR HANDLING DROP-DOWN MENUS WITH IE */

/*
 * Function to fix IE bug where <select> elements go over dropdowns
 * @param elem
 *     the element hovered over (link)
 * @param state
 *     the state of the hover (true for hover, false for unhover)
 */

function dropdownFix(elem, state) {
	ul = elem.parentNode.getElementsByTagName('ul')[0];
	if(ul != null)
	{
		navElem = document.getElementById('tabs');
		iframe = document.getElementById('iefix');
		if (state) {
			iframe.style.width = ul.offsetWidth - 7; // width of the ul minus the width of the png shadow
			iframe.style.height = ul.offsetHeight - 8; // height of the ul minus the height of the png shadow
			if (ul.id == 'ul_about') {
			    iframe.style.left = navElem.offsetLeft + elem.parentNode.offsetLeft + 6; // position of the #nav div + position of the li + the custom offset for the "about" menu
			}
			else {
				iframe.style.left = navElem.offsetLeft + elem.parentNode.offsetLeft; // position of the #nav div + position of the li
			}
			iframe.style.top = ul.offsetTop; // position of the ul from the top
			iframe.style.display = "block";
		}
		else {
			iframe.style.display = "none";
		}
	}
}

startList = function() {

 if (document.all && document.getElementById) {
	var navRoot = document.getElementById('tabs');
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += " over";
					dropdownFix(this.firstChild, true);
  				}
  				node.onmouseout = function() {
  					this.className = this.className.replace(" over", "");
					dropdownFix(this.firstChild, false);
   				}
   		}
  	}
 }	
}
window.onload = startList;


