var inits = inits || {};
inits.front = {};
inits.contentsFromAtuthor = {};

inits.front.contentsFromAtuthor = function() {
	//zeit.showlist();
	var codProfile = $("input[@name=codP]").val();
	$('.blfeature .tagCloud').load('/ajax/authorsTags.html?index.itemsPerPage='+TAGCLOUD_PAGESIZE+'&codProfile=' + codProfile, false, function() {
		$('.blfeature .tagCloud a').each(function() {
			var text = $(this).text();
			$(this).attr("href",$(this).attr("href")+'&show=fromAuthor&codProfile='+codProfile);
			$(this).text(text);
		});
		utils.fixFeaturesPosition();
	});
	$.getJSON("/ajax/friends.html?types=A&flavor=json&codProfile=" + codProfile, function(data){
		var friendsContent = data.content;
		if (friendsContent.length > 0) {
			for(var x=0; x<friendsContent.length; x++){
				//var url = "/content.html?types=A&action=contentsFromAuthor&codProfile=" + friendsContent[x].userProfile + "&index.currentPage=1&show=mostRecent";
				$('.friendsContainer').append("<dl class='userFriend'></dl>");
				$('.userFriend:last').append("<dt><a href='"+ friendsContent[x].contentUrl +"'><img src='http://" + friendsContent[x].userProfile + ".uolk.uol.com.br/images/thumb_avatar.jpg' /></a></dt>");
				$('.userFriend:last').append("<dd class='userName'><a href='"+ friendsContent[x].contentUrl +"'>" + friendsContent[x].userName + "</a></dd>");
				$('.userFriend:last').append("<dd class='userPosts'>Posts: <a href='"+ friendsContent[x].contentUrl +"'>" + friendsContent[x].userPosts + "</a></dd>");
			}
		} else {
			var linkInvite = $("#inviteNewFriendUrl").attr("href");
			if (!linkInvite) {
				linkInvite = "/";
			}
			var userName = $('#profileNamNick').val();
			$('.friendsContainer').append('<div class="friendempty">'+userName+' ainda não possui amigos na rede UOL.</div>');
			$('.feat_friends h2 a').css('display','none');
		}
		utils.fixFeaturesPosition();
	});


	$('dl.sort').each(function(){
		var current = $('dt:first', this).attr('class');
		var content = $('.' + current + ' a', this).html();		

		$('dt:first', this).append('&nbsp;<strong>' +  content + '<a href="#"></a></strong>');
		$('dt:first a', this).click(function(){
			$('.sort dd').hide();
			$('.sort').removeClass('opened');
			$(this).parents('dl').find('dd').toggle();
			$(this).parents('dl').toggleClass('opened');
			
			return false;
		});
	});
	
	$(document).click(function(){
		$('.sort dd').hide();
		$('.sort').removeClass('opened');
	});
	
	$('dl.sort strong')
		.mouseover(function(){
			$(this).addClass('hover');
		})
		.mouseout(function(){
			$(this).removeClass('hover');
		});

	// Avatar
	$('.user-header-avatar').error(function() {
		$(".avatar").remove();
	});
	
	$('.specialtitle a').each(function() { this.target = "blank"; })
	
	utils.userPostsSearch();
}