// JavaScript Document


function abreNovidades(url, rede) {
	
	$('#comunidade').fadeOut("slow");
	$(".casapro .abreFecha img").attr({ src: "/_arquivos/seta-rede.gif" });
	$(".casaclaudiasocial .abreFecha img").attr({ src: "/_arquivos/seta-rede.gif" });
	
	if (rede == 'casapro') {
		$('.casapro .ajax-load').fadeIn('slow');
	} else {
		$('.casaclaudiasocial .ajax-load').fadeIn('slow');
	}
	
	var html = "";
	//var url = "http://casaclaudia.ning.com/activity/log/list?fmt=rss"
	
	
	//clear the content in the div for the next feed.
	$("#feedContent").empty();
	
	//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('/ferramentas/proxy.php?url='+url, function(d) {
		
		
		
		//find each 'item' in the file and parse it
		$(d).find('item').each(function(num) {
			html = "";
			//name the current found item this for this particular loop run
			var $item = $(this);
			// grab the post title
			//var title = $item.find('title').text();
			// grab the post's URL
			//var link = $item.find('link').text();
			// next, the description
			var description = $item.find('description').text();
			//don't forget the pubdate
			//var pubDate = $item.find('pubDate').text();
			
			// now create a var 'html' to store the markup we're using to output the feed to the browser window
			//html = "<div class=\"entry\"><a href=\"" + link + "\" target=\"_blank\"><h3 class=\"postTitle\">" + title + "<\/h3><\/a>";
			html += "<div class=\"entry\"><p>" + description + "<\/p><\/div>";
			//html += "<p class=\"description\">" + description + "</p>";
			//html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";
			
			//put that feed content on the screen!
			$('#feedContent').append($(html)); 
			
			success: if (rede == 'casapro') { $('.casapro .ajax-load').fadeOut('slow'); } else { $('.casaclaudiasocial .ajax-load').fadeOut('slow'); } 
			//$("#msg").fadeOut('Slow');
						
			$(".entry a").attr({ target: "_blank" });


		});
		
		
		if (rede == 'casapro') {
			$('#comunidade').css('background', '#e0e0e0');
			$('.entry').css('background', '#FFF');
			$('.entry a').css('color', '#c4151c');
			$('.titComunidade').empty();
			$('.titComunidade').append('Novidades na comunidade');
			$('#comunidade').css('left' , '7px');
			$('#comunidade').css('top' , '45px');
			$(".casapro .abreFecha img").attr({ src: "/_arquivos/fecha-rede.gif" });
			
			$(".casapro .abreFecha a").attr({ href: "javascript:fechaNovidades();" });
			
			
			/*$('#comunidade').css('left' , '15px');
			$('#comunidade').css('top' , '697px');*/
			
			
		} else {
			$('#comunidade').css('background', '#e0e0e0');
			$('.entry').css('background', '#FFF');
			$('.entry a').css('color', '#C04B62');
			$('.titComunidade').empty();
			$('.titComunidade').append('Novidades na comunidade');
			$('#comunidade').css('left' , '7px');
			$('#comunidade').css('top' , '72px');
			$(".casaclaudiasocial .abreFecha img").attr({ src: "/_arquivos/fecha-rede.gif" });
			
			$(".casaclaudiasocial .abreFecha a").attr({ href: "javascript:fechaNovidades();" });
			
			/*$('#comunidade').css('left' , '15px');
			$('#comunidade').css('top' , '725px');*/
			
		}
		
		$('#comunidade').fadeIn("slow");

	});
}


function fechaNovidades() {

	$("#feedContent").empty();
	$('#comunidade').fadeOut("slow");
	$(".casapro .abreFecha img").attr({ src: "/_arquivos/seta-rede.gif" });
	$(".casaclaudiasocial .abreFecha img").attr({ src: "/_arquivos/seta-rede.gif" });
	
	$(".casapro .abreFecha a").attr({ href: "javascript:abreNovidades('http://pro.casa.abril.com.br/activity/log/list?fmt=rss', 'casapro');" });
	$(".casaclaudiasocial .abreFecha a").attr({ href: "javascript:abreNovidades('http://casaclaudia.ning.com/activity/log/list?fmt=rss', 'casaclaudiasocial');" });
	
}		
	
/*$(document).ready(function(){
		$("#comunidade").shadow({
           width:5,
           startOpacity:60,
           endOpacity:10,
           cornerHeight:8,
           color:"#000000"
       });
});*/
