// JavaScript Document
var xDoc= null;
var brprototype=document.createElement("br");
	function ajaxRead(xfile,listType)
	{
		var xmlObj = null;
  		if(window.XMLHttpRequest)
		{
			xmlObj = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
      		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  		} 
		else 
		{
      		return;
  		}
  		xmlObj.onreadystatechange = function()
		{
  			if(xmlObj.readyState == 4)
			{
       			xDoc=xmlObj.responseXML;
	   			drawPage(listType);
     		}
    	}
    	xmlObj.open ('GET', xfile, true);
    	xmlObj.send ('');
  	}
	function initpage(listType)
	{
		var n=11;
		var imgNo=Math.floor(Math.random( ) * n) + 1;
		document.getElementById("header").style.backgroundImage = "url(images/header"+imgNo+".jpg)";
		ajaxRead("content.xml",listType);
	}
	function drawPage(listType) 
	{
		var maxItems=10;
		var nameProto=document.getElementById("linkProto").firstChild.cloneNode(true);
		var itemProto=document.getElementById("itemProto").firstChild.cloneNode(true);
		var totalName=xDoc.getElementsByTagName("content")[0].getElementsByTagName("item").length;
		var streamNo=0;
		var downloadNo=0;
		var slideNo=0;
		var scrollNo=0;
		var featurehead="";
		var feature=false;
		var linkName="";
		for (var i = 0; i < totalName; i++)
		{
			var data = xDoc.getElementsByTagName("content")[0].getElementsByTagName("item")[i];
			nameProto.setAttribute("title",data.getElementsByTagName("linktitle")[0].firstChild.nodeValue);
			nameProto.setAttribute("href",data.getElementsByTagName("url")[0].firstChild.nodeValue);
			linkName=data.getElementsByTagName("linktitle")[0].firstChild.nodeValue;
			if (data.getElementsByTagName("length")[0])
			{
				linkName=linkName+" ("+data.getElementsByTagName("length")[0].firstChild.nodeValue+")";
			}
			if (data.getElementsByTagName("size")[0])
			{
				linkName=linkName+" ("+data.getElementsByTagName("size")[0].firstChild.nodeValue+")";
			}
			if (data.getElementsByTagName("date")[0])
			{
				linkName=linkName+" - "+data.getElementsByTagName("date")[0].firstChild.nodeValue;
			}
			nameProto.firstChild.nodeValue=linkName;
			if (document.getElementById("cFrame"))
			{
				if (data.getAttribute("feature")=="true" && feature==false)
				{
					feature=true;
					if (data.getAttribute("type")=="streaming")
					{
						featurehead="Feature Video: "+data.getElementsByTagName("linktitle")[0].firstChild.nodeValue;
						document.getElementById("featureHead").firstChild.nodeValue=featurehead;
						document.getElementById("cFrame").src=data.getElementsByTagName("url")[0].firstChild.nodeValue+"?close=1";
					}
					if (data.getAttribute("type")=="scroll")
					{
						featurehead="Feature Panorama: "+data.getElementsByTagName("linktitle")[0].firstChild.nodeValue;
						document.getElementById("featureHead").firstChild.nodeValue=featurehead;
						document.getElementById("cFrame").src=data.getElementsByTagName("url")[0].firstChild.nodeValue+"?close=1";
					}
					if (data.getAttribute("type")=="slide")
					{
						featurehead="Feature Slide Show: "+data.getElementsByTagName("linktitle")[0].firstChild.nodeValue;
						document.getElementById("featureHead").firstChild.nodeValue=featurehead;
						document.getElementById("cFrame").src=data.getElementsByTagName("url")[0].firstChild.nodeValue+"?close=1";
					}
				}
			}				
			if (data.getAttribute("type")=="streaming" && listType != "streaming")
			{
				if(streamNo < maxItems)
				{
					document.getElementById("streaming").appendChild(nameProto.cloneNode(true));
					document.getElementById("streaming").appendChild(brprototype.cloneNode(true));
				}
				streamNo++;
			}
/*
			if (data.getAttribute("type")=="download" && listType != "download")
			{
				if(downloadNo < maxItems)
				{
					document.getElementById("download").appendChild(nameProto.cloneNode(true));
					document.getElementById("download").appendChild(brprototype.cloneNode(true));
				}
				downloadNo++;
			}
*/	
			if (data.getAttribute("type")=="slide" && listType != "slide")
			{
				if(slideNo < maxItems)
				{
					document.getElementById("slide").appendChild(nameProto.cloneNode(true));
					document.getElementById("slide").appendChild(brprototype.cloneNode(true));
				}
				slideNo++;
			}
			if (data.getAttribute("type")=="scroll"&& listType != "scroll")
			{
				if(scrollNo < maxItems)
				{
					document.getElementById("scroll").appendChild(nameProto.cloneNode(true));
					document.getElementById("scroll").appendChild(brprototype.cloneNode(true));
				}
				scrollNo++;
			}
			var descrip="";
			if (data.getAttribute("type")==listType)
			{
				itemProto.childNodes[0].setAttribute("title",data.getElementsByTagName("linktitle")[0].firstChild.nodeValue);
				itemProto.childNodes[0].setAttribute("href",data.getElementsByTagName("url")[0].firstChild.nodeValue);
				linkName=data.getElementsByTagName("linktitle")[0].firstChild.nodeValue;
				if (data.getElementsByTagName("length")[0])
				{
					linkName=linkName+" ("+data.getElementsByTagName("length")[0].firstChild.nodeValue+")";
				}
				if (data.getElementsByTagName("size")[0])
				{
					linkName=linkName+" ("+data.getElementsByTagName("size")[0].firstChild.nodeValue+")";
				}
				if (data.getElementsByTagName("date")[0])
				{
					linkName=linkName+" - "+data.getElementsByTagName("date")[0].firstChild.nodeValue;
				}
				if (data.getElementsByTagName("description")[0])
				{
					descrip=data.getElementsByTagName("description")[0].firstChild.nodeValue;
				}
				itemProto.childNodes[0].firstChild.nodeValue=linkName;
				itemProto.childNodes[1].firstChild.nodeValue=descrip;
				document.getElementById("content").appendChild(itemProto.cloneNode(true));

			}
		}
		if (streamNo > maxItems)
		{
			nameProto.firstChild.nodeValue="Archive";
			nameProto.setAttribute("href","streaming.html");
			nameProto.setAttribute("title","Video Streaming Archive");
			document.getElementById("streaming").appendChild(nameProto.cloneNode(true));
		}
		if (downloadNo > maxItems)
		{
			nameProto.firstChild.nodeValue="Archive";
			nameProto.setAttribute("href","download.html");
			nameProto.setAttribute("title","Video Download Archive");
			document.getElementById("download").appendChild(nameProto.cloneNode(true));
		}
		if (slideNo > maxItems)
		{
			nameProto.firstChild.nodeValue="Archive";
			nameProto.setAttribute("href","slideshow.html");
			nameProto.setAttribute("title","Slide Show Archive");
			document.getElementById("slide").appendChild(nameProto.cloneNode(true));
		}
		if (scrollNo > maxItems)
		{
			nameProto.firstChild.nodeValue="Archive";
			nameProto.setAttribute("href","scrollImage.html");
			nameProto.setAttribute("title","Scroll Image Archive");
			document.getElementById("scroll").appendChild(nameProto.cloneNode(true));
		}
	}