var current_sport;
var current_slide = 0;

jQuery.noConflict();
jQuery(document).ready(function($){
																
// rh 101309
var dirName;
	$.ajax({
		   url: "mysite/code/mediaxml_folders.php",
		   dataType: ($.browser.msie) ? "text" : "php",
		   success: function(xml) {
				  
			  var newXML = parseXml(xml);
					//find the node called dir in our xml
					$(newXML).find("dir").each(function() {
						// for each dir found, find the name of the directory
						dirName = $(this).attr("name")
						// create a div for each dir
						var dirWrap = "\n<div id=\"" + dirName + "\">\n"
						// NAVIGATION define a variable to hold the html for a list of nav items
						var imgDirNav = "<li onclick=\"selectDir('" + dirName + "')\" id=\"nav_" + dirName + "\" class=\"nav_items\"><span>" + dirName + "</span></li>"
						
						// put the list items in the unordered list with an id of imgDirNav
						$("#imgDirNav").append(imgDirNav);
						// writes the imgLink variable to the div with an id
						$("#naca_box_content").append(dirWrap);
						// while we're in this dir, find the "file" node and do something for each that we find
						$(this).find("file").each(function() {
							// define the variable imgName to the value of the "name" attribute of the "file" node
							var imgName = $(this).attr("name")
							// take imgName and trim away excess characters and use as an image title description
							var imgTitle = imgName.replace(/_/g, " ");
							imgTitle = imgTitle.replace(/(.jpg$)/, "");
							// define the variable imgLink to include the html needed for each image instance
							var imgLinkHtml = "<div class=\"nacaImgContain\">\n<img src=\"themes/naca/images/naca_sports/"+ dirName + "/" + imgName + "\" class=\"nacaImg\" />\n</div>\n"

							// add our imgLinkHtml variable to the end of dirWrap
							$("#" + dirName).append(imgLinkHtml);
							
							// hide all but video on load
							$("#video").show();
	  						$("#soccer, #basketball, #football, #volleyball").hide();
							
						
						}); // end the for each file node loop
					}); // .newXml stuff
				}
			}); // .ajax
	
	// youtube
	$(".videoOnButton").click(function () {
    	$("#imgnav").hide();
		$("#video").show();
	});
  	$("#imgnav").hide();
	// end youtube

	/* JH next/previous */
	$('#imgnav span').click(function() {
		var nextSlide;
		var slideCount = $('#naca_box_content').find('div[id="' + current_sport + '"]').find('.nacaImgContain').length;
		$('#naca_box_content').find('div[id="' + current_sport + '"]').find('.nacaImgContain').hide();
		switch ($(this).text()) {
			case 'PREVIOUS':
					if (current_slide==0) {
						current_slide = slideCount-1;
					} else {
						current_slide--;
					}
					$('#naca_box_content').find('div[id="' + current_sport + '"]').find('.nacaImgContain').eq(current_slide).show();
				break;
			case 'NEXT':
					if (current_slide==slideCount-1) {
						current_slide = 0;
					} else {
						current_slide++;
					}
					$('#naca_box_content').find('div[id="' + current_sport + '"]').find('.nacaImgContain').eq(current_slide).show();
				break;
		}
	});
	
}); // ready

// part of the xml parsing stuff
function parseXml(xml) {
    if (jQuery.browser.msie) {
	  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.loadXML(xml);
	  xml = xmlDoc;
    }
    return xml;
}

// switches for nav items and showing / hiding imgnav
function selectDir(x) {
	current_sport = x;
	current_slide = 0;
	$('#naca_box_content').find('div[id="' + current_sport + '"]').find('.nacaImgContain').eq(current_slide).show();
	switch (x)
	{
	  case "video":
	  	$("#video").show();
	  	$("#soccer, #basketball, #football, #volleyball").hide();
			$("#imgnav").hide();
			break;
	  case "volleyball":
	  	$("#volleyball").show();
			$("#soccer , #basketball , #football , #video").hide();
			$("#imgnav").show();
	  	break;
	  case "soccer":
	  	$("#soccer").show();
			$("#volleyball, #basketball, #football, #video").hide();
			$("#imgnav").show();
	  	break;
	  case "basketball":
	  	$("#basketball").show();
			$("#volleyball, #soccer, #football, #video").hide();
			$("#imgnav").show();
	  	break;
	  case "football":
			$("#football").show();
			$("#volleyball, #basketball, #soccer, #video").hide();
			$("#imgnav").show();
	 		break;
	  default:
	  	$("#video").show();
	  	$("#soccer, #basketball, #football, #volleyball").hide();
	}
}


<!-- you tube embed script -->

    var params = { allowScriptAccess: "always" };
    var atts = { id: "nacaVideo" };
    swfobject.embedSWF("http://www.youtube.com/v/Io4HSpOkFGY?border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer", "viewerPane", "420", "330", "8", null, null, params, atts);

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("nacaVideo");
}
function dunkVideo(){
	$("#soccer, #basketball, #football, #volleyball").hide();
	ytplayer.loadVideoByUrl("http://www.youtube.com/v/Io4HSpOkFGY", 0);
}
function footballVideo(){
	$("#soccer, #basketball, #football, #volleyball").hide();
	ytplayer.loadVideoByUrl("http://www.youtube.com/v/gjzRw6CHf_g", 0);
}

