// get a feed and populate it in the #feed on page
// argument is the complete feed url
var feed_get_url = function( asURL )
{
	$("#feed").feed({
		url : asURL,
		count : 3,
		complete: function(html)
		{
			// populate the feed
			$('#feed').html(html);
			
			// links open in the new tab/window
			$("#feed p > a").attr('target','_blank');
			
			// modify the items
			var i = 0; // item counter
			// for each item
			$("#feed .item").each(function()
			{
				// provide id to item
				$(this).attr('id', 'feeditem'+i);
				// format the meta date
				var oMeta = $("#feeditem" + i + " .meta");
				oMeta.html(oMeta.html().replace('+0000',''));
				// provide id to body
				$("#feeditem" + i + " .body").attr('id','itembody'+i);
				// hide the body
				$("#itembody" + i).toggleClass('hidden');
				// increase the counter
				i++;
			});
			
			// attach click to items
			$("#feed .item").click(function()
			{
				// toggle the body hide
				var id = $(this).attr('id');
				id = id.substring(8);
				$("#itembody" + id).toggleClass('hidden');
			});
			
			// unhide the feed
			$("#feed").toggleClass('hidden');
		}
	});
}
// get a feed and populate it in the #feed on page
// url is built from server, group and item
var feed_get = function( asServer, asGroup, asItem )
{
	feed_get_url( 'http://'+ asServer + '/drommeholdet/sportenproxy.php?group=' + asGroup + '&item=' + asItem );
}

