$(document).bind('pageinit', function(){
		
		var items;
		
		$.ajax({
			url : "http://localhost:8888/csiaf_plugin/?feed=rss2",
			method: "GET",
			dataType: "xml",
			success: function(data){
				
				items = $(data).find("item");
				
				var content = '';
				for (var i=0; i< $(items).length; i++){
					
					var newsEncoded = $( $(items[i]).find('encoded').text() );
					var imgSrc = $(".gallery li img:first", $(items[i])).attr("src");	
					content+= "<li><a href='#custom-post-page' class='entry-link' data-entryid="+i+"> "+
					 		  "<img src='"+imgSrc+"' class='ui-li-thumb'>"	
							  + $(items[i]).find("title").text() +"</a></li>";
					
					
				}			
				$("#news-list").html( content);
				$('#news-list').listview('refresh');
			},
			error: function (err){
				console.log(err);
				
			}
		});	
		
		$(document).on("click", ".entry-link", function(){
			var selectedId = $(this).data("entryid");
			var newsContent = "<h3>"+ $(items[selectedId]).find("title").text() +"</h3>";
			newsContent += "<img src='"+ $(items[selectedId]).find("img").attr('src') +"' style='width:100%;'></img>";
			newsContent += $(items[selectedId]).find("encoded").text();
			
			$("#entry-content").html( newsContent );
		});	
	
});