﻿// **** Page builds for "shows.aspx" *****
function buildSeason(s){
	var seasonPath = "resources/xml/bizkids_showseason" + s + ".xml";
	xml = loadXMLDoc(seasonPath);
	var theXpath = "/show/episode/@number";
	var builtUL = "<ul id='episodeList'>";
	if (window.ActiveXObject){ // ***code for IE***
		var nodes = xml.selectNodes(theXpath);
		for (i=0;i<=nodes.length-1;i++){
			builtUL = builtUL + "<li><div id='number'>" + nodes[i].childNodes[0].nodeValue + "</div> <a href='javascript:buildResources(" + nodes[i].childNodes[0].nodeValue + ");'>" + pullEpisodeTitleMS(nodes[i].childNodes[0].nodeValue) + "</a></span></li>";
		}
	} else if (document.implementation && document.implementation.createDocument){ //*** code for  Mozilla ***
		var nodes = xml.evaluate(theXpath , xml, null, XPathResult.ANY_TYPE, null);
		while(result=nodes.iterateNext()){
			builtUL = builtUL + "<li><div id='number'>" + result.childNodes[0].nodeValue + "</div> <a href='javascript:buildResources(" + result.childNodes[0].nodeValue + ");'>" + pullEpisodeTitleMOZ(result.childNodes[0].nodeValue) + "</a></span></li>";
		}
	}
	builtUL = builtUL + "</ul>";
	$("#generatedSeasonList").html(builtUL);
	$("#episodeList li a:first-child").children(0).addClass("highlightLIA");
	$("#episodeList li a:first-child").children(0).addClass("highlightA");
	$("#episodeList li:first-child").children(0).parent().addClass("highlightLI");
	buildResources($(builtUL).find("div#number:first").text()); //Load the first episode of the season when user switched season.
}
function buildResources(e){
	var e = e.toString();
	var seasonPath = "resources/xml/bizkids_showseason" + e.charAt(0) + ".xml";
	xml = loadXMLDoc(seasonPath);
	var setPath = "/show/episode[@number='" + e + "']/relatedcontent/file/@link";
	var theXpath = setPath;
	var builtUL = "<ul id='resourceList'>";
	if (window.ActiveXObject){ // ***code for IE***
		var nodes = xml.selectNodes(theXpath);
		for (i=0;i<=nodes.length-1;i++){
			builtUL = builtUL + "<li><a href='" + curriculumpath + nodes[i].childNodes[0].nodeValue + "' target='_blank'>" + pullResourceTitleMS(nodes[i].childNodes[0].nodeValue) + "</a><br />" + pullResourceDescriptionMS(nodes[i].childNodes[0].nodeValue) + "</li>";
		}
		buildHeaderMS(e);
	} else if (document.implementation && document.implementation.createDocument){ //*** code for  Mozilla ***
		var nodes = xml.evaluate(theXpath , xml, null, XPathResult.ANY_TYPE, null);
		while(result=nodes.iterateNext()){
			builtUL = builtUL + "<li><a href='" + curriculumpath + result.childNodes[0].nodeValue + "' target='_blank'>" + pullResourceTitleMOZ(result.childNodes[0].nodeValue) + "</a><br />" + pullResourceDescriptionMOZ(result.childNodes[0].nodeValue) + "</li>";
		}
		buildHeaderMOZ(e);
	}
	builtUL = builtUL + "</ul>";
	$("#generatedResourceList").html(builtUL);
//	if (killThis(e) = 1){$("#generatedResourceList").html(builtUL);}
	setEvents();
}

// **** KILL THIS ****
function buildHeaderMS(e){ //*** code for  IE ***
	var title = xml.selectSingleNode("/show/episode[@number='" + e + "']/title");
	$("#headerText").html("Episode #" + e + ": " + title.text);
}
function buildHeaderMOZ(e){ //*** code for  Mozilla ***
	var title = xml.evaluate("/show/episode[@number='" + e + "']/title", xml, null, XPathResult.STRING_TYPE, null);
	$("#headerText").html("Episode #" + e + ": " + title.stringValue);
}

// **** Support Functions to the Builds ****
function buildHeaderMS(e){ //*** code for  IE ***
	var title = xml.selectSingleNode("/show/episode[@number='" + e + "']/title");
	$("#headerText").html("Episode #" + e + ": " + title.text);
}
function buildHeaderMOZ(e){ //*** code for  Mozilla ***
	var title = xml.evaluate("/show/episode[@number='" + e + "']/title", xml, null, XPathResult.STRING_TYPE, null);
	$("#headerText").html("Episode #" + e + ": " + title.stringValue);
}


function pullResourceTitleMS(link){ //*** code for  IE ***
	var title = xml.selectSingleNode("/show/episode/relatedcontent/file[@link='" + link+ "']/@title");
	return title.text;
}
function pullResourceDescriptionMS(link){ //*** code for  IE ***
	var description = xml.selectSingleNode("/show/episode/relatedcontent/file[@link='" + link+ "']/@description");
	return description.text;
}
function pullResourceTitleMOZ(link){ //*** code for  Mozilla ***
	var title = xml.evaluate("/show/episode/relatedcontent/file[@link='" + link+ "']/@title", xml, null, XPathResult.STRING_TYPE, null);
	return title.stringValue;
}
function pullResourceDescriptionMOZ(link){ //*** code for  Mozilla ***
	var description = xml.evaluate("/show/episode/relatedcontent/file[@link='" + link+ "']/@description", xml, null, XPathResult.STRING_TYPE, null);
	return description.stringValue;
}
function pullEpisodeTitleMS(id){ // ***code for IE***
	var titleNode = xml.selectSingleNode("/show/episode[@number=" + id + "]/title");
	return titleNode.text;
}
function pullEpisodeTitleMOZ(id){ //*** code for  Mozilla ***
	var titleNode = xml.evaluate("/show/episode[@number=" + id + "]/title", xml, null, XPathResult.STRING_TYPE, null);
	return titleNode.stringValue;
}