I have the following code, and it works fine until i hit the the #play button. I'm assuming it's because the var intID is set in another place and it's not in the same scope when i window.clearInterval() it... how do I fix this? BTW, this is the Google Maps API Version 3
function intervalTrigger(){
return window.setInterval(function(){
placement++;
if(placement >= markers.length){placement = 0;}
google.maps.event.trigger(markers[placement], "click");
}, 5000);
};
var intID = intervalTrigger();
$('#map_canvas').click(function(){window.clearInterval(intID);});
$('a[href=#nextmarker]').live('click',function(){
placement++;
if(placement >= markers.length){placement = 0};
google.maps.event.trigger(markers[placement], "click");
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});
$('a[href=#prevmarker]').live('click',function(){
placement--;
if(placement == -1){placement = markers.length-1}
google.maps.event.trigger(markers[placement], "click");
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});
$('a[href=#play]').live('click',function(){
$('a[href=#play]').replaceWith('<a href="#pause">Pause</a>');
var intID = intervalTrigger();
return false;
});
$('a[href=#pause]').live('click',function(){
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});