function getUrlParam(str)
{
	if(typeof str != 'string')return null;//If not string return null
	var sLoc = (arguments.length == 2) ? arguments[1].split('?') : window.location.toString().split('?');//Get url and split it according to '?'
	
	if(sLoc.length == 1)return null;//If there are no parameters in url return null
	
	var params = sLoc[1].split('&');//Get url params array
	
	for(var i = 0; i < params.length; i++)//Loop through url params
	{
		if(params[i].match(new RegExp(str + '=','gi')) != null)return decodeURIComponent(params[i].split('=')[1]);//If found return it
	}
	
	return null;//Return null
}


function loadFeedinList(result)//Loads the first entry in a feed into the element which is the context upon this function is called
{
	jQuery(document).ready(function(){
	
		var pageFeed = $('#footer');
			
		if(!result.error && (result.feed.entries.length > 0)) {//If there is no error and
			var nLength = (result.feed.entries.length > 4) ? 4 : result.feed.entries.length;
			pageFeed.html('');
			for(var i = 0; i < nLength; i++)
			{
				
				var entry = result.feed.entries[i];
				var oFeed = $('<div class="info"></div>').appendTo(pageFeed);
				
				/*console.log(entry);*/
				
				var title = (entry.title.length > 70) ? (function(){var tempEntry = entry.title.substr(0,70); return tempEntry.substr(0,tempEntry.lastIndexOf(' ')) + ' ...';})() : entry.title;
				oFeed.html('<h3><strong>' + $.trim(title) + '</strong></h3>');
				$('<p class="date">' + $.trim(entry.publishedDate.replace(/(\d+:\d+:\d+)|(-\d+)/gi,'')) + '</p>').appendTo(oFeed);
				
				var snippet = (entry.contentSnippet.length > 55) ? (function(){var tempSnippet = entry.contentSnippet.substr(0,55); return tempSnippet.substr(0,tempSnippet.lastIndexOf(' ')) + ' ...';})() : entry.contentSnippet;
				$('<p>' + $.trim(snippet) + '</p>').appendTo(oFeed);
				
				var sId = getUrlParam('ID',entry.link.toString());
				var sLink = (typeof sId == 'string' && sId.length > 0) ? ('/feed-entry?PAGEID=' + sId) : $.trim(entry.link);
				
				$('<p><a target="_blank" href="' + sLink + '">Read more</a></p>').appendTo(oFeed);
				
			}
					
		} else {
			pageFeed.html('<p>There has been an error loading this feed. Please reload the page.<p>');	
		}	
	});
}
	
function initialize() {

	
	
	var feed01 = new google.feeds.Feed("http://wilhelmsen.prettypollution.com/RSSRetrieve.aspx?ID=5389&Type=RSS20");
	feed01.load(loadFeedinList);
	
}

google.load("feeds", "1");

google.setOnLoadCallback(initialize);
