// blog_roll.js

google.load("feeds", "1");

// THIS IS THE FILTERING SCRIPT TO REMOVE INVALID CHARACTERS

function stringFilter (input) {
	var returnString = input;
	var i = 0;
	var characterArray = [	"�", "",
							"&ccedil;", "\u00E7",
							"&rsquo;", "\u0027",
							"&lsquo;", "\u0027",
							"&rdquo;", "\u201D",
							"&ldquo;", "\u201C",
							"&amp;", "\u0026",
							"&mdash;", "\u2014",
							"&nbsp;", " ",
							"&oslash;", "\u00F8"]; //these are the strings to swap
	
	for (i; i < characterArray.length; i = i+2){
		var regexToFind = new RegExp(characterArray[i], "gi");// regex constructor to find strings in feed text
		returnString = returnString.replace(regexToFind, characterArray[i+1]);
		};

	return returnString;
}


function initialize() {
	
	
// THIS LOADS THE FIRST FEED - ArchitectureBoston
	
	
  var bsa_custom_feed_1 = new google.feeds.Feed("http://architectureboston.com/feed/"); // this is the feed to fetch
  bsa_custom_feed_1.setNumEntries(1); //sets the number of entries for this feed
  
  bsa_custom_feed_1.load(function(result) {
  
  var filteredTitle = "";
  
	if (!result.error) {
	  var container = document.getElementById("bsa_custom_feed_1");
  
	  for (var i = 0; i < result.feed.entries.length; i++) {
  
		var entry = result.feed.entries[i];
		var attributes = ["title", "link", "contentSnippet"]; //these are the data pairs to fetch
		var div = document.createElement("div");
	
		for (var j = 0; j < attributes.length; j++) {
	
			var div = document.createElement("div"); // creates new feed entry
			var attribute_class = document.createAttribute("class"); //creates class name for feed entry
	
				switch(j) // this decides what to do when we receive a piece a data
				{
				case 0: // feed entry title
					filteredTitle = stringFilter(entry.title); // call function to filter odd characters
					
					attribute_class.nodeValue = "bsa_custom_feed_title";
					var div_link = document.createElement("a");
					var attribute_div_link = document.createAttribute("href"); //creates href value for title
					attribute_div_link.nodeValue = entry[attributes[j+1]]; // sets href to the feed link
					div_link.setAttributeNode(attribute_div_link); // adds the new href to the <a> tag
					div_link.appendChild(document.createTextNode(filteredTitle)); //add feed entry title text to the div
					div.appendChild(div_link); // add the constructed <a> tag to the entry div
					container.appendChild(div); // add the constructed div tag to the container div
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					break;
				case 1: // do nothing since we've reached the link data and we don't need to display that
					break;
				case 2: // feed entry snippet
					filteredSnippet = stringFilter(entry.contentSnippet); // call function to filter odd characters
				
					attribute_class.nodeValue = "bsa_custom_feed_snippet";
					container.appendChild(div);
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					div.appendChild(document.createTextNode(filteredSnippet));
					break;
				}
		}
	  }
	}
  });
	  
	  
// THIS LOADS THE SECOND FEED - Archinect
	  
	  
  var bsa_custom_feed_2 = new google.feeds.Feed("http://feeds.feedburner.com/archinect"); // this is the feed to fetch
  bsa_custom_feed_2.setNumEntries(1); //sets the number of entries for this feed
  
  bsa_custom_feed_2.load(function(result) {
  
  var filteredTitle = "";
  
	if (!result.error) {
	  var container = document.getElementById("bsa_custom_feed_2");
  
	  for (var i = 0; i < result.feed.entries.length; i++) {
  
		var entry = result.feed.entries[i];
		var attributes = ["title", "link", "contentSnippet"]; //these are the data pairs to fetch
		var div = document.createElement("div");
	
		for (var j = 0; j < attributes.length; j++) {
	
			var div = document.createElement("div"); // creates new feed entry
			var attribute_class = document.createAttribute("class"); //creates class name for feed entry
	
				switch(j) // this decides what to do when we receive a piece a data
				{
				case 0: // feed entry title
					filteredTitle = stringFilter(entry.title); // call function to filter odd characters
					
					attribute_class.nodeValue = "bsa_custom_feed_title";
					var div_link = document.createElement("a");
					var attribute_div_link = document.createAttribute("href"); //creates href value for title
					attribute_div_link.nodeValue = entry[attributes[j+1]]; // sets href to the feed link
					div_link.setAttributeNode(attribute_div_link); // adds the new href to the <a> tag
					div_link.appendChild(document.createTextNode(filteredTitle)); //add feed entry title text to the div
					div.appendChild(div_link); // add the constructed <a> tag to the entry div
					container.appendChild(div); // add the constructed div tag to the container div
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					break;
				case 1: // do nothing since we've reached the link data and we don't need to display that
					break;
				case 2: // feed entry snippet
					filteredSnippet = stringFilter(entry.contentSnippet); // call function to filter odd characters
				
					attribute_class.nodeValue = "bsa_custom_feed_snippet";
					container.appendChild(div);
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					div.appendChild(document.createTextNode(filteredSnippet));
					break;
				}
		}
	  }
	}
  });

	  
// THIS LOADS THE THIRD FEED - Architectural Record
	  
  var bsa_custom_feed_3 = new google.feeds.Feed("http://sitelife.construction.com/ver1.0/Blog/BlogRss?plckBlogId=Blog:ac946cd0-ba4a-4e0e-8da4-47c9e7c5d923"); // this is the feed to fetch
  bsa_custom_feed_3.setNumEntries(1); //sets the number of entries for this feed
  
  bsa_custom_feed_3.load(function(result) {
  
  var filteredTitle = "";
  var filteredSnippet = "";
  
	if (!result.error) {
	  var container = document.getElementById("bsa_custom_feed_3");
  
	  for (var i = 0; i < result.feed.entries.length; i++) {
  
		var entry = result.feed.entries[i];
		var attributes = ["title", "link", "contentSnippet"]; //these are the data pairs to fetch
		var div = document.createElement("div");
	
		for (var j = 0; j < attributes.length; j++) {
	
			var div = document.createElement("div"); // creates new feed entry
			var attribute_class = document.createAttribute("class"); //creates class name for feed entry
	
				switch(j) // this decides what to do when we receive a piece a data
				{
				case 0: // feed entry title
					filteredTitle = stringFilter(entry.title); // call function to filter odd characters
					
					attribute_class.nodeValue = "bsa_custom_feed_title";
					var div_link = document.createElement("a");
					var attribute_div_link = document.createAttribute("href"); //creates href value for title
					attribute_div_link.nodeValue = entry[attributes[j+1]]; // sets href to the feed link
					div_link.setAttributeNode(attribute_div_link); // adds the new href to the <a> tag
					div_link.appendChild(document.createTextNode(filteredTitle)); //add feed entry title text to the div
					div.appendChild(div_link); // add the constructed <a> tag to the entry div
					container.appendChild(div); // add the constructed div tag to the container div
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					break;
				case 1: // do nothing since we've reached the link data and we don't need to display that
					break;
				case 2: // feed entry snippet
					filteredSnippet = stringFilter(entry.contentSnippet); // call function to filter odd characters
				
					attribute_class.nodeValue = "bsa_custom_feed_snippet";
					container.appendChild(div);
					div.setAttributeNode(attribute_class); // adds class name attribute to entry div
					div.appendChild(document.createTextNode(filteredSnippet));
					break;
				}
		}
	  }
	}
  });
		 
}
	
	
// ALL DONE WITH FEED PROCESSING
	
	
google.setOnLoadCallback(initialize);