// wait for the DOM to be ready, which is a little sooner than when the page loads for the user
$(document).ready(function() {
    // hide the specified element
    $('.slide_contents').hide();
    // hide the specified element
    $('#javascript_error').hide();
    // show the specified element
    $('.startOpen').show();
    // add a click handler to the specified element
    $('a.slide_link').click(function() {
        /*
           crawl up the DOM tree by finding the ancestor element of
           of the one that was just clicked. then, go to the sibling
           element (next), and then toggle that element 
        */
        $(this).parents('.slide_parent').next('.slide_contents').slideToggle('fast');
    });
    // fill the specified element with some code
    $('#toggle_background').html('<input id="all_slide_show" type="radio" name="slide_toggle" tabindex="0" /> <label for="all_slide_show">Expand all submenus.</label> <input id="all_slide_hide" type="radio" name="slide_toggle" tabindex="1" /> <label for="all_slide_hide">Hide all submenus.</label>');
    // add a click handler to the specified element
    $('#all_slide_show').click(function() {
        // show all of the specified elements
        $('.slide_contents').show('fast');
    });
    // add a click handler to the specified element
    $('#all_slide_hide').click(function() {
        // show all of the specified elements
        $('.slide_contents').hide('fast');        
    });
    
    // use jquery to add tracking code to all .pdf files using the path name
    // for all a tags that have an href attribute that ends in .pdf, 
    // add the onclick attribute with pagetracking code
    $("a[href$='.pdf']").attr('onclick', function() {return "javascript: pageTracker._trackPageview(\'pdf" + this.pathname + "\'); " });
    
    $('#all_finals').click(function() {
        $('.toggle').toggleClass('offstate-a');
        $('.toggle').toggleClass('offstate-b');
    });
    
    // add title text to the specified element
    $('.slide_link').attr({title: "click to expand"});
});

function toggle(id) {
    var elementId = document.getElementById(id);
    if (elementId.style.display != 'none') {
        elementId.style.display = 'none';
    } else {
        elementId.style.display = '';
    }
}

/*
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
*/

/*
 * menu.js code taken from a Web tutorial by Joseph De Araujo.
 * http://www.interspire.com/content/articles/10/1/Building-An-Expanding-DHTML-Menu-With-CSS-and-JavaScript
 * Thank you!
 */

menu_status = new Array();

function showHide(theid)
{
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);

        if(menu_status[theid] != 'onstate-a') {
           switch_id.className = 'onstate-a';
           menu_status[theid] = 'onstate-a';
        }else{
           switch_id.className = 'offstate-a';
           menu_status[theid] = 'offstate-a';
        }
    }
}

/*
 * menu_status2 written by CSU Staff by modifying menu_status to work with drop-down select elements.
 */

menu_status2 = new Array();

function showHide2(dropdown)
{

    var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value

    if (document.getElementById) {
    var switch_id = document.getElementById(SelValue);

        if(menu_status2[SelValue] != 'onstate-a') {
           switch_id.className = 'onstate-a';
           menu_status2[SelValue] = 'onstate-a';
        }else{
           switch_id.className = 'offstate-a';
           menu_status2[SelValue] = 'offstate-a';
        }
    }
}
