﻿//uses xmlhttpreq to get the raw rss xml
function getRSS()
{

	var RSS_LOCAL_URL = "photos_public.gne";
	
	//call the right constructor for the browser being used
	if (window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else
		alert("not supported");
	
	//prepare the xmlhttprequest object
	xhr.open("GET", RSS_LOCAL_URL);

	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)
					processRSS(xhr.responseText);
				else
				{
					alert("Failed to receive RSS file from the server - file not found.");
					return false;
				}
			}
			else
				alert("Error code " + xhr.status + " received: " + xhr.statusText);
		}
	}

	//send the request
	xhr.send(null);
}
		

//processes the received rss xml
function processRSS(rssxml)
{
	var elem;
	var thumbURLs = new Array();
	var linkURLs = new Array();
	var currentLink = new Array();
	
	items = rssxml.split(/<item>/);
	
	//capture each of the URLs out of the text by using split to find exactly what we want
	for(i=1; i<items.length; i++)
	{
		currentLink = items[i].split(/<media:content url="/);
		currentLink = currentLink[1].split(/"/);
		linkURLs[i] = currentLink[0];
		
		currentLink = items[i].split(/<media:thumbnail url="/);
		currentLink = currentLink[1].split(/"/);
		thumbURLs[i] = currentLink[0];
	}
	
	//use the URLs that we captured and display them on the page
	for(i=1; i<=10; i++)
	{
		elem = document.getElementById("flickr" + i);
		elem.innerHTML = "<a href=\"" + linkURLs[i] + "\" rel=\"lightbox [flickr]\"><img src=\"" + thumbURLs[i] + "\" class=\"flickr\" Onload=\"Lightbox.init()\" /></a>"
	}
}


var xhr;



