// JavaScript Document

function popitup(url, width, height) {
	var newwindow = window.open(url,'name','height=' + height + ',width=' + width + ',scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}    

//////////////////////////////////////////////////////////////////////////////////////////////////// XML HANDLERS ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// BUILD CATEGORIES //////////////////// 

//// MASTER VARIABLES

var strMasterHDFile;
var strMasterLDFile;
var strMasterImage;
var iAutoStart;

function splitCategoryItem(itemxml) {
	var properties = new Array("categoryID", "title", "description", "sortOrder", "resources", "intro");
	var tmpElement = null;
	for (var i=0; i<properties.length; i++) {
		tmpElement = itemxml.getElementsByTagName(properties[i])[0];
		if (tmpElement != null)
			if (properties[i]=='resources') {
				eval("this."+properties[i]+"=tmpElement");				
			} else {
				eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
			}
	}
}

function splitResourceItem(resourceXML) {
	var properties = new Array("title", "link", "type");

	var tmpElement = null;
	for (var i=0; i<properties.length; i++) {
		tmpElement = resourceXML.getElementsByTagName(properties[i])[0];
		if (tmpElement != null)
				eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}
}

function splitCategoryChannels(categoryXML) {
	this.items = new Array();

	var itemElements = categoryXML.getElementsByTagName("category");

	for (var i=0; i<itemElements.length; i++) {
		Item = new splitCategoryItem(itemElements[i]);
		this.items.push(Item);
	}
}

function splitResourceChannels(resourceXML) {
	this.resourceList = new Array();
	var itemReourcesElements = resourceXML.getElementsByTagName("resource");
	for (var i=0; i<itemReourcesElements.length; i++) {
		thisResource = new splitResourceItem(itemReourcesElements[i]);
		this.resourceList.push(thisResource);
	}
}

function getCategories() {
	if (window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else
		alert("not supported");

	xhr.open("GET","xml/categories.xml",true);
	xhr.setRequestHeader("Cache-Control", "no-cache");
	xhr.setRequestHeader("Pragma", "no-cache");
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				if (xhr.responseText != null) {
					processCategories(xhr.responseXML);
				} else {
					alert("Failed to receive RSS file from the server - file not found.");
					return false;
				}
			} else {
				alert("Error code " + xhr.status + " received: " + xhr.statusText);
			}
		}
	}
	xhr.send(null);
}

function processCategories(categoriesXML) {
	categoryArray = new splitCategoryChannels(categoriesXML);
	showCategories(categoryArray);
}

function processResources(resourcesXML) {
	resourcesArray = new splitResourceChannels(resourcesXML);
	showResources(resourcesArray);
}

function showCategories(categoryArray) {
	// GET SELECTED CATEGORY
	var intCategoryID
		intCategoryID = gup('categoryID');

	var strMenuStart = "<ul class='mainMenuItems'>";
	var strMenuEnd = "</ul>";	

	var startCategoryTag = "<li><div><span class='mainMenu'><a href='categoryDetail.html?categoryID=";
	var startCategoryTagOn = "<li><div class='current'><span class='mainMenu'><a href='categoryDetail.html?categoryID=";	
	var middleCategoryTag = "'>";
	var endCategoryTag = "</a></span></div></li>";	
	
	var strMenuBuild = ""
	
	var strDescription
	var strTitle
	var strResourcesTitle
	
	document.getElementById("mainNavigation").innerHTML = ""
	for (var i=0; i<categoryArray.items.length; i++) {
		if (intCategoryID==categoryArray.items[i].categoryID) {
			// SET TITLE AND DESCRIPTION 
			strTitle = categoryArray.items[i].title;
			document.getElementById("categoryTitle").innerHTML = strTitle			
			strDescription = categoryArray.items[i].description
			document.getElementById("categoryDescription").innerHTML = strDescription
			
			//SET TOP RESOURCE TITLE
			strResourcesTitle = "Videos on " + strTitle;
			document.getElementById("topResourceTitle").innerHTML = strResourcesTitle;
			
			// SET RESOURCES TITLE
			strResourcesTitle = "Additional Resources";
			document.getElementById("resourceTitle").innerHTML = strResourcesTitle;
			processResources(categoryArray.items[i].resources);
		} 
		if (intCategoryID==categoryArray.items[i].categoryID) {
			category_html = (categoryArray.items[i].title == null) ? "" : startCategoryTagOn + categoryArray.items[i].categoryID + middleCategoryTag + categoryArray.items[i].title + endCategoryTag;			
		} else {
			category_html = (categoryArray.items[i].title == null) ? "" : startCategoryTag + categoryArray.items[i].categoryID + middleCategoryTag + categoryArray.items[i].title + endCategoryTag;
		}
		strMenuBuild += category_html;
	}
	document.getElementById("mainNavigation").innerHTML = strMenuStart + strMenuBuild + strMenuEnd;	
	
	// GET VIDEO CONTENT //
	getVideos();
	
	return true;
}

function showResources(resourceArray) {
	
	var strTitle
	var strLink
	var intType
	var strResourceList = "";

	for (var i=0; i<resourceArray.resourceList.length; i++) {
		strResourceList += "<tr><td colspan='2'><img src='images/clearPixel.gif' height='8' width='2'></td></tr>";				
		if (resourceArray.resourceList[i].type==1) {
			strResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceList[i].link + "' target='_blank' class='resourceLink'><img src='images/iconPaper.gif' width='15' height='18' border='0' class='imgPadding' />";
		} else if (resourceArray.resourceList[i].type==2) {
			strResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceList[i].link + "' target='_blank' class='resourceLink'><img src='images/iconPaper.gif' width='15' height='18' border='0' class='imgPadding' />";			
		} else {
			strResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceList[i].link + "' target='_blank' class='resourceLink'><img src='images/iconVideo.gif' width='15' height='18' border='0' class='imgPadding' />";			
		}
		strResourceList += "</td><td valign='top'><a href='" + resourceArray.resourceList[i].link + "' target='_blank' class='resourceLink'>" + resourceArray.resourceList[i].title + "</a></td></tr>";
	}
	
	document.getElementById("videoSTResourcesHolder").innerHTML = "<table cellpadding='0' cellspacing='0' width='280'>" + strResourceList + "</table>";	
	
	// GET VIDEO CONTENT //
	getVideos();
	
	return true;
}

var xhr;

//////////////////////////////////////////////////////////////////////////////////////////////////// GET VIDEDOS CONTENT ////////////////////////////////////////////////////////////////////////////////////////////////////

//// VIDEO XML VAR
var videoXMLObject;

//// VIDEO AND CATEGORY CHECKER VAR
var sCategoryID
var sVideoID

//// GET VIDEO XML FILE
function getVideos() {
	if (window.ActiveXObject)
		videoXMLObject = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		videoXMLObject = new XMLHttpRequest();
	else
		alert("not supported");

	//prepare the xmlhttprequest object
	videoXMLObject.open("GET","xml/videos.xml",true);
	videoXMLObject.setRequestHeader("Cache-Control", "no-cache");
	videoXMLObject.setRequestHeader("Pragma", "no-cache");
	videoXMLObject.onreadystatechange = function() {
		if (videoXMLObject.readyState == 4) {
			if (videoXMLObject.status == 200) {
				if (videoXMLObject.responseText != null) {
					processVideos(videoXMLObject.responseXML);
				} else {
					alert("Failed to receive RSS file from the server - file not found.");
					return false;
				}
			} else {
				alert("Error code " + videoXMLObject.status + " received: " + videoXMLObject.statusText);
			}
		}
	}
	//send the request
	videoXMLObject.send(null);
}

//// PROCESS VIDEO XML
function processVideos(videoXML) {
	videoFeed = new splitVideoXML(videoXML);
	showVideos(videoFeed);
}

//// BREAK OUT THE VARIABLES AND ADD TO ARRAY
function splitVideoXML(videoXML) {
	this.videos = new Array();
	var videoElements = videoXML.getElementsByTagName("video");
	for (var i=0; i<videoElements.length; i++) {
		
			
		newVideo = new parseVideoItem(videoElements[i]);
		this.videos.push(newVideo);
	}
}

//// STRIP VIDEO ASSETS
function parseVideoItem(itemxml) {
	var videoProperties = new Array("videoID","title","date","categoryID","description","intro","keywords","videoFileHD","videoFileLD","thumb","length","autoPlay","resources","contactName", "contactTitle","contactPhone","contactEmail");
	var tmpVideoElement = null;

	for (var k=0; k<videoProperties.length; k++) {
		tmpVideoElement = itemxml.getElementsByTagName(videoProperties[k])[0];
		if (tmpVideoElement != null) {
			if (videoProperties[k]=='resources') {
				eval("this."+videoProperties[k]+"=tmpVideoElement");				
			} else {
				eval("this."+videoProperties[k]+"=tmpVideoElement.childNodes[0].nodeValue");
			}
		}
	}
}

// SHOW VIDEOS 
function showVideos(videoFeed) {

	sCategoryID = gup('categoryID');	

	// SORT ARRAY ON DATE FOR TOP 5 VIDEOS
	if (sCategoryID=="") {
		var newDateSorted = new Array(sortDate(videoFeed.videos));	
	}
	
	var tempSortArray = new Array(videoFeed.videos.length);

	for (var i = 0; i < videoFeed.videos.length; i++) {
		tempSortArray[i] = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '];
	}

	for (var i=0; i<videoFeed.videos.length; i++) {	
		tempSortArray[i][0] = videoFeed.videos[i].videoID;
		tempSortArray[i][1] = videoFeed.videos[i].title;
		tempSortArray[i][2] = videoFeed.videos[i].date;
		tempSortArray[i][3] = videoFeed.videos[i].categoryID;
		tempSortArray[i][4] = videoFeed.videos[i].description;
		tempSortArray[i][5] = videoFeed.videos[i].intro;		
		tempSortArray[i][6] = videoFeed.videos[i].keywords;
		tempSortArray[i][7] = videoFeed.videos[i].videoFileHD;
		tempSortArray[i][8] = videoFeed.videos[i].videoFileLD;
		tempSortArray[i][9] = videoFeed.videos[i].thumb;	
		tempSortArray[i][10] = videoFeed.videos[i].length;
		tempSortArray[i][11] = videoFeed.videos[i].autoPlay;	
		tempSortArray[i][12] = videoFeed.videos[i].resources;			
		tempSortArray[i][13] = videoFeed.videos[i].contactName;
		tempSortArray[i][14] = videoFeed.videos[i].contactTitle;	
		tempSortArray[i][15] = videoFeed.videos[i].contactPhone;	
		tempSortArray[i][16] = videoFeed.videos[i].contactEmail;			
	}
	
	var strTopVideos = ""; 
	
// CHECK FOR CATEGORY AND VIDEO ID //
	sVideoID = gup('videoID');		
	
	if (sCategoryID>0) {
		intCount = tempSortArray.length;
		// SET TABLE TOP FOR THUMBS
		strTopVideos = "<table class='videoThumbTable'>";				
	} else {
		intCount = 3
	}

	var cFirstVideo
		cFirstVideo = 0;

	for (var i=0; i<intCount; i++) {
		if (sCategoryID>0) {
			document.getElementById("videoSThumbHolder").innerHTML = ""
			if (tempSortArray[i][3]==sCategoryID) {
				// SET THE DEFAULT VIDEO (NEWEST)
				if (cFirstVideo==1) {				
					strTopVideos += "<tr><td colspan='2'><img src='images/hLineDivider.gif' width='100%' height='2'></td></tr>";					
				}
				if (cFirstVideo==0 && sVideoID=="") {
					document.getElementById("selectedVideoTitle").innerHTML = tempSortArray[i][1];
					document.getElementById("selectedDescription").innerHTML = tempSortArray[i][4];		
					strMasterHDFile = tempSortArray[i][7];
					strMasterLDFile = tempSortArray[i][8];
					strMasterImage = tempSortArray[i][9];
					iAutoStart = tempSortArray[i][11];
					cFirstVideo = 1;
					// POPULATE VIDEO RESOURCE PANEL 
					document.getElementById("contactInfo").innerHTML = tempSortArray[i][13] + "<br>" + tempSortArray[i][14] + "<br>" + tempSortArray[i][15] + "<br><a href='mailto:" + tempSortArray[i][16] + "' class='txtWhite'>" + tempSortArray[i][16] + "</a>";
					// POPULATE AND STRIP RESOURCES 
					processVideoResources(tempSortArray[i][12]);					
					// SUB PAGES SELECTED OR PLAYING
					strTopVideos += "<tr><td colspan='2' align='left'><a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "' class='txtMediumGrey'>" + tempSortArray[i][1] + "</a></td></tr>"
					strTopVideos += "<tr><td valign='top'><div style='background:url(videoAssets/thumbnail/" + tempSortArray[i][9] + ") no-repeat top center; width: 144px; height:96px; overflow:hidden; display:block; margin: 0 0 2px 0; padding: 0px; float: left;'>";
					strTopVideos += "<a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "'><img src='images/videoThumbRoundCurrent.png' width='144' height='96' /></a></div></td><td class='txtGreySmall introTest' valign='top'>" + tempSortArray[i][5] + "<br><span class='txtOrange'>" + tempSortArray[i][10] +"<br></span>" + tempSortArray[i][2] + "</td></tr>";
				} else {
					if (sVideoID==tempSortArray[i][0]) {					
						document.getElementById("selectedVideoTitle").innerHTML = tempSortArray[i][1];
						document.getElementById("selectedDescription").innerHTML = tempSortArray[i][4];			
						strMasterHDFile = tempSortArray[i][7];
						strMasterLDFile = tempSortArray[i][8];
						strMasterImage = tempSortArray[i][9];						
						iAutoStart = tempSortArray[i][11];						
						// POPULATE VIDEO RESOURCE PANEL 
						document.getElementById("contactInfo").innerHTML = tempSortArray[i][13] + "<br>" + tempSortArray[i][14] + "<br>" + tempSortArray[i][15] + "<br><a href='mailto:" + tempSortArray[i][16] + "' class='txtWhite'>" + tempSortArray[i][16] + "</a>";
						// POPULATE AND STRIP RESOURCES 
						processVideoResources(tempSortArray[i][12]);											
						// SUB PAGES SELECTED OR PLAYING
						strTopVideos += "<tr><td colspan='2' align='left'><a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "' class='txtMediumGrey'>" + tempSortArray[i][1] + "</a></td></tr>"
						strTopVideos += "<tr><td valign='top'><div style='background:url(videoAssets/thumbnail/" + tempSortArray[i][9] + ") no-repeat top center; width: 144px; height:96px; overflow:hidden; display:block; margin: 0 0 2px 0; padding: 0px; float: left;'>";
						strTopVideos += "<a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "'><img src='images/videoThumbRoundCurrent.png' width='144' height='96' /></a></div></td><td class='txtGreySmall introTest' valign='top'>" + tempSortArray[i][5] + "<br><span class='txtOrange'>" + tempSortArray[i][10] +"</span><br>" + tempSortArray[i][2] + "</td></tr>";
					} else {
						// SUB PAGES NOT SELECTED
						strTopVideos += "<tr><td colspan='2' align='left'><a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "' class='txtMediumGrey'>" + tempSortArray[i][1] + "</a></td></tr>"
						strTopVideos += "<tr><td valign='top'><div style='background:url(videoAssets/thumbnail/" + tempSortArray[i][9] + ") no-repeat top center; width: 144px; height:96px; overflow:hidden; display:block; margin: 0 0 2px 0; padding: 0px; float: left;'>";
						strTopVideos += "<a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "'><img src='images/videoThumbRound.png' width='144' height='96' /></a></div></td><td class='txtGreySmall introTest' valign='top'>" + tempSortArray[i][5] + "<br><span class='txtOrange'>" + tempSortArray[i][10] +"</span><br>" + tempSortArray[i][2] + "</td></tr>";
					}
				}
			}
		} else {
			if (i==0) { 
				strTopVideos = "<img src='images/hTopInset.gif' width='160' height='8' /><br>";		
			}			
			if (cFirstVideo==0) {
				document.getElementById("selectedVideoTitle").innerHTML = tempSortArray[i][1];
				document.getElementById("selectedDescription").innerHTML = tempSortArray[i][4];		
				strMasterHDFile = tempSortArray[i][7];
				strMasterLDFile = tempSortArray[i][8];
				strMasterImage = tempSortArray[i][9];				
				iAutoStart = tempSortArray[i][11];				
				cFirstVideo = 1;

				// POPULATE VIDEO RESOURCE PANEL 
				document.getElementById("contactInfo").innerHTML = tempSortArray[i][13] + "<br>" + tempSortArray[i][14] + "<br><a href='mailto:" + tempSortArray[i][15] + "' class='txtWhite'>" + tempSortArray[i][15] + "</a>";
				// POPULATE AND STRIP RESOURCES 
				processVideoResources(tempSortArray[i][12]);	
				strTopVideos += "<div style='background:url(videoAssets/thumbnail/" + tempSortArray[i][9] + ") no-repeat top center; width: 144px; height:96px; overflow:hidden; display:block; margin: 0 0 2px 0; padding: 0px;'>";								
				strTopVideos += "<a class='showMePLZ' style='text-decoration:none;' href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "'><img src='images/videoThumbRound.png' width='144' height='96' name='firstVideo'/><div class='justatip'><b class='jatArrow'></b><b class='jatTop'></b><div class='jatM'>" + tempSortArray[i][5] + "</div><b class='jatBottom'></b><br clear='all' /></div></a></div>";				
			} else {
				strTopVideos += "<div style='background:url(videoAssets/thumbnail/" + tempSortArray[i][9] + ") no-repeat top center; width: 144px; height:96px; overflow:hidden; display:block; margin: 0 0 2px 0; padding: 0px;'>";				
				strTopVideos += "<a class='showMePLZ' style='text-decoration:none;' href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "'><img src='images/videoThumbRound.png' width='144' height='96'/><div class='justatip'><b class='jatArrow'></b><b class='jatTop'></b><div class='jatM'>" + tempSortArray[i][5] + "</div><b class='jatBottom'></b><br clear='all' /></div></a></div>";				
			}

			
			strTopVideos += "<a href='categoryDetail.html?categoryID=" + tempSortArray[i][3] + "&videoID=" + tempSortArray[i][0] + "' class='txtGrey'>" + tempSortArray[i][1] + "<br><span class='txtOrange'>" + tempSortArray[i][10] + "</span></a>";
			strTopVideos += "<br><img src='images/clearPixel.gif' width='1' height='8' />";
			
		}
		
		// CHECK FOR VIDEO ID
		if (sVideoID==tempSortArray[i][0]) {

		}

	}
	
	if (sCategoryID>0) {
		document.getElementById("videoSThumbHolder").innerHTML = strTopVideos + "</table>";
	} else {
//		strTopVideos += "<img src='images/hBottomInset.gif' width='160' height='8' /><br>";		
		document.getElementById("videoThumbHolder").innerHTML = strTopVideos;			
	}
	return true;
}


function splitVideoResourceChannels(resourceXML) {
	this.resourceVideoList = new Array();
	var itemReourcesElements = resourceXML.getElementsByTagName("resource");

	for (var i=0; i<itemReourcesElements.length; i++) {
		thisResource = new splitVideoResourceItem(itemReourcesElements[i]);
		this.resourceVideoList.push(thisResource);
	}

}

function splitVideoResourceItem(resourceXML) {
	var properties = new Array("title", "link", "type");

	var tmpElement = null;
	for (var i=0; i<properties.length; i++) {
		tmpElement = resourceXML.getElementsByTagName(properties[i])[0];
		if (tmpElement != null)
				eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}
}

function processVideoResources(resourcesXML) {
	resourcesVideoArray = new splitVideoResourceChannels(resourcesXML);
	showVideoResources(resourcesVideoArray);
}

function showVideoResources(resourceArray) {
	
	var strTitle
	var strLink
	var intType
	var strVideoResourceList = "";

	for (var i=0; i<resourceArray.resourceVideoList.length; i++) {
		strVideoResourceList += "<tr><td colspan='2'><img src='images/clearPixel.gif' height='4' width='2'></td></tr>";				
		if (resourceArray.resourceVideoList[i].type==1) {
			strVideoResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceVideoList[i].link + "' target='_blank' class='txtWhite'><img src='images/iconVideoPaper.gif' width='13' height='16' border='0' class='vRLImage' />";
		} else if (resourceArray.resourceVideoList[i].type==2) {
			strVideoResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceVideoList[i].link + "' target='_blank' class='txtWhite'><img src='images/iconVideoPaper.gif' width='13' height='16' border='0' class='vRLImage' />";			
		} else {
			strVideoResourceList += "<tr><td valign='top'><a href='" + resourceArray.resourceVideoList[i].link + "' target='_blank' class='txtWhite'><img src='images/iconVideoVideo.gif' width='13' height='16' border='0' class='vRLImage' />";			
		}
		strVideoResourceList += "</td><td valign='top'><a href='" + resourceArray.resourceVideoList[i].link + "' target='_blank' class='txtWhite'>" + resourceArray.resourceVideoList[i].title + "</a></td></tr>";
	}
	document.getElementById("resourceList").innerHTML = "<table cellpadding='0' cellspacing='0' width='286'>" + strVideoResourceList + "</table>";	
	
	return true;
}

//// FUNCTIONAL SORTING BUILDERS ////

Sign = new Array();
Sign["new"] = ">";
Sign["old"] = "<";

months=new Array("1","2","3","4","5","6","7","8","9","10","11","12");

function ConvertDate(DT){
	M = DT.substring(0,DT.indexOf("/"));
	D = DT.substring(DT.indexOf(" ")+1,DT.indexOf("/"));
	Y = DT.substring(DT.lastIndexOf("/")+1,DT.length);
	if (D.length == 1) {D = "0"+D;}
	for (l=0;l<12;l++) {
		if (months[l] == M) {M = l+1; break;}
	}
	if (M < 10) {M = "0"+M;}
	return Y+""+M+""+D;
}

var dateVideoIDSort = new Array();

function sortDate(sortArrayContent){
	
	var temp = new Array(sortArrayContent.length);	
	
	for (var i = 0; i < sortArrayContent.length; i++) {
		temp[i] = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '];
	}	
	
	for (z=0;z<sortArrayContent.length-1;z++) {
		for (y=0;y<(sortArrayContent.length-(z+1));y++) {
			if (eval(ConvertDate(sortArrayContent[y+1].date)+ Sign['new'] +ConvertDate(sortArrayContent[y].date))) {
				// PULL CONTENT INTO TEMP ARRAY FOR SORTING
				temp[y][0] = sortArrayContent[y+1].videoID;
				temp[y][1] = sortArrayContent[y+1].title;
				temp[y][2] = sortArrayContent[y+1].date;
				temp[y][3] = sortArrayContent[y+1].categoryID;
				temp[y][4] = sortArrayContent[y+1].description;
				temp[y][5] = sortArrayContent[y+1].intro;		
				temp[y][6] = sortArrayContent[y+1].keywords;
				temp[y][7] = sortArrayContent[y+1].videoFileHD;
				temp[y][8] = sortArrayContent[y+1].videoFileLD;
				temp[y][9] = sortArrayContent[y+1].thumb;	
				temp[y][10] = sortArrayContent[y+1].length;
				temp[y][11] = sortArrayContent[y+1].autoPlay;	
				temp[y][12] = sortArrayContent[y+1].resources;			
				temp[y][13] = sortArrayContent[y+1].contactName;
				temp[y][14] = sortArrayContent[y+1].contactTitle;	
				temp[y][15] = sortArrayContent[y+1].contactPhone;	
				temp[y][16] = sortArrayContent[y+1].contactEmail;					
				// PLACE NEWER DATE IN CURRENT ARRAY SLOT
				sortArrayContent[y+1].videoID = sortArrayContent[y].videoID;
				sortArrayContent[y+1].title = sortArrayContent[y].title;
				sortArrayContent[y+1].date = sortArrayContent[y].date;
				sortArrayContent[y+1].categoryID = sortArrayContent[y].categoryID;
				sortArrayContent[y+1].description = sortArrayContent[y].description;
				sortArrayContent[y+1].intro = sortArrayContent[y].intro;
				sortArrayContent[y+1].keywords = sortArrayContent[y].keywords;
				sortArrayContent[y+1].videoFileHD = sortArrayContent[y].videoFileHD;
				sortArrayContent[y+1].videoFileLD = sortArrayContent[y].videoFileLD;
				sortArrayContent[y+1].thumb	= sortArrayContent[y].thumb;
				sortArrayContent[y+1].length = sortArrayContent[y].length;
				sortArrayContent[y+1].autoPlay = sortArrayContent[y].autoPlay;
				sortArrayContent[y+1].resources = sortArrayContent[y].resources;
				sortArrayContent[y+1].contactName = sortArrayContent[y].contactName;
				sortArrayContent[y+1].contactTitle = sortArrayContent[y].contactTitle;
				sortArrayContent[y+1].contactPhone = sortArrayContent[y].contactPhone;
				sortArrayContent[y+1].contactEmail = sortArrayContent[y].contactEmail;
				// PLACE OLD ARRAY CONTENT IN PREVIOUS SLOT
				sortArrayContent[y].videoID = temp[y][0];
				sortArrayContent[y].title = temp[y][1];
				sortArrayContent[y].date = temp[y][2];
				sortArrayContent[y].categoryID = temp[y][3];
				sortArrayContent[y].description = temp[y][4];
				sortArrayContent[y].intro = temp[y][5];
				sortArrayContent[y].keywords = temp[y][6];
				sortArrayContent[y].videoFileHD = temp[y][7];
				sortArrayContent[y].videoFileLD = temp[y][8];
				sortArrayContent[y].thumb = temp[y][9];
				sortArrayContent[y].length = temp[y][10];
				sortArrayContent[y].autoPlay = temp[y][11];
				sortArrayContent[y].resources = temp[y][12];
				sortArrayContent[y].contactName = temp[y][13];
				sortArrayContent[y].contactTitle = temp[y][14];
				sortArrayContent[y].contactPhone = temp[y][15];
				sortArrayContent[y].contactEmail = temp[y][16];
			}
		}
	}
	
	return sortArrayContent;
}


// URL PARSER //
function gup( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//// FLASH FUNCTIONAL CALLS FOR VIDEO PLAYER 

function fetchHDVideo() {
	rebuildSIFR();
	return strMasterHDFile;
}

function fetchLDVideo() {
	return strMasterLDFile;	
}

function autoPlayStatus() {
	return iAutoStart;	
}

function pauseImage() {
	strMasterImage = "placeholder.jpg";
//	LOAD XML THUMBNAIL
	return strMasterImage;	
}

function showResourcesPanel() {
	document.getElementById('resourcePanel').style.visibility = "visible";	
}

function hideResourcesPanel() {
	document.getElementById('resourcePanel').style.visibility = "hidden";		
}

function showVideoPanel() {
	document.getElementById('videoPlayerHome').style.backgroundImage = "url(images/whiteColumn.gif)";
	document.getElementById('resourcePanel').style.visibility = "hidden";			
	document.getElementById('contentPanelSwitch').style.display = "block";			
	document['firstVideo'].src = 'images/videoThumbRoundCurrent.png';			
}

function showGreenScreen() {
	document.getElementById('videoPlayerHome').style.backgroundImage = "url(images/clearPixel.gif)"	
	document.getElementById('resourcePanel').style.visibility = "hidden";			
	document.getElementById('contentPanelSwitch').style.display = "none";		
	document['firstVideo'].src = 'images/videoThumbRound.png';				
}

// ERROR CORRECTION FOR OLDER BROWSERS //

function silentErrorHandler() {
	return true;
}

window.onerror=silentErrorHandler;
