$(document).ready(function(){
	// blog rss
	$(function(){		
		// build list
		ulElement = document.createElement("ul");
		ulElement.setAttribute('id', 'rss-blog');
		ulElement.setAttribute('style', 'display:none');
		$.getJSON("rss-json.php", function(data){
			$.each(data, function(i, item){
				liElement = document.createElement("li");
				
				aElement = document.createElement("a");
				aElement.setAttribute('href', item.link);
				aElement.setAttribute('title', item.title);
				aContent = document.createTextNode(item.title);
				aElement.appendChild(aContent);
				
				// break line
				var lf = document.createElement('br')
				
				spanElement = document.createElement("span");
				spanContent = document.createTextNode("Artigo publicado em " + item.date + " - " + item.commentsCount + " Comentário(s)");
				spanElement.appendChild(spanContent);				
				
				liElement.appendChild(aElement);
				liElement.appendChild(lf);
				liElement.appendChild(spanElement);
				ulElement.appendChild(liElement);
			});
		});
				
		// insert list
		$(".dm-container.blog .dm-container-body").html(ulElement);
		
		// show content slow
		$('#rss-blog').fadeIn('slow');
	});
	
	// tweets
	$('#jTweets-container').jTweetsAnywhere({
		username: 'dmmatheus',
		count: 20,
		showTweetFeed: {
			showProfileImages: true,
			showUserScreenNames: true,
			expandHovercards: true,
        	showSource: true,
			paging: {
				mode: 'endless-scroll'
			}
		},
		onDataRequestHandler: function(stats) {
			if (stats.dataRequestCount < 11) {
				return true;
			}
			else {
				alert("Siga-me no twitter para conferir mais mensagens.");
			}
		}
	});
	
	$("#dm-header-icons ul li").hover(function() {
		$(this).stop().animate({ backgroundColor: "#bfd630" }, 600);
	},function() {
		$(this).stop().animate({ backgroundColor: "#f6f6f6" }, 400);
	});
	
	$(".dm-container.books .dm-container-body ul li").hover(function() {
		$(this).stop().animate({ backgroundColor: "#f6f6f6" }, 600);
	},function() {
		$(this).stop().animate({ backgroundColor: "#ffffff" }, 400);
	});
	
	$("#dm-footer ul li.header a").click(function(){
		$('html, body, .content').animate({scrollTop: '0px'}, 300);
		return false;
	});
});
