If I were to approach this, here is how I would handle it:
$('#checkbox').change(function(){
if(!$(this).prop('checked')){
moveRight();
$(this).data('slideshow', setInterval(function () {
moveRight();
}, 3000));
} else {
clearInterval($(this).data('slideshow'));
}
});
The logic checks if the checkbox is unchecked, in which case it initiates the moveRight function and starts the interval. This is stored in the element so that when the checkbox is checked next time, the slideshow can be stopped by clearing it out.
For the live demonstration, you can access the fiddle here:
http://jsfiddle.net/r6uf38v4/2/
UPDATE: Considering the requirement to begin the slideshow from the start.
To address this, a modification is made to ensure moveRight is only called initially when the checkbox is clicked:
$('#checkbox').on('change', function(ev, load){
var load = load === undefined ? false : true;
if(!$(this).prop('checked')){
if(!load) { moveRight(); }
$(this).data('slideshow', setInterval(function () {
moveRight();
}, 3000));
} else {
clearInterval($(this).data('slideshow'));
}
});
An extra argument is included to prevent moveRight from being invoked initially when the page loads. To trigger the function, use the following code:
$('#checkbox').trigger('change', {load : true});
Furthermore, ensure that the checkbox input does not have the "checked" attribute in the HTML to avoid conflicting with the interval functionality:
<input type="checkbox" id="checkbox">
The updated fiddle can be accessed here:
http://jsfiddle.net/r6uf38v4/3/