// hoopshoot.js	Elks Hoop Shoot JavaScript functions
jQuery.noConflict();


jQuery(document).ready(
function() {
	jQuery('#accordionNav').accordion({
		autoHeight:false,
		navigation:true,
		navigationFilter:
			function() {
				/*	Fixed filter for dealing with root directories	*/
				if(location.hash == '' && location.href.indexOf('.cfm') == -1) {
					return this.href == window.location + 'default.cfm';
				} else {
	      	return this.href.toLowerCase() == location.href.toLowerCase();
				}		
			},
		header: "a.navHeader"
		});

		if(scriptQuerystring() == 'news') {
			fetchFeaturedNews();
		}

		roundCorners();
		//activateAccordion();
	});

function scriptQuerystring() {
	var bodyTag = document.getElementsByTagName('body')[0].getAttribute('rel');
	return bodyTag;
}

function createMap() {
	if($('mapContainer')) {
		$('mapContainer').update('<img src="/images/spinner.gif"> Loading State Associations map...');
			var url = '../includes/incUSMap.cfm';
	
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) { $('mapContainer').update(trim(transport.responseText)); }});
	}
}

function roundCorners() {
	if(!jQuery.browser.msie) { jQuery('#content').corners('10px top'); }
	jQuery('.sidebar').corners('5px top-left bottom-left');
}

		jQuery(window).bind("load", function() {
			if(jQuery('div#slider1').length > 0) {
			jQuery("div#slider1").codaSlider()
			  var autoSlide = setInterval(function()
			  {
				if(window.scroll) { jQuery("#right-link").click(); }
				}, 6000);
			}
		if(jQuery.browser.msie) { jQuery('.stripViewer').height(140); }
		});

function toggleSlider() {
	if(window.scroll == true) {
		jQuery('#panelCounter').text(jQuery('#panelCounter').text() + ' [Paused]');
		window.scroll = false;
	} else {
		jQuery('#panelCounter').text(jQuery('#panelCounter').text());
		window.scroll = true;
	}
}

function validateForm() {
/*	Quick form validation	*/
	var textBox = document.getElementById('Name');
	if(textBox.value == null || textBox.value == "") {
			alert('Please supply your name.');
			return false;
	}

	var textBox = document.getElementById('Email');
	if(textBox.value == null || textBox.value == "") {
			alert('Please supply your email address.');
			return false;
	}

	var textBox = document.getElementById('ContestYear');
	if(textBox.value == null || textBox.value == "") {
			alert('Please specify your contest year.');
			return false;
	}

	if(document.getElementById('ContestLevel')[document.getElementById('ContestLevel').selectedIndex].value == '-') {
		alert('Please specify your contest level.');
		return false;
	}

	if(document.getElementById('Age')[document.getElementById('Age').selectedIndex].value == '-') {
		alert('Please specify your age.');
		return false;
	}

	var textBox = document.getElementById('Story');
	if(textBox.value == null || textBox.value == "") {
			alert('Please tell your story.');
			return false;
	}
}

function fetchFeaturedNews() {
	/*	Gets a JSON object of featured news via AJAX	*/
	window.scroll = false;
	jQuery.getJSON("featured.cfm", function(data){
		for(var x = 0; x < 4; x++) {
			/*	Check for pics with the story	*/
			if(data.data.featuredimageurl[x].length != 0) {
				var imgCode = '<img src="' + data.data.featuredimageurl[x] + '" class="left" />';
			} else {
				var imgCode = '';
			}

			jQuery('#panel' + (x + 1)).html('<div class="wrapper">' + imgCode + '<h1>' + data.data.news_headline[x] + '</h1><p>' + data.data.news_introduction[x] + '</p><p><a href="story.cfm?StoryID=' + data.data.news_id[x].toString() + '">Read more...</a></p></div>');
		}
	});
	window.scroll = true;
}

function createNewsPanel() {
	/*	Create a news panel for inside the news Coda slider	*/
}

function trim(str) {
	/*	Generic regular expression to trim whitespace from a string	*/
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}