var yearOpened = 0;
function openYear ( year ) {
	$('#archive ul').hide();
	if (yearOpened != year) {
		$('#archive ul.year' + year).show();
		yearOpened = year;
	} else {
		yearOpened = 0;
	}
}

function openClosePostMore ( i, item ) {
	$('.more_'+i+' .moreItem').hide(100);
	$('#postFooter_'+i+' .links .item').removeClass('marked');
	
	$('#'+item+'_'+i).show(1500);
	$('#'+item+'Link_'+i).addClass('marked');
}

function marcarLink () {
	var url = document.location.href;
	if (url.match(/^(.*)#comments$/)) {
		openClosePostMore ( 1, 'comments' );
	} else if (url.match(/^(.*)#friend$/)) {
		openClosePostMore ( 1, 'friend' );
	} else if (url.match(/^(.*)#share$/)) {
		openClosePostMore ( 1, 'share' );
	}
}

function checkEmail (inputvalue) {
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)) {
		return true;
    } else {
		return false;
    }
}

var fileCount = 1;
var fileRemoved = 0;
var fileMax = 15;
function addInputFile () {
	if ((fileCount - fileRemoved) > fileMax) {
		alert('O limite de arquivos (' + fileMax + ') foi atingido, envie em uma nova mensagem outros arquivos.');
		return;
	}
	var fileHtml = "<input type=\"file\" name=\"file[]\" /> <input type=\"image\" src=\"../_img/button_cancel.png\" onclick=\"removeInputFile(" + fileCount + ");\" />";
	var files = document.getElementById("files");
	var div = document.createElement("div");
	div.setAttribute('id', 'fileDiv_' + fileCount);
	div.innerHTML = fileHtml;
	files.appendChild(div);
	fileCount++;
}
function removeInputFile (i) {
	var file = document.getElementById("fileDiv_" + i);
	file.parentNode.removeChild(file);
	fileRemoved++;
}

function initJCarousel () {
	jQuery('.jCarousel').jcarousel();
}

$(document).ready(function() {
	marcarLink();
	initJCarousel();
});

// Vote
function vote (post, opt) {
	if (!post || (opt != 1 && opt != 2)) {
		return;
	}
	
	$.ajax({
		type: "POST",
		url: "../../vote.php",
		data: "p=" + post + "&o=" + opt,
		success: function (msg) {
			var resposta = new Object();
			eval("resposta=" + msg);
			if (resposta.error != '') {
				alert( resposta.error );
				return;
			}
			$('#vote_header_' + post).html('Resposta');
			$('#opt_1_' + post).html($('#opt_1_' + post).html() + ' - ' + resposta.votes_1);
			$('#opt_2_' + post).html($('#opt_2_' + post).html() + ' - ' + resposta.votes_2);
			var opt1 = document.getElementById('opt_1_' + post);
			var opt2 = document.getElementById('opt_2_' + post);
			opt1.onclick = '';
			opt2.onclick = '';
			opt1.style.cursor = 'default';
			opt2.style.cursor = 'default';
		}
	});
}



