// JavaScript Document

$(document).ready(function(){


	// REMOVE THE LAST "|" IN THE FOOTER NAV

	$('.navbar-pages').each(function(){
		var x = $(this).html(); 
		lastComma = x.lastIndexOf("|");
		x = x.substring(0, lastComma);
		$(this).html(x);
	});


	// SELECTED STATE FOR THE NAVIGATION

	try {
		var hiddenNav = $(".hiddenNav").attr("id");
		$(".navbar li[class="+hiddenNav+"] a").addClass("selected");
	}
	catch(err){} 
	
	//Load XML Feed
	/* 
	   The following is not working on live site for some reason. 
		Still need to figure out why.
	*/
	/*
	//$.jGFeed('http://qa.globaladrenaline.net/xml.ashx?name=Blog',
	$.jGFeed('http://webview.mepco.com/mepconewsfeed.ashx',
		function(feeds){
			if(!feeds){
				return false;
			}
			//var l = feeds.entries.length < 5?feeds.entries.length:5;
			var c="";

			for(var i=0; i< feeds.entries.length; i++){
				var entry = feeds.entries[i];
				c+= "<h4>"+entry.title+"</h4>";
				c+= "<p>"+entry.content+"</p>";
				c += "<hr />";
			}
			$("#newsFeed").html(c);
		}, 10);
	*/
	/*
	  Temporary work around
	*/
	var newsFeedLimit = 10;
	$.ajax({
		type: "GET",
		url: "/assets/root/mepconewsfeedproxy.aspx",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('node').each(function(){
				if(newsFeedLimit <= 0)
					return;
				var title = '<h4>' + $(this).find('Title').text() + '</h4>';
				var description = '<p>' + $(this).find('Description').text() + '</p>';
				$('#newsFeed').append(title);
				$('#newsFeed').append(description);
				$('#newsFeed').append('<hr />');
				newsFeedLimit--;
			});
		}
	});
});

    

    

    

    

    

    
