How to use the variable "i" and the value in another function, "izq" and "der"?. I need to use the variable within other functions.
$("#gal li a").on('click', openImg);
function openImg(e){
e.preventDefault();
var href = $(this).attr('href');
i = $(this).parent().index();
$("#overlay").fadeIn();
$("#overlay #cont_img img").attr('src', href);
}
$(".izq").on('click', function(e){
e.preventDefault();
var izq;
i--;
if(i < 0){
i = total-1;
}
izq = $("#galeria li a").eq(i).attr('href');
$("#overlay #cont_img img").attr('src', izq);
});
$(".der").on('click', function(e){
e.preventDefault();
var der;
i = (i-1) % total;
der = $("#gal li a").eq(i).attr('href');
$("#overlay #cont_img img").attr('src', der);
});