﻿/*
------------------------
Hämta poster från RSS eller Atom via JQuery
------------------------
*/

function getFeed(url, target_id, include_description, target, css_class, loading_image_name){
    
    //loading image
    var loading_image;
    if(loading_image_name){loading_image=loading_image_name;}
    else{loading_image="loader.gif";}
	$('#'+target_id).html('<img src=\"images/ajax/'+loading_image+'\" alt=\"Laddar...\" title=\"Laddar...\" style=\"margin-bottom:1em;padding-top:0.5em;\" />');
	 
	 //use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	$.get(url, function(d) {
		   
		$('#'+target_id).empty();
		
		//does element exist?
		if($(d).find('item').length==0){
		    //no feed
		    var p=document.createElement("p");
		    p.className="no_margin";
		    p.innerHTML="&nbsp;";
		    $('#'+target_id).append(p);
		}
		
		var ul=document.createElement("ul");
		
		//css
	    if(css_class){ul.className=css_class;}
	    else{ul.className="blogroll";}
 
		//find each 'item' in the file and parse it
		$(d).find('item').each(function() {
 
			//name the current found item this for this particular loop run
			var $item = $(this);
			
			a=document.createElement("a");
			a.setAttribute("href", $item.find('link').text());
			a.innerHTML=$item.find('title').text();
			if(target){a.setAttribute("target", target);}
			li=document.createElement("li");
			ul.appendChild(li);
			li.appendChild(a);
 
			//put that feed content on the screen!
			$('#'+target_id).append(ul); 
			
		});
	});
}
