nbsmiles=0;
function signaler(id,pid,user_id){
	if(confirm('Etes vous sur de vouloir signaler cette photo ?')){
		$.get('../ajax/signaler.php?id='+id+'&pid='+pid+'&user_id='+user_id,'',function(data){
			if(data=='1') $('#alert').html('<div class="ok bold">OK !</div>');
			else if(data=='0') $('#alert').html('<div class="error bold">Erreur</div>');
		});
	}
}



function affiche_cam(id){
	$('#webcam').slideDown(1000,function(){
		$.get('../ajax/affich_cam.php?id='+id,function (html){ $('#webcam').html(html);});
		$('#text_cam').slideUp();
	});
}

function tchat(pid,user){
	$('#tchat_here').html('<center><iframe src="http://cw.gabbly.com/gabbly/cw.jsp?e=1&nick='+user+'&t=http://www.trombiz.com/gamaniak/'+pid+'&adurl=http://www.gamaniak.com/pubs/gabbly.php" scrolling="no" style="width:600px; height:300px" frameborder="0"></iframe></center>');
}

function vote(id,note){
	$.get('../ajax/vote.php?id='+id+'&note='+note,function(html){ $('#votes').html(html); });
}

function verif_pseudo(pseudo){
	if(pseudo.length > 2){
		$('#libre').css('display','none');
		$.get('../ajax/verif_pseudo.php?pseudo='+pseudo,function(html){ $('#libre').html(html); });
		$('#libre').fadeIn();
	}else{
		$('#libre').html('<span class="error bold"> Doit faire plus de 2 lettres</span>');
	}
}

function verif_mail(mail){
	if(mail.length>2){
		$('#libre2').css('display','none');
		$.get('../ajax/verif_mail.php?mail='+mail,function(html){ $('#libre2').html(html); });
		$('#libre2').fadeIn();
	}else{
		$('#libre2').html('<span class="error bold"> Ne doit pas etre vide</span>');
	}
}

function verif_pass(pass){
	if(pass.length>4){
		$('#libre3').html('<span class="ok bold"> Valide</span>');
	}else{
		$('#libre3').html('<span class="error bold"> Doit faire plus de 4 chiffres/lettres</span>');
	}
}

function post_msg(){
	if(document.comment.pseudo.value == "") {
	   alert("Veuillez entrer un pseudo !");
	   document.comment.psdgam.focus();
	   return false;
	}
	
	if(document.comment.spam.value == "") {
	   alert("Veuillez ecrire le jour en toutes lettres !");
	   document.comment.spam.focus();
	   return false;
	}
	
	if(document.comment.msg.value == "") {
	   alert("Veuillez ecrire un message !");
	   document.comment.msg.focus();
	   return false;
	}
	
	
	document.comment.ajout.value = "En cours d'ajout";
	document.comment.ajout.disabled = true;
}

function more_smiles(){
	$('#smileys').animate({height:80},800);
}

function insertAtCaret(areaId,text) { var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); strPos = range.text.length; } else if (br == "ff") strPos = txtarea.selectionStart; var front = (txtarea.value).substring(0,strPos); var back = (txtarea.value).substring(strPos,txtarea.value.length); txtarea.value=front+text+back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); range.moveStart ('character', strPos); range.moveEnd ('character', 0); range.select(); } else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); } txtarea.scrollTop = scrollPos; }


/* Tooltip */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(document).ready(function(){
	$('#smileys img').click(function(){
		insertAtCaret('comment',' '+$(this).attr('alt')+' ');
		nbsmiles++;
		if(nbsmiles>2) $('#smileys_line').slideUp();
	});
	
	tooltip();
});
