// File: readXML.js

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

	// Open the post.xml file
	$.get("http://blog.haileyfrances.com/rss.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<dl>';
	  	
	  	i=0;
		// Run the function for each post tag in the XML file
		$('entry',xml).each(function(i) {
			titleblog = $(this).find("title").text();
			postlinkblog = $(this).find("[rel='alternate']").attr("href");
			nameblog = $(this).find("name").text();
			infoblog = $(this).find("content").text();
		
			if(i<1){
				mydata = BuildStudentHTML(titleblog,nameblog,infoblog,postlinkblog);
				myHTMLOutput = myHTMLOutput + mydata;
				i++;
			}
			else{
				return false;
			}
		});
		myHTMLOutput += '</dl>';
		
		// Update the DIV called Content Area with the HTML string
		$("div.blogoutput").append(myHTMLOutput);});

//video blog
$.get("http://videoblog.haileyfrances.com/atom.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<dl>';
	  	i=0;
		// Run the function for each post tag in the XML file
		$('entry',xml).each(function(i) {
			title = $(this).find("title").text();
			postlink = $(this).find("[rel='alternate']").attr("href");
			name = $(this).find("name").text();
			info = $(this).find("content").text();
		
			if(i<1){
		
			mydata = BuildVideoHTML(title,name,info,postlink);
			myHTMLOutput = myHTMLOutput + mydata;
			i++;
			}
			else{
				return false;
			}
			
		});
		myHTMLOutput += '</dl>';
		
		// Update the DIV called Content Area with the HTML string
		$("div.videoblogoutput").append(myHTMLOutput);});
	});
 function BuildStudentHTML(title,name, content,postlink){
	

		studentPostHTML = "";
	
	
	// Build HTML string and return
	output = '';
	
	output += '<dt><a href="' + postlink + '">' + title + '</a></dt>';
	output += '<dd>';
	if (content.length > 850)
		output += content.slice(0,850) + '...<a href="' + postlink + '">read more</a></div></dd>';
	else
		output += content + '</dd>';
	return output;
}

function BuildVideoHTML(title,name, content,postlink){
	

		studentPostHTML = "";
	
	
	// Build HTML string and return
	output = '';
	
	output += '<dt class="video"><a href="' + postlink + '">' + title + '</a></dt>';
	output += '<dd class="video">'+ content + '</dd>';
	return output;
}