var activeSelection = ""; //ID of the active selection
var activeCategory = ""; //ID of the active category
var buttonArray = new Array();

function LA_swapImgRestore(itemID) {
    if (itemID != activeSelection) {
        var imageRef = document.getElementById(itemID);
        imageRef.src = "../images/" + itemID + "_btn_off.jpg";
    }
}
function LA_swapImage(itemID) {
    if (itemID != activeSelection) {
        var imageRef = document.getElementById(itemID);
        imageRef.src = "../images/" + itemID + "_btn_on.jpg";
    }
}
function LA_swapImgRestore2(itemID) {
    if (itemID != activeCategory) {
        var imageRef = document.getElementById(itemID);
        imageRef.src = "../images/" + itemID + "_btn_off.jpg";
    }
}
function LA_swapImage2(itemID) {
    if (itemID != activeCategory) {
        var imageRef = document.getElementById(itemID);
        imageRef.src = "../images/" + itemID + "_btn_on.jpg";
    }
}
function buttonChange(itemID, identifier) {
    var imageRef = document.getElementById(itemID);
    var arrayLength = buttonArray.length;
    for (i = 0; i < arrayLength; i++) {
        buttonArray[i].src = "../images/" + buttonArray[i].id + "_btn_off.jpg";
    }
    activeSelection = itemID;
    if (itemID != "full") imageRef.src = "../images/" + itemID + "_btn_on.jpg";
    window.open("index_desc.html", "descriptionPage");
}
function sectionButtonChange(section)
{
	var url = parent.window.location.toString();
	
	if (url.indexOf("&section=") > -1)
	{
		url = url.substring(0, url.indexOf("&section="));
	}
	
	url = url + "&section=" + section;
	
	parent.window.location = url;
}

function OpenResource(URL, VideoName)
{
	window.open("../../indexVariable.html?asset=" + URL + "&footer=footer.swf","","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=500,height=575,left=0,top=0");
}

function OpenFooterAsset(URL)
{
	window.open(URL,"Spectrum_Information","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=750,height=550,left=0,top=0");
}

function openAudio(audio)
{
	var audioWin = window.open(audio, "audioWindow");
	audioWin.focus();
}

function embedAudioObject(audio)
{
	audio = "../" + audio;
	
	var height = 180;
	var width = 240;
	
	document.write("<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='" + width + "' height='" + height + "' codebase='http://www.apple.com/qtactivex/qtplugin.cab'>");
		document.write("<param name='src' value='" + audio +"' />");
		document.write("<param name='controller' value='true' />");
		document.write("<param name='autoplay' value='true' />");
		document.write("<param name='enablejavascript' value='true' />");
		document.write("<param name='scale' value='aspect' />");
		document.write("<param name='kioskmode' value='true' />");
		document.write("<param name='bgcolor' value='#FFFFFF' />");
			
		document.write("<embed ");
			document.write("src='" + audio + "'");
			document.write("width='" + width + "'");
			document.write("height='" + height + "'");
			document.write("autoplay='true'");
			document.write("scale='aspect'");
			document.write("kioskmode='true'");
			document.write("bgcolor='#FFFFFF'");
			document.write("type='video/quicktime'");
			document.write("pluginspage='http://www.apple.com/quicktime/download/'");
			document.write("enablejavascript='true'");
			document.write("controller='true'");
		document.write("></embed>");
	document.write("</object>");
}

function embedQuicktimeObject(movie)
{
	if (movie.indexOf(".jpg") == -1)
	{
	    movie = "../" + movie.replace(".mov", ".smil").toLowerCase();

	    if (movie.indexOf("intro") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/IntroBCC.mov";
	    if (movie.indexOf("video/pro_create") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Pro_CreateBCC.mov";
	    if (movie.indexOf("video/pro_evaluate") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Pro_EvaluateBCC.mov";
	    if (movie.indexOf("video/pro_explore") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Pro_ExploreBCC.mov";
	    if (movie.indexOf("video/superpro_create") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/SuperPro_CreateBCC.mov";
	    if (movie.indexOf("video/superpro_evaluate") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/SuperPro_EvaluateBCC.mov";
	    if (movie.indexOf("video/superpro_explore") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/SuperPro_ExploreBCC.mov";
        if (movie.indexOf("video/turbo_create") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Turbo_CreateBCC.mov";
        if (movie.indexOf("video/turbo_evaluate") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Turbo_EvaluateBCC.mov";
        if (movie.indexOf("video/turbo_explore") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/Turbo_ExploreBCC.mov";
        if (movie.indexOf("video/ultraturbo_create") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/UltraTurbo_CreateBCC.mov";
        if (movie.indexOf("video/ultraturbo_evaluate") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/UltraTurbo_EvaluateBCC.mov";
        if (movie.indexOf("video/ultraturbo_explore") > -1) movie = "StreamedMovie.mov?Cdn.Rewrite=1&Cdn.RewritePath=/english_language_arts_building_and_celebrating_community/UltraTurbo_ExploreBCC.mov";
	}
	
	document.write("<object id='spectrumMovie' name='spectrumMovie' classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='500' height='400' codebase='http://www.apple.com/qtactivex/qtplugin.cab'>");
		document.write("<param name='src' value='" + movie +"' />");
		
		if (movie.indexOf(".jpg") == -1)
		{
			document.write("<param name='controller' value='true' />");
		}
		else
		{
			document.write("<param name='controller' value='false' />");
		}
		
		document.write("<param name='autoplay' value='true' />");
		document.write("<param name='enablejavascript' value='true' />");
		document.write("<param name='scale' value='aspect' />");
		document.write("<param name='kioskmode' value='true' />");
		document.write("<param name='bgcolor' value='#FFFFFF' />");
			
		document.write("<embed ");
			document.write("id='spectrumMovie'");
			document.write("name='spectrumMovie'");
			document.write("src='" + movie + "'");
			document.write("width='500'");
			document.write("height='400'");
			document.write("autoplay='true'");
			document.write("scale='aspect'");
			document.write("kioskmode='true'");
			document.write("bgcolor='#FFFFFF'");
			document.write("type='video/quicktime'");
			document.write("pluginspage='http://www.apple.com/quicktime/download/'");
			document.write("enablejavascript='true'");
			if (movie.indexOf(".jpg") == -1)
			{
				document.write("controller='true'");
			}
			else
			{
				document.write("controller='false'");	
			}
		document.write("></embed>");
			
	document.write("</object>");
}

function arraySorter(whichArray, whichField)
{
	// whichArray: {name:value, name:value, ..... }
	// whichField: String -- One of the names in whichArray to sort by.
	var temp = [];
	
	for (var i = 0; i < whichArray.length; i++) 
	{
		temp.push([whichArray[i][whichField], whichArray[i]]);
	}
	
	temp.sort();
	
	for (var i = 0; i < temp.length; i++) 
	{
		whichArray[i] = temp[i][1];
	}
}
