Its probably not the best way to create a slider but in terms of fixing what you have already this should be sufficient to get you started.
$('body').on('click','.gleft', function() {
if($('.gthumb.active').next().length > 0){
$('.gthumb.active').removeClass('active').next().trigger('click').addClass('active');
}
});
$('body').on('click','.gright', function() {
if($('.gthumb.active').prev().length > 0){
$('.gthumb.active').removeClass('active').prev().trigger('click').addClass('active');
}
});