/*


Thanks Quirksmode!
http://www.quirksmode.org/js/blockinvi.html

	Sections are defined by the innerHTML of the a's in the #toggleNav

	Example:
	<ul id="toggleNav">
		<li><a href="#sectionName"></li>
	</ul>
*/


// Show only one of the sections on load
function show(){

	// Hide all of the sections
	var nav = document.getElementById('toggleNav');
	var as = nav.getElementsByTagName('a');


	// Put the regular expression into an array
	var toggleArray = new Array(as.length);
	for(i = 0; i < as.length; i++){
		toggleArray[i] = as[i].href.match(/#(\w.+)/)[1];
	}

	// Gets the value of this toggled
	//var toggleMe = nr.href.match(/#(\w.+)/)[1];

	var url = location.href;
	var iAtPound = url.indexOf("#");
	var sQueryString = "";

	if (iAtPound != -1) {
		sQueryString = url.substring(iAtPound+1, url.length);
	} else {
		sQueryString = toggleArray[0];
	}


	// Show the correct section
	if (document.layers){
//		document.layers[toggleArray[0]].display = 'block';
		document.layers[sQueryString].display = 'block';
	}

	else if (document.all){
//		document.all[toggleArray[0]].style.display = 'block';
		document.all[sQueryString].style.display = 'block';
	}

	if (document.getElementById){
//		document.getElementById(toggleArray[0]).style.display = 'block';
		document.getElementById(sQueryString).style.display = 'block';
	}

	//alert("sQueryString = " + sQueryString);
	//setActive(sQueryString);
	setActive(location.href);
	//toggle(sQueryString);

}




// This function is used to toggle the visibility of sections of the Events and Events Schedule pages
function toggle(nr){

	//alert("Toggle: nr = " + nr);

	var nav = document.getElementById('toggleNav');
	var as = nav.getElementsByTagName('a');

	// Put the "active" class on the clicked <a>
	setActive(nr);

	// Put the regular expression into an array
	var toggleArray = new Array(as.length);
	for(i = 0; i < as.length; i++){
		toggleArray[i] = as[i].href.match(/#(\w.+)/)[1];
	}


	// Gets the value of this toggled
	var toggleMe = nr.href.match(/#(\w.+)/)[1];


	if (document.layers){
		for(i = 0; i < as.length; i++){
			document.layers[toggleArray[i]].display = 'none';
		};
		//current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[toggleMe].display = 'block';
	}

	else if (document.all){
		for(i = 0; i < as.length; i++){
			document.all[toggleArray[i]].style.display = 'none';
		}
		//current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[toggleMe].style.display = 'block';
	}

	if (document.getElementById){
		for(i = 0; i < as.length; i++){
			document.getElementById(toggleArray[i]).style.display = 'none';
		}
		//vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(toggleMe).style.display = 'block';
	}

}


// Sets the #toggleNav tab to active
function setActive(activateMe){

	//alert('activateMe = ' + activateMe); // activateMe = http://pluto/AllstarProductions/event_schedule.asp#Ho13


	var nav = document.getElementById('toggleNav');
	var as = nav.getElementsByTagName('a');

	for(i = 0; i < as.length; i++){

		// If the link is the right one, activate it
		if(as[i].href == activateMe){
			as[i].className = 'active';

		// For event_schedule.asp: It's the root, without a suffix (ie: filename.asp#sportName)
		} else if (location.href.substring(location.href.indexOf('.') + 1, activateMe.length) == 'asp'){
			as[0].className = 'active';

		// For event_details.asp: It's the root (ie: filename.asp)
		} else if (location.href.indexOf('?') != '-1' && activateMe == location.href){
			as[0].className = 'active';

		// Hide all the other ones
		} else {
			as[i].className = '';
		}
	}
}


// Attach toggle function
function init(){

	if(document.getElementById && document.createTextNode){
		var nav = document.getElementById('toggleNav');
		var as = nav.getElementsByTagName('a');

		for(i = 0; i < as.length; i++){

			// Attach toggle function to #toggleNav
			as[i].onclick=function(){toggle(this);return false}
		}



		var nav1 = document.getElementById('dropNav');
		var as1 = nav1.getElementsByTagName('a');

		for(i = 0; i < as1.length; i++){

			// Attach toggle function to #dropNav
			as1[i].onclick=function(){toggle(this);return false}
		}

	}

}
