var count = 4;

function loadFeedOld(rssFeed) {
	var xmlDoc;
	try {
		if (window.ActiveXObject) {
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load(rssFeed);
		} else if(window.XMLHttpRequest) {
			var errorHappendHere = "Error handling XMLHttpRequest request";
			var d = new XMLHttpRequest();
			d.open("GET", rssFeed, false);
			d.send(null);
			xmlDoc=d.responseXML;
		} else {
			var errorHappendHere = "Error.";
			xmlDoc = document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load(rssFeed);
		}
		parseFeed(xmlDoc);
	} catch(e) {
		alert(errorHappendHere);
	}
}

function loadFeed(xml, style){
	$.ajax({type:"GET", url:xml, dataType:'xml', success:function(xmlData){parseFeed(xmlData, style);}});
}

function parseFeed(doc, style){
	var c = 0;
	var output = '';
	var total = $('item', doc).length;
	if (count>total){
		count = total;
	}
	$(doc).find('item').each(function(){
		var item = $(this);
		var month = item.find('month').text();
		var date = item.find('date').text();
		var text = item.find('text').text();
		if (c<count){
			if (style == 'wide'){
				output += buildItemWide(month, date, text);
			} else {
				output += buildItem(month, date, text);
			}
		}
		c++;
	});
	document.getElementById('feed').innerHTML = output;
	
}

function buildItemWide(month, date, text){
	var string = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr valign="top"><td width="60"><div style="padding-right:10px;"><div><div id="creditCrisis"><div class="calendar"><div class="month">'+month+'</div><div class="day">'+date+'</div></div> <!-- end calendar --></div> <!-- end creditCrisis --></div></div></td><td><div><div class="tt"><div class="articleText">';
	string += text;
	string += '</div> <!-- end articleText --></div></div></td></tr></table><div><div class="padTop4"></div></div><div><div class="dotted1px"><img src="http://cache.boston.com/bonzai-fba/File-Based_Image_Resource/spacer.gif" width="1" height="1" border="0" alt="" /></div></div>';
	return string;
}

function buildItem(month, date, text){
	var string = '<table cellpadding="0" cellspacing="0" border="0" width="377"><tr valign="top"><td width="60"><div style="padding-right:10px;"><div><div id="creditCrisis"><div class="calendar"><div class="month">'+month+'</div>';
	string += '<div class="day">'+date+'</div></div> <!-- end calendar --></div> <!-- end creditCrisis --></div></div></td><td width="317"><div><div class="tt"><div class="articleText">';
	string += text
	string += '</div> <!-- end articleText --></div></div></td></tr></table><div><div class="padTop4"></div></div>';
	string += '<div><div class="dotted1px"><img src="http://cache.boston.com/bonzai-fba/File-Based_Image_Resource/spacer.gif"                      width="1" height="1" border="0" alt="" /></div></div>'
	return string;
}