$(document).ready(function() {

	$("img").lazyload({
		placeholder : conf.url_cdn+'/images/blank.gif'
	});

	$('textarea#text').autoResize({
		animateDuration : 300,
		extraSpace : 40
	});

});

function thumb(id,type) {

	$.post('/ajax/comments/thumb.php',{'ref_id':id,'type':type},function(retour) {
		$('.post#c'+id+' .thumbs').css('display','none').html('<img src="'+conf.url_cdn+'/images/thumb_up_off.png" /> <img src="'+conf.url_cdn+'/images/thumb_down_off.png" /> <span style="font-size:80%;color:#808080">('+retour+')</span>').fadeIn();
	});

}

function afCountdown() {

	if ($('#alerte_af span#secondes')) {
		nombre = parseInt($('#alerte_af span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) nombre = '0';
			$('#alerte_af span#secondes').html(nombre);
			if (nombre == 1) $('#alerte_af span#secondes_txt').html(lang.comments.second);
			setTimeout('afCountdown();',1000);
		} else {
			$('#alerte_af').html(lang.comments.cancomment);
		}
	}

}

function afCountdownComment(id) {

	if ($('#commentEdit'+id+' span#secondes')) {
		nombre = parseInt($('#commentEdit'+id+' span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) {
				nombre = '0';
				$('#commentEdit'+id).fadeOut();
			}
			$('#commentEdit'+id+' span#secondes').html(nombre);
			if (nombre == 1) 
				$('#commentEdit'+id+' span#secondes_txt').html(lang.comments.second);
			setTimeout('afCountdownComment(\''+id+'\');',1000);
		}			
	}

}
 
function buriedCommentToggle(id) {

	if ($('.post#c'+id+' p.texte').css('display') == 'none') {
	
		$('.post#c'+id+' p.it a').html(lang.comments.hidecomment);
		
		$.get('/ajax/comments/thumbed.php?ref_id='+id,function(xml) { 
		
			if ($('root thumbed',xml).text() == '0') {
				$('.post#c'+id+' .thumbs').html('<a onclick="thumb(\''+id+'\',\'1\');" href="javascript:;"><img src="'+conf.url_cdn+'/images/thumb_up.png"/></a> <a onclick="thumb(\''+id+'\',\'0\');" href="javascript:;"><img src="'+conf.url_cdn+'/images/thumb_down.png"/></a> <span style="font-size:80%;color:#808080">('+$('root note',xml).text()+')</span>');
			} else {
				$('.post#c'+id+' .thumbs').html('<img src="'+conf.url_cdn+'/images/thumb_up_off.png" /> <img src="'+conf.url_cdn+'/images/thumb_down_off.png" /> <span style="font-size:80%;color:#808080">('+$('root note',xml).text()+')');
			}
		
		}); 
		
		$('.post#c'+id+' p.texte').css('display','block');
	
	} else {
	
		$('.post#c'+id+' p.it a').html(lang.comments.showcomment);
		
		$.get('/ajax/comments/thumbed.php?ref_id='+id,function(xml) {
		
		$('.post#c'+id+' .thumbs').html('<img src="'+conf.url_cdn+'/images/thumb_up_off.png" /> <img src="'+conf.url_cdn+'/images/thumb_down_off.png" /> <span style="font-size:80%;color:#808080">('+$('root note',xml).text()+')');
		$('.post#c'+id+' p.texte').css('display','none');
		
		});
	
	}

}

function replyToComment(id) {

	$('form#comment div#infos').html(lang.comments.inreplyto+id+' (<a href="javascript:;" onclick="replyToComment_cancel();">'+lang.comments.cancel+'</a>)');
	$('form#comment input[name=in_reply_to]').val(id);
	document.location = '#comment';
	$('form#comment textarea[name=texte]').focus();

}

function replyToComment_cancel() {

	$('form#comment div#infos').html('');
	$('form#comment input[name=in_reply_to]').val('0');

}