window.addEvent('domready', function() {

	// Retrieve all of the UL elements that reside directly inside the accordion DIV
	// and subsequently retrieve all of the list items which reside inside the 
	// first UL element
	var aList = $('accordion').getElements('ul');
	var aListItems = aList[0].getChildren('li');

	// Iterate through the list items inside the first UL element and assign
	// the correct classes to them and manipulate the anchor elements accordingly
	for (var i = 0; i < aListItems.length; i++) {
		
		// Retrieve all of the UL elements inside the current list item
		// and if there are more than zero, remove the href attribute for the
		// current item and set its class to "toggler" as it has a sub-level beneath it
		var aSubmenu = aListItems[i].getChildren('ul');
		if (aSubmenu.length > 0) {
			var aAnchor = aListItems[i].getElements('a');
			aListItems[i].className = "toggler";

			// Iterate through the UL elements of the current list item and
			// set their classes to "element" to let the accordion know that 
			// these are the UL elements which should slide in and out
			for (n = 0; n < aSubmenu.length; n++) {
				aSubmenu[n].className = "element";
			}
		} else {
			// If there are no UL elements inside the current list item, the
			// list item should maintain its href attribute and should be set
			// to the class "treenav_static" so it does not act like a toggler
			aListItems[i].className = "treenav_static";
		}
	}

});
