var http_request = false;
var dateSort = false;
var state = "type";
var resourceBy = -1;
var id;
var sortBy;
var innerAttrSort = false;
var articles;
var bI = '/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/blank-holder.gif';

function d(str) { // debug function
	
	if(document.getElementById('debugger') == null){
		var s = document.createElement('span');
		s.style.display = 'none';
		s.id = 'debugger';
		s.innerHTML = str+'\n';
		var b = document.getElementsByTagName('body')[0];
		b.appendChild(s);
	} else {
		var s = document.getElementById('debugger');
		s.innerHTML += str+'\n';
	}	
}

function watchMoviePopUp( obj ) {
	popUpHTML='<HTML>\n';
	popUpHTML+='<HEAD>\n';
	popUpHTML+='<TITLE>New Document</TITLE>\n';
	popUpHTML+='<link href="http://www.umc.org/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/MoviePopUp.css" rel="stylesheet" type="text/css">\n';
	popUpHTML+='</HEAD>\n';
	popUpHTML+='<BODY>\n';
	popUpHTML+='<div id="MoviePopUpArea">';
	popUpHTML+='<h1>Video: '+obj.title+'</h1>';
	popUpHTML+='<div id="Flash" style=\"display:_none;\"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="234" height="196" id="videoplayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="FLASHVARS" value="loadFile='
				+obj.vlink+'&loadTime=50&fileType=FLV"><param name="swliveconnect" value="true"><param name="movie" value="http://www.umc.org/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/videoplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="http://www.umc.org/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/videoplayer.swf" swliveconnect="true" FLASHVARS="file=http://www.umc.org/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/DEALSDIFFERENTCITIES_BPHIL.FLV&totaltime=50&playType=FLV" quality="high" bgcolor="#ffffff" width="234" height="196" name="videoplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>';
	popUpHTML+='<h2>'+obj.title+'</h2>';
	popUpHTML+='<p>'+obj.description+'</p>';
	popUpHTML+='<p style="text-align:center"><a href="#">MPEG Download</a>&nbsp;|&nbsp;<a href="#">Podcast</a>&nbsp;|&nbsp;<a href="#">Transcript</a>&nbsp;|&nbsp;<a href="#">More Video Stories</a></p></div></BODY>\n';
	popUpHTML+='</HTML>';
	moviePopUp=window.open('',obj.id,'left=20,top=20,width=350,height=400,toolbar=0,resizable=0');
	moviePopUp.document.write(popUpHTML);
	if(document.all!=null){	
		var flashDivs = moviePopUp.document.getElementsByTagName('div');
		var divInnerHTML = "";
		var i = 1;
		divInnerHTML = flashDivs[i].innerHTML;
		flashDivs[i].innerHTML = "";
		flashDivs[i].innerHTML = divInnerHTML;
		flashDivs[i].setAttribute("style","");
	}
}

function greyOut(pN) {
	
}

function watchMovie( obj, art ) {
	var b = document.getElementsByTagName('body')[0];
	var hD = obj.parentNode.parentNode; // Holding Div
	var s = document.createElement('div'); // Spacer

	s.style.height = hD.offsetHeight+10+'px';
	s.className = "ArticleMovieSpacer";
	
	hD.className = hD.className+' TopMovie';
	hDL = hD.offsetLeft;
	hDT = hD.offsetTop;

	var gD = document.createElement('div'); // Greyed div background	
	gD.id = "GreyBox";

	var cL = document.createElement('a'); // Closing Link
	cL.href="javascript:;";
	cL.onclick= function () { closeMovie(this); };
	cL.innerHTML="<img src=\"/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/close_gif.gif\" />";
	cL.className="CloseMovie";
	
	fD = document.createElement('div');
	fD.id = 'MovieFlash';
	fD.innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0&lt;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab       &gt;" width="240" height="200"><param name="movie" value="/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/6_videoplayer8.swf"/><param name="quality" value="high"/><param name="FLASHVARS" value="file='+art.vlink+'&amp;totaltime=268&amp;playType=FLV"/><param name="swliveconnect" value="true"/><embed src="/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/6_videoplayer8.swf" swliveconnect="true" FLASHVARS="file='+art.vlink+'&amp;totaltime=268&amp;playType=FLV" quality="high" pluginspage="           &lt;http://www.macromedia.com/go/getflashplayer &gt;" type="application/x-shockwave-flash" width="240" height="200"></embed></object>';
	var cD = hD.lastChild; // Clear Div
	hD.insertBefore(fD,cD);
	hD.insertBefore(cL,cD);
	hD.parentNode.insertBefore(gD,obj.parentNode.parentNode);

	obj.parentNode.nextSibling.lastChild.style.display = 'none'; // View All Tag Remove

	hD.parentNode.insertBefore(s,obj.parentNode.parentNode.nextSibling);
	
	hD.style.top = hD.offsetTop - 22+'px';
	hD.style.left = hD.offsetLeft - 12+'px';
	hD.style.border  = "2px solid #D38200";
	obj.style.display = "none";
}

function closeMovie(o) {
	var hD = o.parentNode; // Holding Div
	var m = o.previousSibling; // movie
	var gB = document.getElementById('GreyBox');
	var s = hD.nextSibling; // spacer
	var a = o.previousSibling.previousSibling.previousSibling.lastChild; // a tag watch video
	m.previousSibling.lastChild.style.display = 'block';
	a.style.display = "";
	hD.style.border  = "0";
	hD.removeChild(o);
	hD.removeChild(m);
	hD.parentNode.removeChild(gB);
	hD.parentNode.removeChild(s);
	hD.className = "resourceblock first";
	hD.style.top = '';
	hD.style.left = '';
}

function getElementsByClassName(oElm, strTagName, strClassName) { 
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName); 
	var arrReturnElements = new Array(); 
	strClassName = strClassName.replace(/\-/g, "\\-"); 
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)"); 
	var oElement; 
	for(var i=0; i<arrElements.length; i++){ 
		oElement = arrElements[i]; 
		if(oRegExp.test(oElement.className)){ 
			arrReturnElements.push(oElement); 
		} 
	} 
	return (arrReturnElements)  }

function changeSort( type, aid, o) {
	var obj = document.getElementById("viewby");
	if (type == 'sponsor') {
		document.getElementById('viewby').innerHTML = 'View stories by:&nbsp;&nbsp;<a href="#"  onclick="return changeSort(\'type\');" >Type</a><span>|</span><a href="#" onclick="return changeSort(\'sponsor\');" >Date</a>';
		document.getElementById('anchorlinks2').innerHTML = '';
		obj.childNodes[3].className="current";
		obj.childNodes[1].className="";
		dateSort = true;
		state = 'featured';
	} else if (type == 'type') {
		document.getElementById('viewby').innerHTML = 'View stories by:&nbsp;&nbsp;<a href="#"  onclick="return changeSort(\'type\');" >Type</a><span>|</span><a href="#" onclick="return changeSort(\'sponsor\');" >Date</a>';
		document.getElementById('anchorlinks2').innerHTML = '';
		obj.childNodes[1].className="current";
		obj.childNodes[3].className="";
		dateSort = false;
		state = 'featured';
	}
	
	if (type == "sponsor_all_2") {
		state= "type_all2";
		document.getElementById('viewby').innerHTML = '';
		document.getElementById('anchorlinks2').innerHTML = '&lt;&lt; <a href="#" onclick="return changeSort(\'type\',\'\',this);">Back to Video Stories home</a>';
		
		sortBy = aid;
		dateSort = true;
	}
	if (type == "sponsor_all") {
		state= "type_all";
		document.getElementById('viewby').innerHTML = '';
		sortBy = aid;
		dateSort = true;
	}
	if (type == "type_all") {
		state= "type_all";
		document.getElementById('viewby').style.visibilty = 'hidden';
		/* document.getElementById('viewby').innerHTML = 'View videos by:&nbsp;&nbsp;<a href="#"  onclick="return changeSort(\'type_all\','+id+');" >Most Recent</a><span>|</span><a href="#" onclick="return changeSort(\'type_all\','+id+',true);" >Date</a>';		
		if(sort2) {
			obj.childNodes[1].className="";
			obj.childNodes[3].className="current";
		} else {
			obj.childNodes[1].className="current";
			obj.childNodes[3].className="";
		}*/

		sortBy = aid;
		dateSort = false;
	}

	var l = document.createElement('img');
	l.src = "/atf/cf/%7BDB6A45E4-C446-4248-82C8-E131B6424741%7D/loading_ajx.gif";
	l.id = "LoadingImage";
	l.style.display = "block";
	l.style.margin = "50px 0 0 210px";
	var a = document.getElementById("articles");
	a.innerHTML = "";
	a.appendChild(l);
	
	articles = getArticles(root_node);
		
	switch(state) {
		case "type_all"	:   document.getElementById('anchorlinks2').innerHTML = '&lt;&lt; <a href="#" onclick="return changeSort(\'type\',\'\',this);">Back to Video Stories home</a>';
							document.getElementById('articles').innerHTML = displayAllTypes(articles);
							break;
		case "type_all2":   document.getElementById('anchorlinks2').style.visibility = "";
							document.getElementById('articles').innerHTML = createResources(articles);
							document.getElementById('viewby').innerHTML = '';
							document.getElementById('anchorlinks2').innerHTML = '&lt;&lt; <a href="#" onclick="return changeSort(\'type\',\'\',this);">Back to Video Stories home</a>';;
							
							break;
		default			:	document.getElementById('anchorlinks2').style.visibility = "";
							document.getElementById('articles').innerHTML = createResources(articles);
							document.getElementById('anchorlinks2').innerHTML = buildJumpTo(articles);
							break;
	}
	//makeRequestResources();
	return false;
}

function compare(x,y) {
	if(x.type == y.type) { return 0; }
	if(x.type < y.type) { return -1; }
	return 1;
}

//Mon, 14 Aug 2006 12:55:28 PST
function convertDate( d, rYear ) {
	var nm = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var m = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var arr = d.split(',')[1].split(' ');
	var day = arr[1];
//	monthTemp = arr[2];
	var month = arr[2];
	var year = arr[3];
	var i;
	var monthDigit;
	for(i=0; i<m.length; i++) { 
			if(month == m[i]) {
					month = nm[i];
					monthDigit = i+1;
			}
		
	}
	monthDigit = monthDigit.toString();
	if(monthDigit.length == 1) {
		monthDigit = '0'+monthDigit;
	}
	day = day.toString();
	if(day.length == 1) {
		day = '0'+day;
	}
	var cDate = month;
	if(rYear) {

//			return month + ' ' + year;
			return year;
	
	} else {
		var cDate = monthDigit+'/'+day+'/'+year;
		return cDate;
	}
}


function getArticles( XMLNode ) {
	var XMLItem = new Array();
	var test = "";
	var dS= dateSort ? 'date' : 'type';
	var sA = new Array();
	
	for (i=0; XMLNode.length>i; i++)
	{
		 XMLItem[i] = new Array();
		 for (k=0; XMLNode[i].childNodes.length>k; k++)
		 {
 			 if(XMLNode[i].childNodes[k].firstChild != null) {
				 switch(XMLNode[i].childNodes[k].tagName) {
					 case "title" : XMLItem[i]["title"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "k:go_to_article_now" : XMLItem[i]["article"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "k:type" : if( !dateSort ) {
										XMLItem[i]["type"] = XMLNode[i].childNodes[k].firstChild.data;
									 }
										break;
					 case "k:video_link" : XMLItem[i]["vlink"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "k:summary_img" : XMLItem[i]["image"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "title" : XMLItem[i]["title"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "description" : XMLItem[i]["description"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "link" : XMLItem[i]["hlink"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "k:visit_site" : XMLItem[i]["sponsor_link"] = XMLNode[i].childNodes[k].firstChild.data;
										break;
					 case "guid" :      XMLItem[i]["id"] = XMLNode[i].childNodes[k].firstChild.data.split('ct=')[1];
										break;
					 case "pubDate" : 
					 				if( dateSort ) {
  									   XMLItem[i]["type"] = convertDate(XMLNode[i].childNodes[k].firstChild.data,true);
									   XMLItem[i]["date"] = convertDate(XMLNode[i].childNodes[k].firstChild.data);
									 } else {
										XMLItem[i]["date"] = convertDate(XMLNode[i].childNodes[k].firstChild.data);
									 }
									break;
				 }
			 }
			 XMLItem[i].include = true;
			 if(XMLItem[i].article != null) {
				if(XMLItem[i].article != "") {
					XMLItem[i].hlink = XMLItem[i].article;
				}
			 }
			 
			if(XMLItem[i].image == "") {
					XMLItem[i].image = "/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/blank-holder.gif";
			}
		 }
	}
	
	for(i=0;i<XMLItem.length; i++) {  // This loop splits categories into another array
		d(XMLItem[i].image);
		if(dS == 'type') {
			d(XMLItem[i].image);
			if(XMLItem[i]['type'].indexOf(';') > -1) {
				 c = XMLItem[i]['type'].split(';');
				 for (i2=0; i2<c.length; i2++) {
					 if(i2==0) {
						 //test +=  "XMLItem["+i+"]['type'] = "+c[i2]+"\n";
						 XMLItem[i]['type'] = c[i2];
					 } else {
						 var tX = new Array();
						 tX.title = XMLItem[i].title;
						 tX.article = XMLItem[i].article;
						 tX.id = XMLItem[i].id;
						 tX.sponsor_link = XMLItem[i].sponsor_link;
						 tX.image = XMLItem[i].image;
						 tX.hlink = XMLItem[i].hlink;
						 tX.vlink = XMLItem[i].vlink;
						 tX.description = XMLItem[i].description;
						 tX.date = XMLItem[i].date;
						 tX.type = c[i2].replace(/^\s*(.*?)\s*$/, "$1");
						 tX.include = false;
						 sA.push(tX);
					 }
				 }
			 }
		 }
	}

	for(i=0; i<sA.length; i++) { // this array joins other categories split from above loop
		XMLItem.push(sA[i]);	
	}

	if( !dateSort ) {
		XMLItem.sort(compare);
	}
	
	var oldType = "";
	k = -1;
	m = 0;
	var articles = new Array();
	for (i=0; XMLItem.length>i; i++)
	{
		//d(i+" : "+XMLItem[i].type+" - "+XMLItem[i].title);
		if (oldType != XMLItem[i].type ) {
			k++;
			oldType = XMLItem[i].type;
			articles[k] = new Array();
			m=0;
		}
		articles[k].type = XMLItem[i].type;
		articles[k][m] = XMLItem[i];
	
		m++;
	}
	
	var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
	for (i=0; articles.length>i; i++)
	{
//		if(i==1) {alert(articles[i].type+'=='+ sortBy);}
		
		if(articles[i].type == sortBy) {
			id = i; // adds witch type to show all requests from
		}
		
		articles[i].sort(function (a, b){
				a = a['date'].replace(dateRE,"$3$1$2");
				b = b['date'].replace(dateRE,"$3$1$2");
				if (a>b) return -1;
				if (a <b) return 1;
				return 0; }
			);
	}
	return articles;
}


function buildJumpTo(articles) {
	var oldType = "";
	var jumpToBlock = "";
	jumpToBlock = "Jump to:&nbsp;&nbsp;";
	var i;
	var test = articles.length;
	for (i=0; articles.length>i; i++)
	{
		if (oldType != articles[i].type ) {
			jumpToBlock += '<a href="#'+articles[i].type+'">'+articles[i].type+'</a>';
			oldType = articles[i].type;
			if(articles.length != (i+1) ) {
				jumpToBlock += ' <span>|</span>';
			}
		}
	}
	return jumpToBlock;
}


function displayAllTypes( articles ) {
	document.getElementById('viewby').innerHTML = '';
	if(innerAttrSort) {	articles[id].sort( function (x,y) {	if(x.sponsor == y.sponsor) { return 0; }	if(x.sponsor < y.sponsor) { return -1; }	return 1; }); } // sorting if they are sorting by sponsor or type
		resourceBlocks = '';
		var backgroundImage = '';
	
		if(dateSort) { backgroundImage = 'style="background: url(http://www3.umcom.org/atf/cf/%7B60C02017-4F6A-4F3B-883A-4AFAECE1182F%7D/bg_tan.gif) repeat-x;"'; }
			else { backgroundImage = 'style="background: url(http://www3.umcom.org/atf/cf/%7B60C02017-4F6A-4F3B-883A-4AFAECE1182F%7D/bg_tan.gif) repeat-x 0;"'; }
		resourceBlocks += '<h2 id="'+articles[id].type+'" '+backgroundImage+' >'+articles[id].type+'&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;All Results</h2>';
		for (j=0; articles[id].length>j; j++) {
			if(articles[id][j].article != "") {
				articles[id][j].hlink = articles[id][j].article;
			}
			resourceBlocks += '<div class="resourceblock first"><div class="photo"><img alt="" src="'+articles[id][j].image+'" /></div><div class="text">  <h3><a href="'+articles[id][j].hlink+'">'+articles[id][j].title+'</a></h3><p>'+articles[id][j].description+'</p><a onclick="watchMovie(this,articles['+id+']['+j+']);" class="extlink" href="javascript:;">Watch video now</a></div><div class="extlinks">'+articles[id][j].date+'<br />';
			if(!dateSort) {
				resourceBlocks += '<a href="#"  onclick="return changeSort(\'sponsor_all_2\', \''+articles[id][j].date+'\', this);">View All</a></div>'; 
			} else { 
				resourceBlocks += '<a href="#" onclick="return changeSort(\'type_all\', \''+articles[id][j].date+'\',this);">view all</a></div>'; 
				
			}
			resourceBlocks += '<div class="clear"></div></div><span style="display:none">'+articles[id][j].type+'</span>';
		}
		resourceBlocks += '<div class="backtotoplink"><a href="#anchorlinks2">Back to top</a></div><div class="clear"></div>';
		return resourceBlocks;
	
}


function createResources(articles) {

	if(!dateSort) {
		var resourceBlocks = "";
		var maxArticles = 2;
		var backgroundImage = "";
		var tA = maxArticles;
		for (i=0; articles.length>i; i++)
		{
			if(dateSort) { 
				backgroundImage = 'style="background: url(http://www3.umcom.org/atf/cf/%7B60C02017-4F6A-4F3B-883A-4AFAECE1182F%7D/bg_tan.gif) repeat-x;"';
				thisSortType = 'sponsor_all';
				//resourceBlocks += '<h2 id="'+articles[i].type+'" '+backgroundImage+' ><a href="#" onclick="return changeSort(\''+thisSortType+'\',\''+articles[i].type+'\');">'+articles[i].type+'</a></h2>';
			} else {
				thisSortType = 'type_all';
				backgroundImage = 'style="background: url(http://www3.umcom.org/atf/cf/%7B60C02017-4F6A-4F3B-883A-4AFAECE1182F%7D/bg_tan.gif) repeat-x;"';
			}
			
			resourceBlocks += '<h2 id="'+articles[i].type+'" '+backgroundImage+' >Featured '+articles[i].type+' Videos ( <a href="#" onclick="return changeSort(\''+thisSortType+'\',\''+articles[i].type+'\',this);">View all</a> )</h2>';
			
			for (j=0; articles[i].length>j; j++) {
				if (tA<=j) { break; }
				if(articles[i][j].include) {
			//			watchVideoA = '<a class="extlink" target="_extVideo" href="'+articles[i][j].video_link+'">';
						watchVideoA = '<a class="extlink" onclick="watchMovie(this,articles['+i+']['+j+']);" href="javascript:;">';
						resourceBlocks += '<div class="resourceblock first"><div class="photo"><img alt="" src="'+articles[i][j].image+'" /></div><div class="text">  <h3><a href="'+articles[i][j].hlink+'">'+articles[i][j].title+'</a></h3><p>'
						+articles[i][j].description+'</p><a class="extlink" onclick="watchMovie(this,articles['+i+']['+j+']);" href="javascript:;">Watch video now</a></div><div class="extlinks">'+articles[i][j].date+'<br />';
						if(!dateSort) { resourceBlocks += '<a href="#" onclick="return changeSort(\'sponsor_all_2\', \''+articles[i][j].date+'\', this);">View All</a></div>'; }
						  else { resourceBlocks += '<a href="#" onclick="return changeSort(\'type_all\',\''+articles[i][j].date+'\',this); ">view all</a></div>'; }
						resourceBlocks += '<div class="clear"></div></div>';

				} else {
					tA++;
				}
			}
			tA = maxArticles;
			resourceBlocks += '<div class="backtotoplink"><a href="#anchorlinks2">Back to top</a></div><div class="clear"></div>';
		}
		return resourceBlocks;
	} else {
		var resourceBlocks = "";
	//	var maxArticles = 10;
		var backgroundImage = "";
		for (i=0; articles.length>i; i++)
		{
			thisSortType = 'type_all';
			backgroundImage = 'style="background: url(http://www3.umcom.org/atf/cf/%7B60C02017-4F6A-4F3B-883A-4AFAECE1182F%7D/bg_tan.gif) repeat-x;"';
			
			for (j=0; articles[i].length>j; j++) {
				d(articles[i][j].date+' == '+sortBy);
				if (state== "type_all2") {
					if(articles[i][j].date == sortBy) {
						i2=i; j2=j;
						resourceBlocks += '<div style="height:20px;width:100%;clear:both;"><a href="'+articles[i][j].hlink+'" style="width:370px;float:left;">'+articles[i][j].title+'</a><div class="extlinks" style="float:left;">'+articles[i][j].date+'</div></div>';
					}
				} else {
					if(j==0) {resourceBlocks += '<h2 id="'+articles[i].type+'" '+backgroundImage+' >'+articles[i].type+'</h2>';}
					    resourceBlocks += '<div style="height:20px;width:100%;clear:both;"><a href="'+articles[i][j].hlink+'" style="width:370px;float:left;">'+articles[i][j].title+'</a><div class="extlinks" style="float:left;">'+articles[i][j].date+'</div></div>';
				}
			}

		}
		if (state== "type_all2") { resourceBlocks = '<h2 id="'+articles[i2].type+'" '+backgroundImage+' >'+articles[i2].type+'</h2>'+resourceBlocks; }
//		resourceBlocks = '<h2 id="'+articles[i2].type+'" '+backgroundImage+' >'+articles[i2].type+'</h2>'+resourceBlocks;
		resourceBlocks += '<div class="backtotoplink"><a href="#anchorlinks2">Back to top</a></div><div class="clear"></div>';
		return resourceBlocks;
	}
}

function makeRequestResources() {
	url='http://www.umcom.org/site/apps/nl/rss3.asp?c=mrLZJ9PFKmG&b=4865169';
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = displayResources;
	http_request.open('GET', url, true);
	http_request.send(null);
}


var root_node;
function displayResources() {
	if (http_request.readyState == 1) {

	}
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
			root_node = xmldoc.getElementsByTagName('item');
			articles = getArticles(root_node);
		
			switch(state) {
				case "type_all"	:   document.getElementById('anchorlinks2').innerHTML = '&lt;&lt; <a href="#" onclick="return changeSort(\'type\',\'\',this);">Back to Video Stories home</a>';
									document.getElementById('articles').innerHTML = displayAllTypes(articles);
									break;
				case "type_all2":   document.getElementById('anchorlinks2').style.visibility = "";
									document.getElementById('articles').innerHTML = createResources(articles);
									document.getElementById('viewby').innerHTML = '';
									document.getElementById('anchorlinks2').innerHTML = '&lt;&lt; <a href="#" onclick="return changeSort(\'type\',\'\',this);">Back to Video Stories home</a>';;
									
									break;
				default			:	document.getElementById('anchorlinks2').style.visibility = "";
									document.getElementById('articles').innerHTML = createResources(articles);
									document.getElementById('anchorlinks2').innerHTML = buildJumpTo(articles);
									break;
			}

			} else {
				alert('There was a problem with the request.');
			}
	}
	
	document.getElementById('articles').innerHTML = document.getElementById('articles').innerHTML;
}

function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load', fn, false);
	}
 	else if (typeof document.addEventListener != 'undefined')
 	{
   	document.addEventListener('load', fn, false);
	}
 	else if (typeof window.attachEvent != 'undefined')
 	{
   	window.attachEvent('onload', fn);
 	}
 	else
 	{
   	var oldfn = window.onload;
   	if (typeof window.onload != 'function')
   	{
     window.onload = fn;
   	}
   	else
   	{
	window.onload = function()
     {
       oldfn();
       fn();
     };
   }
 }
}

function init(){
	document.getElementById('viewby').innerHTML = 'View stories by:&nbsp;&nbsp;<a class="current" href="#"  onclick="return changeSort(\'type\');" >Type</a><span>|</span><a href="#" onclick="return changeSort(\'sponsor\');" >Date</a>';
	document.getElementById('articles').innerHTML = '<img src="/atf/cf/{DB6A45E4-C446-4248-82C8-E131B6424741}/loading_ajx.gif" style="margin:50px auto 0 210px;"/>';
}
addLoadListener(init);

addLoadListener(makeRequestResources);
