// Menu lavalamp
$(function() {
    $(".menucats").lavaLamp({
		fx: "backout",
		speed: 700,
		click: function(event, menuItem) { return true; }
	});
});

// Sidebar
$(document).ready(function(){
	$('ul.tabNav a').click(function() {
		var curChildIndex = $(this).parent().prevAll().length + 1;
		$(this).parent().parent().children('.actif').removeClass('actif');
		$(this).parent().addClass('actif');
		$(this).parent().parent().next('.tabCont').children('.actif').slideUp('normal',function() {
			$(this).removeClass('actif');
			$(this).parent().children('div:nth-child('+curChildIndex+')').slideDown('slow',function() {
				$(this).addClass('actif');
			});
		});
		return false;
	});
});

// Reply
function replyTo(commentID,author) {
	var inReplyTo='@<a href="#comment-'+commentID+'">'+author+'</a>: ';
    var myField;
    if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
    	myField = document.getElementById('comment');
    }
	else {
    	return false;
    }

	if (document.selection) {
    	myField.focus();
    	sel = document.selection.createRange();
    	sel.text = inReplyTo;
    	myField.focus();
    }
    else if (myField.selectionStart || myField.selectionStart == '0') {
    	var startPos = myField.selectionStart;
    	var endPos = myField.selectionEnd;
    	var cursorPos = endPos;
    	myField.value = myField.value.substring(0, startPos)
    					  + inReplyTo
    					  + myField.value.substring(endPos, myField.value.length);
    	cursorPos += inReplyTo.length;
    	myField.focus();
    	myField.selectionStart = cursorPos;
    	myField.selectionEnd = cursorPos;
    }
    else {
    	myField.value += inReplyTo;
    	myField.focus();
    }
}
