/*
 * ipad.js 3.2.1. The Flowplayer API
 *
 * Copyright 2010 Flowplayer Oy
 * By Thomas Dubois <thomas@flowplayer.org>
 *
 * This file is part of Flowplayer.
 *
 * Flowplayer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Flowplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Date: 2010-08-25 17:40:08 +0000 (Wed, 25 Aug 2010)
 * Revision: 4219
 */
$f.addPlugin("ipad",function(r){var H=-1;var s=0;var t=1;var F=2;var w=3;var B=4;var f=5;var e=this;var J=1;var I=false;var y=false;var o=false;var m=0;var G=[];var c={accelerated:false,autoBuffering:false,autoPlay:true,baseUrl:null,bufferLength:3,connectionProvider:null,cuepointMultiplier:1000,cuepoints:[],controls:{},duration:0,extension:"",fadeInSpeed:1000,fadeOutSpeed:1000,image:false,linkUrl:null,linkWindow:"_self",live:false,metaData:{},originalUrl:null,position:0,playlist:[],provider:"http",scaling:"scale",seekableOnBegin:false,start:0,url:null,urlResolvers:[]};var q=H;var k=H;var n=/iPad|iPhone|iPod/i.test(navigator.userAgent);var b=null;function i(N,M,K){if(M){for(key in M){if(key){if(M[key]&&typeof M[key]=="function"&&!K){continue}if(M[key]&&typeof M[key]=="object"&&M[key].length==undefined){var L={};i(L,M[key]);N[key]=L}else{N[key]=M[key]}}}}}var u={simulateiDevice:false,controlsSizeRatio:1.5,controls:true,debug:false};i(u,r);function d(){if(u.debug){if(n){var K=[].splice.call(arguments,0).join(", ");console.log.apply(console,[K])}else{console.log.apply(console,arguments)}}}function h(K){switch(K){case -1:return"UNLOADED";case 0:return"LOADED";case 1:return"UNSTARTED";case 2:return"BUFFERING";case 3:return"PLAYING";case 4:return"PAUSED";case 5:return"ENDED"}return"UNKOWN"}function z(K){var L=$f.fireEvent(e.id(),"onBefore"+K,m);return L!==false}function D(K){K.stopPropagation();K.preventDefault();return false}function C(L,K){if(q==H&&!K){return}k=q;q=L;d(h(L))}function v(){b.fp_stop();I=false;y=false;o=false;C(t);C(t)}function x(){v();o=true;b.fp_seek(0)}function E(K){}function l(){function K(M){var L={};i(L,c);i(L,e.getCommonClip());i(L,M);if(L.ipadUrl){url=L.ipadUrl}else{if(L.url){url=L.url}}if(url&&url.indexOf("://")==-1&&L.baseUrl){url=L.baseUrl+"/"+url}L.originalUrl=L.url;L.completeUrl=url;L.extension=L.completeUrl.substr(L.completeUrl.lastIndexOf("."));L.type="video";delete L.index;d("fixed clip",L);return L}b.fp_play=function(O,M,Q){var L=null;var P=true;var N=true;d("Calling play() "+O,O);if(M){d("ERROR: inStream clips not yet supported");return}if(O!==undefined){if(typeof O=="number"){if(m>=G.length){return}m=O;O=G[m]}else{if(typeof O=="string"){O={url:O}}b.fp_setPlaylist(O.length!==undefined?O:[O])}O=G[m];L=O.completeUrl;if(O.autoBuffering!==undefined&&O.autoBuffering===false){P=false}if(O.autoPlay===undefined||O.autoPlay===true||Q===true){P=true;N=true}else{N=false}}else{d("clip was not given, simply calling video.play, if not already buffering");if(q!=F){b.play()}return}d("about to play "+L,P,N);v();if(L){d("Changing SRC attribute"+L);b.setAttribute("src",L)}if(P){if(!z("Begin")){return false}$f.fireEvent(e.id(),"onBegin",m);d("calling video.load()");b.load()}if(N){d("calling video.play()");b.play()}};b.fp_pause=function(){d("pause called");if(!z("Pause")){return false}b.pause()};b.fp_resume=function(){d("resume called");if(!z("Resume")){return false}b.play()};b.fp_stop=function(){d("stop called");if(!z("Stop")){return false}y=true;b.pause();try{b.currentTime=0}catch(L){}};b.fp_seek=function(L){d("seek called "+L);if(!z("Seek")){return false}var P=0;var L=L+"";if(L.charAt(L.length-1)=="%"){var M=parseInt(L.substr(0,L.length-1))/100;var O=b.duration;P=O*M}else{P=L}try{b.currentTime=P}catch(N){d("Wrong seek time")}};b.fp_getTime=function(){return b.currentTime};b.fp_mute=function(){d("mute called");if(!z("Mute")){return false}J=b.volume;b.volume=0};b.fp_unmute=function(){if(!z("Unmute")){return false}b.volume=J};b.fp_getVolume=function(){return b.volume*100};b.fp_setVolume=function(L){if(!z("Volume")){return false}b.volume=L/100};b.fp_toggle=function(){d("toggle called");if(e.getState()==f){x();return}if(b.paused){b.fp_play()}else{b.fp_pause()}};b.fp_isPaused=function(){return b.paused};b.fp_isPlaying=function(){return !b.paused};b.fp_getPlugin=function(M){if(M=="canvas"||M=="controls"){var L=e.getConfig();return L.plugins&&L.plugins[M]?L.plugins[M]:null}d("ERROR: no support for "+M+" plugin on iDevices");return null};b.fp_close=function(){C(H);b.parentNode.removeChild(b);b=null};b.fp_getStatus=function(){var M=0;var N=0;try{M=b.buffered.start();N=b.buffered.end()}catch(L){}return{bufferStart:M,bufferEnd:N,state:q,time:b.fp_getTime(),muted:b.muted,volume:b.fp_getVolume()}};b.fp_getState=function(){return q};b.fp_startBuffering=function(){if(q==t){b.load()}};b.fp_setPlaylist=function(M){d("Setting playlist");m=0;for(var L=0;L<M.length;L++){M[L]=K(M[L])}G=M;$f.fireEvent(e.id(),"onPlaylistReplace",M)};b.fp_addClip=function(M,L){M=K(M);G.splice(L,0,M);$f.fireEvent(e.id(),"onClipAdd",M,L)};b.fp_updateClip=function(M,L){i(G[L],M);return G[L]};b.fp_getVersion=function(){return"3.2.3"};b.fp_isFullscreen=function(){return false};b.fp_toggleFullscreen=function(){if(b.fp_isFullscreen()){b.webkitExitFullscreen()}else{b.webkitEnterFullscreen()}};$f.each(("toggleFullscreen,stopBuffering,reset,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled,addCuepoints,css,animate,showPlugin,hidePlugin,togglePlugin,fadeTo,invoke,loadPlugin").split(","),function(){var L=this;b["fp_"+L]=function(){d("ERROR: unsupported API on iDevices "+L);return false}})}function A(){var V=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"];var N=function(X){d("Got event "+X.type,X)};for(var P=0;P<V.length;P++){b.addEventListener(V[P],N)}var K=function(X){d("got onBufferEmpty event "+X.type);C(F);$f.fireEvent(e.id(),"onBufferEmpty",m)};b.addEventListener("emptied",K,false);b.addEventListener("waiting",K,false);var M=function(X){if(k==t||k==F){}else{d("Restoring old state "+h(k));C(k)}$f.fireEvent(e.id(),"onBufferFull",m)};b.addEventListener("canplay",M,false);b.addEventListener("canplaythrough",M,false);var L=function(X){b.fp_updateClip({duration:b.duration,metaData:{duration:b.duration}},m);G[m].duration=b.duration;$f.fireEvent(e.id(),"onMetaData",m,G[m])};b.addEventListener("loadedmetadata",L,false);b.addEventListener("durationchange",L,false);var U=function(X){if(q==B){if(!z("Resume")){d("Resume disallowed, pausing");b.fp_pause();return D(X)}$f.fireEvent(e.id(),"onResume",m)}C(w);if(!I){I=true;$f.fireEvent(e.id(),"onStart",m)}};b.addEventListener("playing",U,false);var R=function(X){if(!z("Finish")){if(G.length==1){d("Active playlist only has one clip, onBeforeFinish returned false. Replaying");x()}else{if(m!=(G.length-1)){d("Not the last clip in the playlist, but onBeforeFinish returned false. Returning to the beginning of current clip");b.fp_seek(0)}else{d("Last clip in playlist, but onBeforeFinish returned false, start again from the beginning");b.fp_play(0)}}return D(X)}C(f);$f.fireEvent(e.id(),"onFinish",m);if(G.length>1&&m<(G.length-1)){d("Not last clip in the playlist, moving to next one");b.fp_play(++m,false,true)}};b.addEventListener("ended",R,false);var Q=function(X){C(s,true);$f.fireEvent(e.id(),"onError",m,201);if(u.onFail&&u.onFail instanceof Function){u.onFail.apply(e,[])}};b.addEventListener("error",Q,false);var T=function(X){d("got pause event from player"+e.id());if(y){return}if(q==F&&k==t){d("forcing play");setTimeout(function(){b.play()},0);return}if(!z("Pause")){b.fp_resume();return D(X)}C(B);$f.fireEvent(e.id(),"onPause",m)};b.addEventListener("pause",T,false);var W=function(X){$f.fireEvent(e.id(),"onBeforeSeek",m)};b.addEventListener("seeking",W,false);var O=function(X){if(y){y=false;$f.fireEvent(e.id(),"onStop",m)}else{$f.fireEvent(e.id(),"onSeek",m)}d("seek done, currentState",h(q));if(o){o=false;b.fp_play()}else{if(q!=w){b.fp_pause()}}};b.addEventListener("seeked",O,false);var S=function(X){$f.fireEvent(e.id(),"onVolume",b.fp_getVolume())};b.addEventListener("volumechange",S,false)}function j(){b.fp_play(0)}function p(){}if(n||u.simulateiDevice){if(!window.flashembed.__replaced){var g=window.flashembed;window.flashembed=function(M,R,N){if(typeof M=="string"){M=document.getElementById(M.replace("#",""))}if(!M){return}var Q=window.getComputedStyle(M,null);var P=parseInt(Q.width);var K=parseInt(Q.height);while(M.firstChild){M.removeChild(M.firstChild)}var L=document.createElement("div");var O=document.createElement("video");L.appendChild(O);M.appendChild(L);L.style.height=K+"px";L.style.width=P+"px";L.style.display="block";L.style.position="relative";L.style.background="-webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.5)), to(rgba(0, 0, 0, 0.7)))";L.style.cursor="default";L.style.webkitUserDrag="none";O.style.height="100%";O.style.width="100%";O.style.display="block";O.id=R.id;O.name=R.id;O.style.cursor="pointer";O.style.webkitUserDrag="none";O.type="video/mp4";O.playerConfig=N.config;$f.fireEvent(N.config.playerId,"onLoad","player")};flashembed.getVersion=g.getVersion;flashembed.asString=g.asString;flashembed.isSupported=function(){return true};flashembed.__replaced=true}var a=e._fireEvent;e._fireEvent=function(K){if(K[0]=="onLoad"&&K[1]=="player"){b=e.getParent().querySelector("video");if(u.controls){b.controls="controls"}l();A();C(s,true);b.fp_setPlaylist(b.playerConfig.playlist);j();a.apply(e,[K])}var L=q!=H;if(q==H&&typeof K=="string"){L=true}if(L){return a.apply(e,[K])}};e._swfHeight=function(){return parseInt(b.style.height)};e.hasiPadSupport=function(){return true}}return e});
