$(function() 
{$.ajaxSetup({cache: false});
var current = -1;
var data = '';
var total	= $('#friendsList').children().length;
$('#friendsList a').bind('click',function(e){
		var $this = $(this);
		show();
		var $elem	= $this.parent();
		current 	= $elem.index() + 1;
		var source 	= $elem.attr('class');
		$('#news_titolo').empty().html($this.find('p').html());
		$('#news_desc').empty().html($this.find('em').html()+' '+$this.find('span').html());
		$('#news_text').empty().html($this.find('div').html());
		$('#latest_post').removeClass('loading').html(data);
		/*
		$.get('rss.class.php', {source:source} , function(data) 
			{$('#latest_post').removeClass('loading').html(data);});
		*/
		e.preventDefault();});
	function show()
		{$('#overlay').show();
		if(!$('#modal').is(':visible'))
		$('#modal').css('left','-260px').show().stop().animate({'left':'50%'}, 500);
		$('#iframe_mov').hide();}
	function hide(){
		$('#modal').stop().animate({'left':'150%'}, 500, function()
			{$(this).hide();
			$('#overlay').hide();
			$('#latest_post').empty();});
			$('#iframe_mov').show(600);}
	$('#modal .close').bind('click',function(){hide();});
	$('#modal .next').bind('click',function(e){
		if(current == total)
			{e.preventDefault();
			return;}	
		$('#latest_post').empty().addClass('loading');
		$('#friendsList li:nth-child('+ parseInt(current+1) +')').find('a').trigger('click');
		e.preventDefault();});
	$('#modal .prev').bind('click',function(e){										
		if(current == 1){ 
			e.preventDefault();
			return;}	
		$('#latest_post').empty().addClass('loading');
		$('#friendsList li:nth-child('+ parseInt(current-1) +')').find('a').trigger('click');
		e.preventDefault();
	});
});
