How to avoid negative (-1) jquery result
I am developing a wordpress slideshow for jquery. I have to say that I am not an expert and this is my first experience with jquery or javascript. Everything works fine, the code works just fine, when the post rotates every x seconds, there are two divs that move the post to the left (previous) or right (next) on click, it works fine, but in the first post (0) when you click to the left (previous), it doesn't show anything since 0 - 1 = -1 there is no -1 message and what was shown is the last message (4). I tried if {} else if {} but as I said I am not an expert and I cannot find a solution on my own. Any help is appreciated. The code...
$("#switch-izquierda").click(
function() {
$("#lista-contenedor-rotatorio li:eq("+img_actual+")").fadeOut(1600);
img_actual = (img_actual -1) % cuenta;
$("#lista-contenedor-rotatorio li:eq("+img_actual+")").fadeIn(2000);
});
The problem is here ...
img_actual = (img_actual -1) % cuenta;
When in the first message (0) the result is -1, I need to show the last message (4)
If you have a solution, I really appreciate it.