$(document).ready(function () { //get presentation ids to poll var presentation_ids = $('body').attr('data-live_presentations'); var presentation_array = []; if (presentation_ids == null || presentation_ids.length < 1) { return; } if (presentation_ids.indexOf(',') > 0) { presentation_array = presentation_ids.split(','); } else { presentation_array.push(presentation_ids); } var checkLiveStateCB = function () { return function () { for (var i in presentation_array) { //make unique stamp var uniq = new Date; var unixtime_ms = uniq.getTime(); //get mode from amazon $.ajax({ type: "GET", url: "http://framewelder.com-cache.s3.amazonaws.com/presentations/" + presentation_array[i] + "/livemode.json?callback=liveswitch", data: { uniq: unixtime_ms }, dataType: "jsonp", success: function(json) {}, error: function() {} }); } }; }; var functionCB = checkLiveStateCB(); functionCB(); //loop setInterval (checkLiveStateCB(), 5000); }); liveswitch = function (response) { var presentation_id = response['presentation_id']; var presentationID_array = []; var mode = response['mode']; var modes = ['before', 'during', 'just', 'after']; var classtype = ''; for (var i in modes) { if (modes[i] == mode) { classtype = 'block'; } else { classtype = 'none'; } $('.' + modes[i] + '-' + presentation_id).css({ display: classtype }); if (mode == 'during' || mode == 'just' || mode == 'after') { $('.streaming-' + presentation_id).remove(); $('.labels-' + presentation_id).remove(); } } };