$(document).ready(function(){
	anularPrevent();
	$('#textarea').markItUp(mySettings);
	setInterval(function(){$.ajax({type:"GET",url:"ajax/online.php"})},5000);
})
function anularPrevent(){$('a[href="/"]').click(function(event){event.preventDefault()})}
function cambiar(idElement){if($("#"+idElement).is(":hidden")){$("#"+idElement).slideDown("slow")}else{$("#"+idElement).hide()}}
function loadUltimCom(){$.get('ajax/ultimos_comentarios.php',function(data){$('#loadUltimCom').fadeOut('slow',function(){$('#loadUltimCom').html(data);$('#loadUltimCom').fadeIn('slow')})})}
function loadUltimSec(){$.get('ajax/ultimos_secretos.php',function(data){$('#loadUltimSec').fadeOut('slow',function(){$('#loadUltimSec').html(data);$('#loadUltimSec').fadeIn('slow')})})}

function irA(){
	window.location="http://secretoss.com.ar/sec-"+$("#irAsec").val();
}

function agregarSecreto(){
	var secretoP = $("#textarea").val();
	var edadP = $("#edad").val();
	var sexoP = $("#sexo").val();
	$("#agregar_secreto").html('<img alt="Cargando..." src="images/cargando.gif" />');
	$.ajax({
		type: "POST",
		url: "ajax/agregar_secreto.php",
		data: "secreto="+encodeURIComponent(secretoP)+"&edad="+encodeURIComponent(edadP)+"&sexo="+encodeURIComponent(sexoP),
		success: function(msg){
			$('#agregar_secreto').fadeOut("fast",function(){
				$('#agregar_secreto').html(msg);
				$('#agregar_secreto').fadeIn("fast");
				$('#textarea').markItUp(mySettings);
				$('#textarea').focus();
			});			
		}
 });
}
function votar(idVot,Valor,elemento){
	$("#"+elemento+"_res_"+idVot).html('<img alt="Cargando..." src="images/cargando.gif" />');
	$.ajax({
		type: "GET",
		url: "ajax/votar.php?id=" + idVot + "&valor=" + Valor + "&elemento=" + elemento,
		data: "",
		success: function(msg){
			$("#"+elemento+"_res_"+idVot).fadeOut("fast",function(){
				$("#"+elemento+"_res_"+idVot).html(msg);
				$("#"+elemento+"_res_"+idVot).fadeIn("fast")
			});			
		}
 });
}
function denunciarSecreto(refIS,idSecDen){
	$(refIS).html('<img alt="Cargando..." src="images/cargando.gif" />');
	$.ajax({
		type: "POST",
		url: "ajax/denunciar.php",
		data: "id=" + idSecDen + "&elemento=secreto",
		success: function(msg){
			$(refIS).html(msg);
		}
 })
}
function denunciarComentario(refIC,idComDen){
	$(refIC).html('<img alt="Cargando..." src="images/cargando.gif" />');
	$.ajax({
		type: "POST",
		url: "ajax/denunciar.php",
		data: "id=" + idComDen + "&elemento=comentario",
		success: function(msg){
			$(refIC).html(msg);
		}
 });
}
function focusCom(idSecFocus){
	$("#inputCom_"+idSecFocus).hide(0);
	$("#textareaCom_"+idSecFocus).show(0);
	$("#comentarionuevo_"+idSecFocus).markItUp(mySettings);
	$("#comentarionuevo_"+idSecFocus).focus();
}

function comentarSecreto(idSecCom){
	valCom=$("#comentarionuevo_"+idSecCom).val();
	$("#comentarionuevo_"+idSecCom).markItUpRemove();
	$("#textareaCom_"+idSecCom).hide(0);
	$("#agregar_comentario_"+idSecCom).html('<img alt="Cargando..." src="images/cargando.gif" />');
	$.ajax({
		type: "POST",
		url: "ajax/agregar_comentario.php",
		data: "idsec=" + idSecCom + "&comm="+encodeURIComponent(valCom),
		success: function(msg){
			$("#agregar_comentario_"+idSecCom).html(msg);
			$("#comentarionuevo_" + idSecCom ).markItUp(mySettings);
			$("#comentarionuevo_" + idSecCom ).focus();
		}
 })
}

function citar(idElCi, ElCit){	
	$.markItUp({replaceWith:' @'+ElCit+'='+idElCi+' '} );
}
