$(document).ready(function() {
	loadBloc1();
	loadBloc2();
});

function loadBloc1() {
	$("#bloc1Elements").empty();
	if ($('#bloc1RssFeedUrl').val()) {
		$.get($('#bloc1RssFeedUrl').val(), function(d) {
		var counter=0;
			$(d).find('item').each(function() {
				var $item = $(this);
				var title = $item.find('title').text();
				var link = $item.find('link').text();
				var description = $item.find('description').text();
				var imageUrl = $item.find('[nodeName=media:content]').attr("url");
				
				var html ="";
				if (counter!=0) {
					html += "<li><hr></li>";
				}
				counter = counter +1;
				
				html += "<li><div class=\"image\"><img src=\""+imageUrl+"\"></div>";
				html += "<div class=\"details\">";
				html += "<p><a href=\""+link+"\">"+title+"</a></p>";
				html += "<p>"+description+"</p>";
				html += "</div></li>";
				
				$('#bloc1Elements').append($(html));  
			});
		});
	}
};

function loadBloc2() {
	$("#bloc2Elements").empty();
	if ($('#bloc2RssFeedUrl').val()) {
		$.get($('#bloc2RssFeedUrl').val(), function(d) {
		var counter=0;
			$(d).find('item').each(function() {
				var $item = $(this);
				var title = $item.find('title').text();
				var link = $item.find('link').text();
				var description = $item.find('description').text();
				var imageUrl = $item.find('[nodeName=media:content]').attr("url");
				
				var html ="";
				if (counter!=0) {
					html += "<li><hr></li>";
				}
				counter = counter +1;
				
				html += "<li><div class=\"image\"><img src=\""+imageUrl+"\"></div>";
				html += "<div class=\"details\">";
				html += "<p><a href=\""+link+"\">"+title+"</a></p>";
				html += "<p>"+description+"</p>";
				html += "</div></li>";
				
				$('#bloc2Elements').append($(html));  
			});
		});
	}
};
