$(function() {
	
	months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	
	function formatDate(string) {
		var d = new Date(string);
		var output = months[d.getMonth()]+' '+d.getDate()+', '+d.getFullYear();
		return output;
	}
	
	function formatDescription(string) {
		if ( string.length >= 90 ) {
			return string.substr(0,90) + '...';
		} else return string;
	}
	
	function formatTitle(string) {
		if ( string.length >= 34 ) {
			return string.substr(0,34) + '...';
		} else return string;
	}
	
	function filter_links(holder) {
		holder.find('a[href^=http://dfmnews.wordpress.com]').click(function(e) {
			this.href = 'news.html#'+this.href
		});
	}
		
	$('#news1').jParse({
		precallback:function() {
			$('#news1').hide();
		},
		callback:function() {
			$('#news1').fadeIn('slow');
			filter_links($('#news1'));
			
			$('#news2').jParse({
				precallback:function() {
					$('#news2').hide();
				},
				callback:function() {
					$('#news2').fadeIn('slow');
					filter_links($('#news2'));
				},
			    ajaxOpts: {url: 'feeds.php?feed=user-group'},
				elementTag:[{elem:'title',format:formatTitle},{elem:'pubDate',format:formatDate},{elem:'link'},{elem:'description',format:formatDescription}],
				output:'<span>jpet1</span><br /><a href="jpet2" target="_blank">jpet0</a><br />jpet3<br /><br />',
				limit: 1
			});
			
		},
	    ajaxOpts: {url: 'feeds.php?feed=news'},
		elementTag:[{elem:'title',format:formatTitle},{elem:'pubDate',format:formatDate},{elem:'link'},{elem:'description',format:formatDescription}],
		output:'<span>jpet1</span><br /><a href="jpet2" target="_blank">jpet0</a><br />jpet3<br /><br />',
		limit: 1
	});
		

});

