RdioPlayer = (function () { function initPlayer (options) { // on page load use SWFObject to load the API swf into div#apiswf var flashvars = { 'playbackToken': options.token, // from token.js 'domain': options.domain, // from token.js 'listener': options.callbackName // the global name of the object that will receive callbacks from the SWF }; var params = { 'allowScriptAccess': 'always' }; var attributes = {}; swfobject.embedSWF('http://www.rdio.com/api/swf/', // the location of the Rdio Playback API SWF options.elementId, // the ID of the element that will be replaced with the SWF 1, 1, '9.0.0', 'expressInstall.swf', flashvars, params, attributes); } var updateQueue = function (callbackObject, element) { $.ajax({ url: '/queue.json', dataType: 'json', success: function (data) { if (data.length > 0) { if (!callbackObject.playing) { element.rdio_play(data[0]); data = data.slice(1); } for (var i = 0, _length = data.length; i < _length; i++) { element.rdio_queue(data[i]); } } } }); setTimeout(function () { updateQueue(callbackObject, element) }, 5000); }; function createCallback(rdio, callbackName, elementId) { var callback = {}; callback.ready = function () { self.ready = true; var element = document.getElementById(elementId); rdio.player = element; updateQueue(callback, element); } callback.playStateChanged = function (playState) { if (playState === 1 || playState === 3) { callback.playing = true; } else { callback.playing = false; } } callback.sourceTitle = function (source) { return source.artist + " - " + source.name; } callback.sourceList = function (source) { var queue = ""; for (var i = 0, _length = source.length; i < _length; i++) { queue += "