String.prototype.replaceAll = function(strTarget,strSubString){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	while (intIndexOfMatch != -1){
		strText = strText.replace( strTarget, strSubString );
		intIndexOfMatch = strText.indexOf( strTarget );
	}
		return( strText );
};

$(document).ready(function(){
	if ($('#flickr').size()>0)
	{
		$.getJSON("http://api.flickr.com/services/feeds/photos_friends.gne?user_id=90921086@N00&friends=0&display_all=1&lang=fr-fr&format=json&jsoncallback=?", function(data){
	  		$.each(data.items, function(i,item){
	  			html = '<a href="'+item.link+'" target="_blank"><img src="' +  item.media.m.replaceAll('_m','_s') + '" alt="'+item.title +'"/></a>';
	  			$('#flickr').append(html);   			
	    			if ( i == 5 ) return false;
	  		});
		});
	
		$.get('proxy.php?url=http://ego.mouton-rebelle.com/tools/rss',
			function(data){

				$(data).children().children('item').each( function(i)
				{   
					title = $(this).children('title').text();	
					src = $($(this).children().get(5)).attr('url');	
					link = 'http://ego.mouton-rebelle.com';
					html = '<a href="'+link+'" target="_blank"><img width="75" height="75" src="' +  src + '" alt="'+ title +'"/></a>';
	  				$('#flickr').append(html);   			
	    				if ( i == 2 ) return false;
				}
				);
		
			}
		
	);
	
	}
	$('#right .article').hide();
	
	$('form#pure select').change(function(){
		if ($(this).val())
		{
			id = $(this).attr('id');
			if (id == 'auteur') $('#mot').val(''); else $('#auteur').val('');
			url = '/spip.php?page=json&id_' + id + '=' + $(this).val();			
			base = $('#pureArticles .article').eq(0);
			$('#pureArticles .article').remove();
			$('#pureArticles').addClass('loading');
			$.getJSON(url, function(data){
				$('#pureArticles').append(base);
				$('#pureArticles').autoRender(data);
				$('#pureArticles').removeClass('loading');
	   			$('#right .article').show(); 
			});

		}
	});	
});