
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 = jQuery('#home-feed').find('ul');
			
		if(!result.error && (result.feed.entries.length > 0)) {//If there is no error and
			jQuery('#home-feed').css('display','block');
			var nLength = (result.feed.entries.length > 4) ? 4 : result.feed.entries.length;
			
			for(var i = 0; i < nLength; i++)
			{
				
				var entry = result.feed.entries[i];
				//var oFeed = jQuery('<li></li>').attr('class','col').appendTo(pageFeed);
				var oFeed = pageFeed.find('li').eq(i);
				
				
				var title = (entry.title.length > 70) ? (function(){var tempEntry = entry.title.substr(0,70); return tempEntry.substr(0,tempEntry.lastIndexOf(' ')) + ' ...';})() : entry.title;
				oFeed.html('<p class="title">' + jQuery.trim(title) + '</p>');
				jQuery('<p class="date">' + jQuery.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;
				jQuery('<p>' + jQuery.trim(snippet) + '</p>').appendTo(oFeed);
				
				var sId = getUrlParam('ID',entry.link.toString());
				var sLink = (typeof sId == 'string' && sId.length > 0) ? ('/feed-entry?PAGEID=' + sId) : jQuery.trim(entry.link);
				
				jQuery('<a href="' + sLink + '" target="_blank">Read more</a>').appendTo(oFeed);
				
			}
					
		} else {
			pageFeed.html('<li>There has been an error loading this feed. Please reload the page.<li>');	
		}	
	});
}
	
function initialize() {

	
	
	var feed01 = new google.feeds.Feed("http://www.wilh.com.au/RSSRetrieve.aspx?ID=5389&Type=RSS20");
	feed01.load(loadFeedinList);
	
}

google.load("feeds", "1");

google.setOnLoadCallback(initialize);
