window.onload = function() {
	if (document.getElementsByClassName) {
		if (document.getElementsByClassName('accToggler') && document.getElementsByClassName('accContent')) {
			var accordionTogglers = document.getElementsByClassName('accToggler');
			accordionTogglers.each(
				function(toggler){
					toggler.origColor = toggler.getStyle('background-color');//remember the original color
					toggler.fx = new Fx.Color(toggler, 'background-color');//set the effect
				}
			);

			var accordionContents = document.getElementsByClassName('accContent');
			var accordion = new Fx.Accordion( 
				accordionTogglers,
				accordionContents
			);
		}
	}
	hideSubCategories();
	addShowCategoryEvents();
}

function addEvent(obj,type,fn ) {
	if ( obj.attachEvent ) {
    	obj['e'+type+fn] = fn;
    	obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    	obj.attachEvent( 'on'+type, obj[type+fn] );
  	} else
    	obj.addEventListener( type, fn, false );
}

function hideSubCategories() {
	// Grabs sub-select elements and hides them, if no JS enabled sub selects will show
	if (document.getElementById("AirShowsBoxSub") && document.getElementById("PerformersSub") && document.getElementById("SupportServicesSub")) {
		document.getElementById("AirShowsBoxSub").style.display = "none";
		document.getElementById("PerformersSub").style.display = "none";
		document.getElementById("SupportServicesSub").style.display = "none";
	}
}

function addShowCategoryEvents() {
	if (document.getElementById("AirShowsBox") && document.getElementById("Performers") && document.getElementById("SupportServices")) {
		addEvent(document.getElementById("AirShowsBox"),'click',toggleSubSelect);
		addEvent(document.getElementById("Performers"),'click',toggleSubSelect);
		addEvent(document.getElementById("SupportServices"),'click',toggleSubSelect);

	}
}

function toggleSubSelect() {
	var id = this.id;
	id = id +'Sub';
	if (this.checked) 
		document.getElementById(id).style.display="block";
	else
		document.getElementById(id).style.display="none";
	
}
