function sortEntries(xml, element, authorFilter) {
		var blogEntry = [];
		var blogPosts = [];
		
		var count;
		var entryCount;
		
		var blogID;
		var blogName;
		var blogURL;
		var blogIMG;
		var blogAuthorName;
		var blogEntryTitle;
		var blogEntryID;
		var blogEntryDate;
		var blogEntryImage;
		
	$(xml).find("Blog").each(function(blogIndex){
		count = $(this).find("BlogEntries").find("BlogEntry").length;
		blogURL = $(this).attr("BlogURL");
		blogID = $(this).attr("BlogID");
		blogIMG = $(this).attr("BlogImageURL");
		blogEntryURL = $(this).attr("BlogEntryURL");
		
		blogName = $(this).attr("BlogName");
		if ( blogName.search(" //") != -1) {
			blogName = blogName.slice( 0 , blogName.search(" //"));
		}
		
				
		//LOOPS BLOG ENTRIES + STORES ENTRY DATA INTO MASTER ARRAY
		$(this).find("BlogEntries").find("BlogEntry").each(function(e){
			entryCount = blogEntry.length;
			blogEntryTitle = $(this).attr("EntryTitle");
			blogEntryID = $(this).attr("BlogEntryID");
			blogEntryDate = $(this).attr("UTCDateTimePublished");
			blogEntryImage = $(this).find("Images").find("Image").attr("ReducedImageURL");
			blogAuthorName = $(this).attr("AuthorName");
			
			//console.log("Blog: " + blogName);
			
			//MASTER ARRAY
			blogEntry[entryCount] = new Array(blogEntryTitle, blogID, blogIMG, blogEntryURL, blogName, blogEntryID, blogEntryDate, blogEntryImage, blogAuthorName);

							});
							
						});
						//console.log(entryCount);
						
						blogEntry.sort(function(a, b){
							a = a[6]+a[0];
							b = b[6]+b[0];
							
							return a == b ? 0 : (a < b ? 1 : -1);
						});
						
						
						
						//LOOPS THROUGH EVERY ENTRY WITHIN FEED
						for (i=0; i < blogEntry.length; i++) {
							
							//Set Dynamic Regular expression for Author Match
							var authorMatch = new RegExp(authorFilter, 'gi');
							
							//COLLECTS ENTRY PARAMETERS
							var entryTitle = blogEntry[i][0];
							var entryID = blogEntry[i][5];
							var pubDate = blogEntry[i][6];
							var entryIMG = blogEntry[i][7];
							var entryURL = blogEntry[i][3];
							var authorName = blogEntry[i][8];

							//Convert EMMIS UTC Date to a Readable timestamp using date.js
							pubDate = Date.parse(pubDate.slice(0, pubDate.search(/\T/gi)));
							//console.log(pubDate);
							pubDate = pubDate.toString('ddd, MMM d, yyyy');
							
							
							//COLLECTS BLOG PARAMETERS
							var blogName = blogEntry[i][4]; 
							var ID = blogEntry[i][1]; 
							var IMG = blogEntry[i][2];
							
							
							//If authorFilter is set to All authors (all OR ALL OR All) then it will display all entries
							if (authorFilter == "all" || authorFilter == "All" || authorFilter == "ALL") {
								$("ul#" + element).append("<li class=" + blogName.toLowerCase() + "><span class=\"latest-blog-thumbnails\"><img src=\"" + IMG + "\" /></span><span class=\"latest-blog-text-info\"><a href=\"" + entryURL + "?BlogEntryID=" + entryID + "\">" + entryTitle + "</a><br />" + authorName + " // " + blogName + "<br />" + pubDate + "</span></li>");
							} 
							
							//If authorFilter isn't set to All then it will only display entries matching the authorFilter
							else if (authorName.search(authorMatch) != -1) {
								$("ul#" + element).append("<li class=" + blogName.toLowerCase() + "><span class=\"latest-blog-thumbnails\"><img src=\"" + IMG + "\" /></span><span class=\"latest-blog-text-info\"><a href=\"" + entryURL + "?BlogEntryID=" + entryID + "\">" + entryTitle + "</a><br />" + authorName + " // " + blogName + "<br />" + pubDate + "</span></li>");
							}	
													
						}
						
						//No Matches then display all blog links
						if ($("ul#" + element + " li").length <= 0) {
								$("ul#" + element).append("<p class=\"largeheader\"><strong>Sorry. No recent matches found. Please browse through our different Blogs.</strong></p>" + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001330/eagles-001.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/eagles/home.aspx\">Eagles // NFL</a><br />All the Latest Eagles Information</span></li>"
 + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001331/phillies.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/phillies/home.aspx\">Phillies // MLB</a><br />All the Latest Phillies Information</span></li>"
 + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001332/flyers.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/flyers/home.aspx\">Flyers // NHL</a><br />All the Latest Flyers Information</span></li>"
 + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001333/sixers.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/sixers/home.aspx\">76ers // NBA</a><br />All the Latest 76ers Information</span></li>"
 + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001334/ncaa.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/college/home.aspx\">Collegiate Sports // NCAA</a><br />All the Latest Collegiate Sport Information</span></li>"
 + 
 "<li><span class=\"latest-blog-thumbnails\"><img src=\"http://origin-www.975thefanatic.com/Pics/Blogs/1001335/generic.gif\" /></span><span class=\"latest-blog-text-info\"><a href=\"http://origin-www.975thefanatic.com/teams/phillies/home.aspx\">News // All</a><br />All the Latest 97.5 The Fanatic Information</span></li>"
 
 );
						}
					}

function getAuthorBlogs(element, authorFilter, blog_ID_Query) {
		payload = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 
		' xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ' +
		 ' <soap:Body> ' +
		   '  <GetXMLBlogsContent xmlns="http://www.emmisinteractive.com/"> ' +
		   '   <BlogIDs>' + blog_ID_Query + '</BlogIDs> ' +
		   '   <NumberOfItems>' + "50" + '</NumberOfItems>' +
		   '   <StartDate></StartDate> '+
			'</GetXMLBlogsContent>'+
		 ' </soap:Body>'+
		'</soap:Envelope>';

		$.ajax({
			   type:'POST',
			   url:'http://www.975thefanatic.com/_shared/content/public/blogservice.asmx?op=GetXMLBlogsContent',
			   dataType:"xml",
			   contentType: "text/xml; charset=\"utf-8\"",
			   data:payload,
			   success: function(xml){
				sortEntries(xml, element, authorFilter);
				//$("ul#" + element).append(xml);
				$("div.contentblock_m01 ul.latest-author-blogs li:odd").addClass("alt");
			   },
			   error: function() {
					console.log("Error");
				}
			   }, "xml");
	}


$(document).ready(function() {
				   					
		$("ul.latest-author-blogs").each(function(i) {
			var listID = $(this).attr("id");
			var listTitle = $(this).attr("title");
			switch (listTitle) {
				case "Villanova":
					blog_ID_Query = "1001334";
					break;
				case "Madee":
					blog_ID_Query = "1001336";
					break;
				case "Cumberland":
					blog_ID_Query = "1001336";
					break;
				case "Seltzer":
					blog_ID_Query = "1001330";
					break;
				case "Paolantonio":
					blog_ID_Query = "1001330";
					break;
				case "DeCamara":
					blog_ID_Query = "1001330,1001331,1001333";
					break;
				case "This Week in Pro Football":
					blog_ID_Query = "1001330";
					break;
				case "Stark":
					blog_ID_Query = "1001331";
					break;
				default:
					blog_ID_Query = "1001330,1001331,1001332,1001333,1001334,1001335";
					break;
				
			}
			
			getAuthorBlogs(listID, listTitle, blog_ID_Query);
			
		});

});	

/*Blogs with IDs

Phillies - 1001331
Eagles - 1001330
Flyers - 1001332
Sixers -1001333
NCAA - 1001334
News - 1001335
Lifestyle - 1001336
***************8*/

