		function unique(ar){
			var targetArray = [];
			if(ar.length){
				targetArray.push(ar[0]);
			}
			for(var q = 0; q < ar.length; q++){
				if(targetArray[targetArray.length-1]!=ar[q]){
					targetArray.push(ar[q]);
				}
			}
			return targetArray;
		}
		
		var addCategories = function(){
			var archiveCategories = ["Agile methodology","Android","CMS","Drupal","IT trends","Linux","Mobile","Web 2.0","Web development"];
			$("#byCategory li").remove()
			for(m=0; m<archiveCategories.length; m++){
				$("#byCategory").append('<li><a href="#'+archiveCategories[m]+'" class="category" id="'+archiveCategories[m]+'">'+archiveCategories[m]+'</a></li>').show('slow');
			}
			
			$("#byCategory").append('<li><a href="#all_categories" class="categoryAll categorySelected" id="categoryAll">View All</a></li>').show('slow');
			
			$(".category").click(function(){				
				$(".categorySelected").removeClass("categorySelected");
				$(".sort").removeClass("sortSelected");
				$(".sortAll").addClass("sortSelected");
				$(this).addClass("categorySelected");
				loadAllFeeds($(this).attr("id"));
				return false;
			});
			
			$(".categoryAll").click(function(){
				$(".categorySelected").removeClass("categorySelected");
				$(".sortAll").addClass("sortSelected");
				$(".categoryAll").addClass("categorySelected");
				loadAllFeeds();
				return false;
			});
		}
		
		var filterFn = function(target){
			$(".sortSelected").removeClass('sortSelected');
			$("#feedListing div.newsItem[rel='"+$(target).attr("id")+"']").show();
			$(".category").removeClass("categorySelected");
			$(".categoryAll").addClass("categorySelected");		
			$("#"+target.id).addClass('sortSelected');
		}		
		
		var archiveMonths = [];
		var AMcheck = 0;
		
		var hasMonth = function(arr,item){
			for(var i=0;i<arr.length;i++){
				if(arr[i]==item){ 
					return true;
				}
			}
			return false;
		}
		
		var loadAllFeeds = function(source,filter){
			var base = 'http://www.google.com/reader/public/atom/user/18256921251369292027/';
			if(!source){
				source = base+"state/com.google/broadcast";
			} else {
				source = base+"label/"+source;
				AMcheck = 1;
			}
			
			jQuery.getFeed({
					url: 'js/proxy.php?url='+source+'?q='+Math.random(),
					success: function(feed) {
						var html='';
						var items = [];
						//var archiveCategories = ["Agile Development","Android","CMS","Drupal","IT trends","Linux","Mobile","Web 2.0","Web development"];
						
						var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
						var monthsLong = ["January","February","March","April","May","June","July","August","September","October","November","December"];

			            if(!feed.items.length){
			            	return false;
			            }

						for(var i = 0; i < feed.items.length; i++) {
            
			                var item = feed.items[i];
						
							var date = item.updated.split("-");
							item.year = date[0];
							item.month = date[1];
							item.day = date[2].split("T")[0];
							
							item.orderDate = new Date(item.year,(item.month-1),item.day);
							
							item.title = item.title.replace("'","");
							item.title = item.title.replace("&amp;apos;","'");
							item.description = item.description.replace("'","");
							item.description = item.description.replace("&amp;apos;","'");
							item.description = item.description.replace(/<[a-zA-Z\/][^>]*>/g,"");
							
							items.push(item);
			            }
			            			
			            items.sort(byDate);
			            for(var i=0; i<items.length; i++){
			            	var currentItem = items[i];
			            	html += '<div class="newsItem" rel="'+monthsLong[parseInt(currentItem.month,10)-1]+currentItem.year+'">';
							html += '<span class="newsDate">'+currentItem.day+" "+months[parseInt(currentItem.month,10)-1]+" "+currentItem.year+'</span>';
							html += '<a class="newsTitle" title="Continue reading: '+currentItem.title+'" target="_blank" href="'+currentItem.link+'">'+currentItem.title+'</a>';
							html += '<p class="newsBody truncate">'+currentItem.description+'</p></div>';						
						
							//Pushing Months+Years
							var currentDate = monthsLong[parseInt(currentItem.month,10)-1]+" "+currentItem.year;
							
							if(!hasMonth(archiveMonths,currentDate) && !AMcheck){
								archiveMonths.push(currentDate);
							}

			            }
			            			            
						$('#feedListing').html(html);
						$('.truncate').truncate(500);
						
						archiveMonths = unique(archiveMonths);
						
						$("#byMonth li").remove();						
						for(var m=0; m<archiveMonths.length; m++){
							$("#byMonth").append('<li><a href="#_'+archiveMonths[m].replace(" ","")+'" class="sort" id="'+archiveMonths[m].replace(" ","")+'">'+archiveMonths[m]+'</a></li>').show('slow');
						}

						//sort all
						$("#byMonth").append('<li><a href="#" class="sortAll sortSelected" id="sortAll">View All</a></li>').show('slow');
						
						$(".sort:not(.sortSelected)").click(function(){
							var _self = this;
							loadAllFeeds(null,function(){filterFn(_self)});
						});
						
						$(".sortAll").click(function(){
							$(".sortSelected").removeClass('sortSelected');
							//$("#feedListing div.newsItem:hidden").fadeIn('normal');
							$("#feedListing div.newsItem:hidden").show();
							$(this).addClass('sortSelected');
						});
						
						if(filter){
							filter();
						} else {
							$("#feedListing div.newsItem").show();
						}
					}	
			});
		}

		var startComplete = function(){
				$.ajaxSetup({
					global: true,
					beforeSend: function(){
		   				$("#feedListing div.newsItem").hide();
		   				$("#loading").show();
					},
					complete: function(){
		   				$("#loading").hide();
					}
				});
		}
				