// File: readXML.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the NewsHour file
	$.get("/newshour/rss/rss_vote2008.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea").append(myHTMLOutput);
	});

	// Open the Rocky Mountain PBS file
	$.get("/vote2008/0.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea2").append(myHTMLOutput);
	});

	// =============================================================
	// Open the Twin Cities Public Television file
	// =============================================================
	$.get("/vote2008/1.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea3").append(myHTMLOutput);
	});

	// =============================================================
	// Open the Minnesota Public Radio file
	// =============================================================
	$.get("/vote2008/2.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea4").append(myHTMLOutput);
	});

	// =============================================================
	// Open the Tavis Smiley file
	// =============================================================
	$.get("/kcet/tavissmiley/rss/voices.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea5").append(myHTMLOutput);
	});

	// =============================================================
	// Open the BallotVox file
	// =============================================================
	$.get("/vote2008/5.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea6").append(myHTMLOutput);
	});

	// =============================================================
	// Open the NPR file
	// =============================================================
	$.get("/vote2008/4.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea7").append(myHTMLOutput);
	});

	// =============================================================
	// Open the Public Interactive file
	// =============================================================
	$.get("/vote2008/3.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea8").append(myHTMLOutput);
	});

	// =============================================================
	// Open the PRI’s The World file
	// =============================================================
	$.get("/vote2008/6.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea9").append(myHTMLOutput);
	});

	// =============================================================
	// Open the Frontline/World file
	// =============================================================
	$.get("/frontlineworld/election2008/rss.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea10").append(myHTMLOutput);
	});
	// =============================================================
	// Open the KPBS file
	// =============================================================
	$.get("/vote2008/8.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table width="480" border="0" cellpadding="2" cellspacing="2">';
	  	//myHTMLOutput += '<th>Title</th><th>Link</th>';
	  	
		// Run the function for each student tag in the XML file
		$('item',xml).each(function(i) {
			if (i == 5) {
				return false;
			}
			rssTitle = $(this).find("title").text();
			rssLink = $(this).find("link").text();
			//studentPhone = $(this).find("phone").text();
			//studentSSN = $(this).find("ssn").text();
			//studentPost = $(this).find("name").attr("post"); 
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(rssTitle,rssLink);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea11").append(myHTMLOutput);
	});
	
	
	
	

});
 
 
 
 function BuildStudentHTML(rssTitle,rssLink){
	

	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td><a href="'+ rssLink + '" target="_blank">' + rssTitle + '</a></td>';
	output += '</tr>';
	output += '<tr><td><div class="in5"></div></td></tr>';
	return output;
}
	 