function prepareFlickrPoem(xmlPoem, stanzaId, status) {
	
	//List of prepositions, conjunctions etc...
	replaceWords = new Array('', 'the', 'an', 'a', 'for', 'and', 'nor', 'but', 'or', 'yet', 'so', 'after', 'although', 'as', 'if', 'though', 'because', 'before', 'even', 'if', 'only', 'in', 'now', 'once', 'rather', 'since', 'that', 'than', 'though', 'till', 'unless', 'until', 'when', 'whenever', 'where', 'whereas', 'wherever', 'while', 'also', 'both', 'not', 'either', 'neither ', 'whether', 'at', 'on', 'however', 'by', 'my', 'some', 'over', 'with', 'i', 'he', 'she', 'it', 'they', 'you', 'we', 'they', 'them', 'theirs', 'themselves', 'us', 'ours', 'ourselves', 'him', 'her', 'it', 'his', 'hers', 'its', 'himself', 'herself', 'itself', 'your', 'yourself', 'me', 'myself', 'of', 'thy', 'is');
	
	//Number words replaced
	var replaceCount = 0;
	
	//Running total of words
	var totalLineWords = 0;
	var subtotalWords = 0;
	var progressEnd = 0;
	
	//Create poem holder
	var poemHolder = document.createElement("div");
	poemHolder.setAttribute("id", 'poemHolder');
	
	//Create stanza holder
	var newStanzaHolder = document.createElement("div");
	var idStanza = ('stanza'+stanzaId);
	newStanzaHolder.setAttribute("id", idStanza);
	newStanzaHolder.className=("stanza");
	poemHolder.appendChild(newStanzaHolder);
	
	//Append poem holder
	var digitalPoem = document.getElementById("digipoem");
	digitalPoem.appendChild(poemHolder);

	//Get author text or set as Anonymous
	try {
		var authorText = xmlPoem.getElementsByTagName("author")[0].childNodes[0].nodeValue;
	}
	catch(err) {
		var authorText = "Anonymous";
	}
	
	//Get title text or set as Untitled
	try {
		var titleText = xmlPoem.getElementsByTagName("title")[0].childNodes[0].nodeValue;
	}
	catch(err) {
		var titleText = "Untitled";
	}
	
	//Progress: 1-Start, 2-End, 4-NoStanza
	if (status == 1){
		var poemHeading = document.getElementById("poemheading");

		if (document.getElementById('poemtitle')) {
			var oldtitleHolder = document.getElementById('poemtitle');
			poemHeading.removeChild(oldtitleHolder);
		}
		
		var titleHolder = document.createElement('span');
		titleHolder.setAttribute("id", "poemtitle");
		var titleNode = document.createTextNode(titleText + " - " + authorText);
		titleHolder.appendChild(titleNode);
		poemHeading.appendChild(titleHolder);
	}

	//Get stanza(s)
	if (status == 4){
		stanzaContent = xmlPoem;
		var stanzaArray = xmlPoem.getElementsByTagName("poem");
	}
	else {
		var stanzaArray=xmlPoem.getElementsByTagName("stanza");
		stanzaContent=stanzaArray[stanzaId];
		if (stanzaContent == null){
			stanzaContent.removeChild(stanzaArray[stanzaId]);
		}
	}
	
	var stanzalinearray=stanzaContent.getElementsByTagName("line");
	var totalLines = stanzalinearray.length;
	
	//For each line  
	for (z=0;z<totalLines;z++) {
		
		var idLine = ('line'+z);
		
		try {
			lineContent=stanzalinearray[z].childNodes[0].nodeValue;
		}
		catch(err) {
			lineContent = null;
		}
				
		if (lineContent != null) {
		
			while (lineContent.charAt(0) == ' ') {
				lineContent = lineContent.substring(1);
			}
			while (lineContent.charAt(lineContent.length - 1) == ' ') {
				lineContent = lineContent.substring(0, lineContent.length - 1);
			}
		
			var newLineHolder = document.createElement("p");
			newLineHolder.setAttribute("id", idLine);
			newStanzaHolder.appendChild(newLineHolder);
			
			var line = lineContent.replace(/[\.,;!#\$\/:\?'\(\)\[\]_\-\\]/g,'');

			var splitline=line.split(" ");
			var totalLineWords = splitline.length;
			var subtotalWords = progressEnd;
			var progressEnd = (subtotalWords + totalLineWords);
			
			//For each word
			for (y=0;y<totalLineWords;y++) {
			
				var idWord = ('stanza'+stanzaId+'line'+z+'word'+y);
						
				var word = splitline[y];
				wordLower=word.toLowerCase();
			
				if (wordLower != '') {
					var newWordHolder = document.createElement("span");
					newWordHolder.setAttribute("id", idWord);
					newWordHolder.className = ("wordholder");
				}
				
				var wordNode = document.createTextNode(word);
				var tagWordNode = document.createTextNode(word);
				var tagWord = document.createElement('span');
				tagWord.className = ("tagword");
				tagWord.appendChild(tagWordNode);
					
				for (i=0; i<replaceWords.length; i++) {
					if (wordLower==replaceWords[i]) {
						newWordHolder.appendChild(wordNode);
						newLineHolder.appendChild(newWordHolder);
						word='replaced';
						minusReplaceCount = (progressEnd - 1);
						progressEnd = minusReplaceCount;
					}
				}
				
				if (word != 'replaced') {
					
					newWordHolder.className = ("wordimgholder");
					newWordHolder.appendChild(tagWord);
					newLineHolder.appendChild(newWordHolder);
					
					var loadingImage = makeLoadingImage(idWord);
					newWordHolder.appendChild(loadingImage);
					
					var requestRecieved = false;
					var firstLoad = true;	
					
					for (i=0; i<wordArray.length; i++) {	
						if ((idWord+0)==wordArray[i]) {
							requestRecieved = true;
							populatePoem(0, 50, idWord, i, word, firstLoad);
						}
					}
					
					if (requestRecieved == false) {
						newStanzaHolder.onLoad = new requestFlickr(word, idWord, idLine); 
					}
				}
			}
		}
	}
	
	progressUpdate(progressEnd, 0);
	stanzaNav(stanzaId, stanzaArray);
	
}

function requestFlickr(word, idWord) {

	//Flickr Request variables
	var hostname = 'http://api.flickr.com/';
	var perpage = 50;
	var path = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=4b061797cb4461989b0de3ae153c1e96&tags="'+encodeURIComponent(word)+'"&sort=relevance&tag_mode=all&per_page='+perpage+'&page=1';
	var url = 'http://www.dudeyjon.com/digipoem/restapiproxy.php?csurl='+encodeURIComponent(path);
	var method = "GET";
	var asyncRequest = "true";
	var callback = responseFlickr;
	var firstLoad = true;
	
	//Make new request
	new xmlRequest(url, method, asyncRequest, callback);
	
	function responseFlickr(request) {	
	
		//Get XML response
		var response = request.responseXML;
		if (response) {
			if (response.documentElement && response.documentElement.tagName == "parsererror") {
				new xmlRequest(url, method, asyncRequest, callback);
			}
			else {
				getPhoto(response);
			}
		}
		else {
			new xmlRequest(url, method, asyncRequest, callback);
		}
		
		function getPhoto(response) {
			
			//Get xml list of photos
			try {
				var photosList = response.getElementsByTagName('photos');
				var total = (photosList[0].getAttribute('total'));
				var photos=response.getElementsByTagName('photo');
			}
			catch (err) {
			}
			
			//Clear loading image
			var loadingId = 'loadingimg' + idWord;
			if (document.getElementById(loadingId)) {
				var loadingImage = document.getElementById(loadingId);
				//If no photos replace loading image with no photos image
				if (total) {
					if (total == 0) {
						loadingImage.setAttribute('src', 'images/noimage.gif');
						loadingImage.setAttribute('alt', "Unknown");
						loadingImage.setAttribute('title', "Flickr has no images tagged with the word '" + word + "'");
						progressUpdate(0, 1);
					}
				}
			}
				
			//Get individual photo urls
			if (photos) {
				var photoTotal = photos.length;
				for (i=0;i<photoTotal;i++) {
					var id = (photos[i].getAttribute('id'));
					var farmid = (photos[i].getAttribute('farm'));
					var secret = (photos[i].getAttribute('secret'));
					var serverid = (photos[i].getAttribute('server'));
					var title = (photos[i].getAttribute('title'));
					var userid = (photos[i].getAttribute('owner'));
					new makeImage(farmid, serverid, id, secret, title, userid, i, photoTotal);
				}
			}
		}
		
		function makeImage (farmid, serverid, id, secret, title, userid, photoNum, photoTotal) {

			//Get this request number
			requestCount = wordArray.length;
			wordArray[requestCount] = (idWord + photoNum);
			
			//Create small and medium size image urls
			var smallImageSrc = "http://farm"+farmid+".static.flickr.com/"+serverid+"/"+id+"_"+secret+"_s"+".jpg";
			var medImageSrc = "http://farm"+farmid+".static.flickr.com/"+serverid+"/"+id+"_"+secret+"_m"+".jpg";
			
			//Create image
			this.image = new Image();
			if (photoNum == 0) {
			this.image.src = smallImageSrc;
			}
			if (photoNum == 0) {
				this.imageMed = new Image();
				this.imageMed.src = medImageSrc;
			}
			this.image.className = ("flickrimg");
			this.image.onmouseover = ImageOnMouseOver;
			this.image.onmouseout = ImageOnMouseOut;
			
			imageArray[requestCount] = this.image;
			
			//Create image link
			imageLinkArray[requestCount] = document.createElement("a");
			imageLinkArray[requestCount].className = ("imagelink");
			imageLinkArray[requestCount].setAttribute("href","http://www.flickr.com/photos/" + userid + "/" + id);
			imageLinkArray[requestCount].setAttribute("target","_blank");
			imageLinkArray[requestCount].setAttribute("id", idWord + 'image');
			imageLinkArray[requestCount].setAttribute("title", word);
			
			//Add image to image link
			imageLinkArray[requestCount].appendChild(imageArray[requestCount]);
			
			//On image mouse over show medium image		
			function ImageOnMouseOver() {
				this.src = medImageSrc;
				this.className = ("imgover");
				this.width = "auto";
				this.height = "auto";
			}
					
			//On image mouse out return to small image		
			function ImageOnMouseOut() {
				//this.className = ('loadingimg');
				//this.src = 'images/load.gif';
				this.width = "auto";
				this.height = "auto";
				this.src = smallImageSrc;
				this.className = ('imgout');
			}
			
				
			//For the first image of photo list		
			if (photoNum == "0") {
				//When image is loaded
				this.image.onLoad = populatePoem(photoNum, photoTotal, idWord,  requestCount, word, firstLoad);
				
			}
			
		}
		
	}
	
}