/*******************************************************************************
* Global Variables
*
*******************************************************************************/
var sections = new Array(
	"news",
	"obits",
	"class",
	"feat",
	"blogs",
	"forums",
	"photo",
	"occ",
	"bsm",
	"help",
	"afil"

);

var partial_expand = false;

/*******************************************************************************
* Attached Events
*
*******************************************************************************/

// This is attached to the body's onload event
window.onload = function() {
	if (section != undefined) {

		if (section != "utility") {
		    // Attach rollover effect functions to the food group buttons in the header.
    		for (var i = 0; i < sections.length; i ++ ) {
        		document.getElementById(sections[i] + "_button").onmouseover = swap;
	    	    document.getElementById(sections[i] + "_button").onmouseout  = swap;
		        if (section == sections[i]) {
					document.getElementById(sections[i] + "_button").onmouseover();
				}
			}
		}
	}



	nav_expand();

}

/*******************************************************************************
* function: swap()
*
* This function can only be used by an attached event or called by an event
* handler, because it is expecting the 'this' object to be passed. It uses
* 'this' to infer the image path to the rollover, and to determine the action
* (whether it should turn the image on or off). Then it performs the appropriate
* image swapping.
*******************************************************************************/
// This function was radically modified to account for Read/In-Print food group
// accountability. -TH 20070406
function swap() {

    var image_src   = this.src.split('/');
    var image_path  = "";
	var state 		= (image_src[image_src.length - 1].indexOf("_on.gif") > -1)
	                    ? "on"
	                    : "off";
    var action      = (state == "on")
	                    ? "off"
	                    : "on";
	var group 		= image_src[image_src.length - 1].substr(0, image_src[image_src.length - 1].indexOf('_' + state + '.gif'));

        action      = (group == section)
	                    ? "on"
	                    : action;

    for (var i = 0; i < image_src.length - 1; i ++ ) {
        image_path += image_src[i] + '/';
    }



}





/*******************************************************************************
* nav_expand(arg)
*
* Added Sept. 11, 2006 by Tobby
*
* This function controls the left-rail main navigation. If called without an 
* argument, it opens the default portion of the nav (based on the global
* variable "section" set in page.tpl.php). If a valid food group is passed
* as an argument, the nav expands that section.
*
* The variable "partial_expand" is set at the top of this file, and tells this
* function whether or not to partially expand all sections of the nav.
*******************************************************************************/
function nav_expand(arg) {
	if (!document.getElementById("left-rail-nav")) return;

	var nav_section 		= (arg) ? arg : section;
	var nav_sections 	= new Array("news", "obits", "class", "feat", "blogs", "forums", "photo", "occ", "bsm", "help", "afil");

	for (i = 0; i < nav_sections.length; i ++) {
	
		if (nav_section != nav_sections[i]) {
	
			document.getElementById("nav-block-main-" + nav_sections[i]).style.display 	= "none";
			document.getElementById("nav-block-major-" + nav_sections[i]).style.display 	= "none";
			document.getElementById("nav-block-minor-" + nav_sections[i]).style.display 	= "none";
			document.getElementById("nav-block-more-" + nav_sections[i]).style.display 	= "none";
			if (document.getElementById("nav-open-link-" + nav_sections[i]))
				document.getElementById("nav-open-link-" + nav_sections[i]).innerHTML		= "[open]";
			
			if (partial_expand) {
				document.getElementById("nav-block-main-" + nav_sections[i]).style.display 	= "block";
				document.getElementById("nav-block-major-" + nav_sections[i]).style.display 	= "block";
				document.getElementById("nav-block-more-" + nav_sections[i]).style.display 	= "block";
			}
		} else {
			// Hides the sub navs based on the partial expanding preference.
			if (document.getElementById("nav-block-minor-" + nav_section).style.display == "block") {
				if (partial_expand) {
					document.getElementById("nav-block-main-" + nav_section).style.display	= "block";
					document.getElementById("nav-block-major-" + nav_section).style.display	= "block";
					document.getElementById("nav-block-more-" + nav_section).style.display	= "block";
					document.getElementById("nav-block-minor-" + nav_section).style.display	= "none";
					if (document.getElementById("nav-open-link-" + nav_section))
						document.getElementById("nav-open-link-" + nav_section).innerHTML	= "[close]";


				} else {
					document.getElementById("nav-block-main-" + nav_section).style.display	= "none";
					document.getElementById("nav-block-major-" + nav_section).style.display	= "none";
					document.getElementById("nav-block-more-" + nav_section).style.display	= "block";
					document.getElementById("nav-block-minor-" + nav_section).style.display	= "none";
					if (document.getElementById("nav-open-link-" + nav_section))
						document.getElementById("nav-open-link-" + nav_section).innerHTML	= "[open]";
				}

			// Shows the sub nav
			} else {
				document.getElementById("nav-block-main-" + nav_section).style.display	= "block"
				document.getElementById("nav-block-major-" + nav_section).style.display	= "block"
				document.getElementById("nav-block-more-" + nav_section).style.display	= "none"
				document.getElementById("nav-block-minor-" + nav_section).style.display	= "block"
				if (document.getElementById("nav-open-link-" + nav_section))
					document.getElementById("nav-open-link-" + nav_section).innerHTML	= "[close]";
			}
		}
	}
}

