function arrayMap(array, iter) { if (array.map) return array.map(iter); else { var result = [], i; for(i = 0; i < array.length; i++) result.push(iter(array[i])); return result; } } function arraySome(array, iter) { if (array.some) return array.some(iter); else { var i; for(i = 0; i < array.length; i++) if (iter(array[i])) return true; return false; } } function arrayForEach(array, iter) { if (array.forEach) array.forEach(iter); else { var i; for(i = 0; i < array.length; i++) iter(array[i]); } } function addButton(container, res, chapters) { var button = $('▶ Play'); if (res.poster) { var img = $(''); img.attr('src', res.poster); if (res.preview) { button.mouseover(function() { img.attr('src', res.preview); }); button.mouseout(function() { img.attr('src', res.poster); }); } button.append(img); } else { /* No poster */ button.text('▶ Play'); button.addClass('no-poster'); } button.click(function() { button.remove(); addPlayer(container, res, chapters); var section = container.parents(). filter(function() { return $(this).hasClass('video-resource'); })[0]; if (section) $(section).addClass("playing"); }); container.append(button); } function parseTime(time) { var parts = time.split(":"), part; var r = 0; while((part = parts.shift())) { r = r * 60 + parseInt(part, 10); } return r; } function addPlayer(container, res, chapters) { var types = arrayMap(res, function(res) { return res.type; }); /* Can we have