var cps=[];function CP(t){"string"==typeof t&&(t=document.querySelector(t)),this._iframe=t,cps.push(this),this.eventListeners={}}function searchInCPs(t){for(var e in cps)if(cps[e]._iframe.contentWindow==t)return e;return-1}CP.prototype._post=function(t){this._iframe.contentWindow.postMessage(t,"*")},CP.prototype.play=function(){this._post({action:"CP.API.PLAY"})},CP.prototype.pause=function(){this._post({action:"CP.API.PAUSE"})},CP.prototype.toggle=function(){this._post({action:"CP.API.TOGGLE"})},CP.prototype.seekTo=function(t){this._post({action:"CP.API.SEEK_TO",value:t})},CP.prototype.getVolume=function(t){this._getter("GET_VOLUME",t)},CP.prototype.getDuration=function(t){this._getter("GET_DURATION",t)},CP.prototype.getPosition=function(t){this._getter("GET_POSITION",t)},CP.prototype.getPaused=function(t){this._getter("GET_PAUSED",t)},CP.prototype.getSource=function(t){this._getter("GET_SOURCE",t)},CP.prototype._getter=function(t,e){var n=this,i=function(s){e&&e(s.data),n.unbind("CP.API.CALLBACK."+t,i)};this.bind("CP.API.CALLBACK."+t,i),this._post({action:"CP.API."+t})},CP.prototype.bind=function(t,e){this.eventListeners[t]instanceof Array||(this.eventListeners[t]=[]),this.eventListeners[t].push(e),this._iframe.addEventListener(t,e,!1)},CP.prototype.unbind=function(t,e){if(e){var n=this.eventListeners[t].indexOf(e);this._iframe.removeEventListener(t,e,!1),-1!==n&&this.eventListeners[t].pop(n)}else if(this.eventListeners[t]instanceof Array){for(var i in this.eventListeners[t])this._iframe.removeEventListener(t,this.eventListeners[t][i],!1);this.eventListeners[t]=[]}},window.addEventListener("message",function(t){if(t.data.event&&-1!=t.data.event.search("CP.")){var e=searchInCPs(t.source);if(-1!=e){var n=new Event(t.data.event);n.data=t.data.data,cps[e]._iframe.dispatchEvent(n)}}});