/*
*   JavaScript interface for the SoundCloud Player widget
*   Author: Matas Petrikas, matas@soundcloud.com
*   Copyright (c) 2009  SoundCloud Ltd.
*   Licensed under the MIT license:
*   http://www.opensource.org/licenses/mit-license.php
*/
(function(){var a=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);var b=window.soundcloud={version:"0.1",debug:false,_listeners:[],_redispatch:function(a,b,c){var d,e=this._listeners[a]||[],f="soundcloud:"+a;try{d=this.getPlayer(b)}catch(g){if(this.debug&&window.console){console.error("unable to dispatch widget event "+a+" for the widget id "+b,c,g)}return}if(window.jQuery){jQuery(d).trigger(f,[c])}else if(window.Prototype){$(d).fire(f,c)}else{}for(var h=0,i=e.length;h<i;h+=1){e[h].apply(d,[d,c])}if(this.debug&&window.console){console.log(f,a,b,c)}},addEventListener:function(a,b){if(!this._listeners[a]){this._listeners[a]=[]}this._listeners[a].push(b)},removeEventListener:function(a,b){var c=this._listeners[a]||[];for(var d=0,e=c.length;d<e;d+=1){if(c[d]===b){c.splice(d,1)}}},getPlayer:function(b){var c;try{if(!b){throw"The SoundCloud Widget DOM object needs an id atribute, please refer to SoundCloud Widget API documentation."}c=a?window[b]:document[b];if(c){if(c.api_getFlashId){return c}else{throw"The SoundCloud Widget External Interface is not accessible. Check that allowscriptaccess is set to 'always' in embed code"}}else{throw"The SoundCloud Widget with an id "+b+" couldn't be found"}}catch(d){if(console&&console.error){console.error(d)}throw d}},onPlayerReady:function(a,b){this._redispatch("onPlayerReady",a,b)},onMediaStart:function(a,b){this._redispatch("onMediaStart",a,b)},onMediaEnd:function(a,b){this._redispatch("onMediaEnd",a,b)},onMediaPlay:function(a,b){this._redispatch("onMediaPlay",a,b)},onMediaPause:function(a,b){this._redispatch("onMediaPause",a,b)},onMediaBuffering:function(a,b){this._redispatch("onMediaBuffering",a,b)},onMediaSeek:function(a,b){this._redispatch("onMediaSeek",a,b)},onMediaDoneBuffering:function(a,b){this._redispatch("onMediaDoneBuffering",a,b)},onPlayerError:function(a,b){this._redispatch("onPlayerError",a,b)}}})()
