

CmdUtils.CreateCommand({
	names: ["news"],  
	icon: "http://www.bennythemink.com/bennythemink.ico",
	description: "Returns the latest posts for the selected feed vendor.",
	help: "Type 'news' and select the vendor from the list to display the latest headlines/post. Click on any headline to open the post in a new tab.",
	author: {name: "Benny Sheerin", email: "bennysheerin@yahoo.ie"},
	license: "GPL",
	homepage: "http://www.bennythemink.com/",
	arguments: [{role: 'object', nountype: ["bbc","cnn","digg","smashing","kohana"], label: "feed to list"}],

	preview: function preview(pblock, args) {
	
		// news feed sources
		var sources = new Array();
		sources['bbc'] = 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml';
		sources['cnn'] = 'http://rss.cnn.com/rss/edition.rss';
		sources['digg'] = 'http://digg.com/rss/index.xml';
		sources['smashing'] = 'http://feeds.feedburner.com/SmashingMagazine';
		sources['kohana'] = 'http://forum.kohanaphp.com/search.php?PostBackAction=Search&Type=Comments&Feed=RSS2';
		
		
		if(args.object.text in sources) // checks if the key is in the associative array.
		{
			// call to get specified RSS feed
			jQuery.ajax({
				type: "GET",
				url: ""+sources[args.object.html],
				data: '',
				dataType: "xml",
				
				error: function(){ 
					displayMessage(args.object.text + " Error");
				},
				
				success: function(response){
					//parseRSS(pBlock,response); 
					parseRSS(response,pblock);
				}
			});
			
			pblock.innerHTML = "Your input is <b>" + args.object.text + "</b>. ";
		}
		
	},


	execute: function execute(args) {
		displayMessage("You selected: " + args.object.html+ " penis", this);
	}

});

function testing(re,bloc){displayMessage("yip "+bloc);}


function parseRSS(xml,previewBlock)
{
	//var $ = window.jQuery;
	
	var pre = "";
	
	$(xml).find('item').each(function()
	{
	  pre += "<a href='"+$(this).find('link').text()+"'>"+$(this).find('title').text()+"</a><br/>";
	}
	);
	
	previewBlock.innerHTML = pre;
}
