(function(jQuery) {                                          // Compliant with jquery.noConflict()
jQuery.fn.mcTagCloud = function(chanId, o) {
	// Default values
	o = jQuery.extend({
		id				: 54,
		container		: '#mcTagBody',

//		link			: 'mc_getTagsXML.php?id=',
		link			: '/dynamic/rsstv.php?rss=tag&id=',
		searchLink		: 'http://www.sportweek.fr/dynamic/rsstv.php?rss=search&tag='
	}, o || {});

	var self = this;

	return this.each(function() {		// Returns the element collection. Chainable.

		if (chanId) o.id = chanId;

		loadData(o.id);

	});		// each

	function loadData(chanId) {
			jQuery.ajax({
				type: "GET",
				url: o.link + chanId,
				dataType: "xml",
				timeout: 20000,
				success: function (serverData, textStatus) {
					drawTagXML(serverData);
//					var toto=0;
				},		//close Success

				error: function (XMLHttpRequest, textStatus, errorThrown) {
					alert('Error loading list: '+textStatus + '\n' + errorThrown + '\n'
						+ unescape( buildUrl(chanId))
					);
				}		//close Error
			});		//close $.ajax
	}

	function drawTagXML(data) {
//		if (!data) return;

		// Create cloud content
		var tagContent = '';

		jQuery(data).find('item').each(function() {
			var rank = jQuery(this).find('description').eq(0).text();
			var value = jQuery(this).find('title').eq(0).text();
			tagContent += '<span class="spTag' + rank + '">' + value + '</span> ';
//			tagContent += '<a href="' + o.searchLink + value + '" class="spTag' + rank + '" rel="tag">' + value + '</a>';
		});

		// Replace container content
		jQuery(o.container).empty().html(tagContent);
	}

/* ---------------------------- Helper functions ---------------------------- */

	function buildUrl(id) {
		url = o.link;
		return url + id;
	}

};

})(jQuery);