/*
Copyright (c) 2009 Happyworm Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Author: Mark J Panaghiston
Version: 0.2.5.beta
Documentation: www.happyworm.com/jquery/jplayer
*/

(function(a){a.jPlayerCount=0;a.each({jPlayer:function(b){a.jPlayerCount++;var c={ready:null,cssPrefix:"jqjp",swfPath:"../../../../script",volume:80,oggSupport:false,position:"absolute",width:0,height:0,top:0,left:0,quality:"high",bgcolor:"#000000",html5:false};a.extend(c,b);b={id:a(this).attr("id"),swf:c.swfPath+(c.swfPath!=""?"/":"")+"Jplayer.swf",fid:c.cssPrefix+"_flash_"+a.jPlayerCount,aid:c.cssPrefix+"_audio_"+a.jPlayerCount,hid:c.cssPrefix+"_force_"+a.jPlayerCount,i:a.jPlayerCount};a.extend(c, b);a.fn["jPlayerReady"+c.i]=c.ready;a(this).prepend('<audio id="'+c.aid+'"></audio>');b=a("#"+c.aid).get();b={canPlayMP3:Boolean(b[0].canPlayType?""!=b[0].canPlayType("audio/mpeg")&&"no"!=b[0].canPlayType("audio/mpeg"):false),canPlayOGG:Boolean(b[0].canPlayType?""!=b[0].canPlayType("audio/ogg")&&"no"!=b[0].canPlayType("audio/ogg"):false),audio:b[0]};a.extend(c,b);b={html5:Boolean(c.oggSupport?c.canPlayOGG?true:c.canPlayMP3:c.canPlayMP3)};c.html5&&a.extend(c,b);a(this).data("jPlayer.config",c);b={setButtons:function(d, e){d=a(this).data("jPlayer.cssId.play");var j=a(this).data("jPlayer.cssId.pause");a(this).data("jPlayer.config");if(d!=null&&j!=null)if(e){e=a(this).data("jPlayer.cssDisplay.pause");a("#"+d).css("display","none");a("#"+j).css("display",e)}else{e=a(this).data("jPlayer.cssDisplay.play");a("#"+d).css("display",e);a("#"+j).css("display","none")}}};var f={setFile:function(d,e){d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_setFile_mp3(e.mp3);a(this).trigger("jPlayer.setButtons", false)},play:function(){var d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_play_mp3()&&a(this).trigger("jPlayer.setButtons",true)},pause:function(){var d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_pause_mp3()&&a(this).trigger("jPlayer.setButtons",false)},stop:function(){var d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_stop_mp3()&&a(this).trigger("jPlayer.setButtons",false)},playHead:function(d,e){d=a(this).data("jPlayer.config").fid; a(this).data("jPlayer.getMovie")(d).fl_play_head_mp3(e)&&a(this).trigger("jPlayer.setButtons",true)},playHeadTime:function(d,e){d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_play_head_time_mp3(e)&&a(this).trigger("jPlayer.setButtons",true)},volume:function(d,e){a(this).data("jPlayer.config").volume=e;d=a(this).data("jPlayer.config").fid;a(this).data("jPlayer.getMovie")(d).fl_volume_mp3(e)}},i={setFile:function(d,e){a("#"+a(this).data("jPlayer.config").aid).remove();a(this).prepend('<audio id="'+ a(this).data("jPlayer.config").aid+'"></audio>');d=a("#"+a(this).data("jPlayer.config").aid).get();a(this).data("jPlayer.config").audio=d[0];a(this).data("jPlayer.config").audio.volume=a(this).data("jPlayer.config").volume/100;if(a(this).data("jPlayer.config").oggSupport&&a(this).data("jPlayer.config").canPlayOGG)a(this).data("jPlayer.config").audio.src=e.ogg;else a(this).data("jPlayer.config").audio.src=e.mp3;a(this).trigger("jPlayer.setButtons",false)},play:function(){a(this).data("jPlayer.config").audio.play(); a(this).trigger("jPlayer.setButtons",true);clearInterval(a(this).data("jPlayer.interval.jPlayerController"));a(this).data("jPlayer.interval.jPlayerController",window.setInterval(a(this).jPlayerController,50,a(this),false))},pause:function(){a(this).data("jPlayer.config").audio.pause();a(this).trigger("jPlayer.setButtons",false);clearInterval(a(this).data("jPlayer.interval.jPlayerController"))},stop:function(){a(this).data("jPlayer.config").audio.currentTime=0;a(this).trigger("jPlayer.pause");a(this).jPlayerController(a(this), true)},playHead:function(d,e){a(this).data("jPlayer.config").audio.currentTime=a(this).data("jPlayer.config").audio.buffered?e*a(this).data("jPlayer.config").audio.buffered.end()/100:e*a(this).data("jPlayer.config").audio.duration/100;a(this).trigger("jPlayer.play")},playHeadTime:function(d,e){a(this).data("jPlayer.config").audio.currentTime=e/1E3;a(this).trigger("jPlayer.play")},volume:function(d,e){a(this).data("jPlayer.config").volume=e;a(this).data("jPlayer.config").audio.volume=e/100;a(this).jPlayerVolume(e)}}; c.html5?a.extend(b,i):a.extend(b,f);for(var g in b){f="jPlayer."+g;a(this).unbind(f);a(this).bind(f,b[g])}a(this).data("jPlayer.getMovie",function(d){return document[d]});g=function(d){var e=false,j;if(window.ActiveXObject)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+d);e=true}catch(k){}else if(navigator.plugins&&navigator.mimeTypes.length>0)if(j=navigator.plugins["Shockwave Flash"])if(navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/,"$1")>=d)e=true;return e}; if(!c.html5)if(g(8))if(a.browser.msie){b='<object id="'+c.fid+'"';b+=' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';b+=' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"';b+=' type="application/x-shockwave-flash"';b+=' width="'+c.width+'" height="'+c.height+'">';b+="</object>";g=[];g[0]='<param name="movie" value="'+c.swf+'" />';g[1]='<param name="quality" value="high" />';g[2]='<param name="FlashVars" value="id='+escape(c.id)+"&fid="+escape(c.fid)+"&vol="+ c.volume+'" />';g[3]='<param name="allowScriptAccess" value="always" />';g[4]='<param name="bgcolor" value="'+c.bgcolor+'" />';b=document.createElement(b);for(f=0;f<g.length;f++)b.appendChild(document.createElement(g[f]));a(this).html(b)}else{g='<embed name="'+c.fid+'" id="'+c.fid+'" src="'+c.swf+'"';g+=' width="'+c.width+'" height="'+c.height+'" bgcolor="'+c.bgcolor+'"';g+=' quality="high" FlashVars="id='+escape(c.id)+"&fid="+escape(c.fid)+"&vol="+c.volume+'"';g+=' allowScriptAccess="always"';g+= ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';a(this).html(g)}else{a("#playlist_single").append("<p>Le Flash Player est n&eacute;cessaire pour &eacute;couter les sons. <a href='http://get.adobe.com/flashplayer' target='_blank'>Installer le Flash Player !</a></p>");a("#playlist_list").append("<p>Le Flash Player est n&eacute;cessaire pour &eacute;couter les sons. <a href='http://get.adobe.com/flashplayer' target='_blank'>Installer le Flash Player !</a></p>")}g= '<div id="'+c.hid+'"></div>';a(this).append(g);a(this).css({position:c.position,top:c.top,left:c.left});a("#"+c.hid).css({"text-indent":"-9999px"});if(c.html5){var h=a(this);window.setTimeout(function(){h.volume(c.volume);h.jPlayerReady()},100)}return a(this)},setFile:function(b,c){b={mp3:b,ogg:c};a(this).trigger("jPlayer.setFile",b);return a(this)},play:function(){a(this).trigger("jPlayer.play");return a(this)},pause:function(){a(this).trigger("jPlayer.pause");return a(this)},stop:function(){a(this).trigger("jPlayer.stop"); return a(this)},playHead:function(b){a(this).trigger("jPlayer.playHead",b);return a(this)},playHeadTime:function(b){a(this).trigger("jPlayer.playHeadTime",b);return a(this)},volume:function(b){a(this).trigger("jPlayer.volume",b);return a(this)},jPlayerId:function(b,c){if(c!=null)if(eval("$(this)."+b)!=null){a(this).data("jPlayer.cssId."+b,c);var f=a(this).data("jPlayer.config").id;eval('var myHandler = function(e) { $("#'+f+'").'+b+"(e); return false; }");a("#"+c).click(myHandler).hover(a(this).jPlayerRollOver, a(this).jPlayerRollOut).data("jPlayerId",f);f=a("#"+c).css("display");a(this).data("jPlayer.cssDisplay."+b,f);b=="pause"&&a("#"+c).css("display","none")}else alert("Unknown function assigned in: jPlayerId( fn="+b+", id="+c+" )");else{c=a(this).data("jPlayer.cssId."+b);if(c!=null)return c;else{alert("Unknown function id requested: jPlayerId( fn="+b+" )");return false}}return a(this)},loadBar:function(b){var c=a(this).data("jPlayer.cssId.loadBar");if(c!=null){var f=a("#"+c).offset();b=b.pageX-f.left; c=a("#"+c).width();c=100*b/c;a(this).playHead(c)}},playBar:function(b){a(this).loadBar(b)},onProgressChange:function(b){a.fn["jPlayerOnProgressChange"+a(this).data("jPlayer.config").i]=b;return a(this)},jPlayerOnProgressChange:function(b,c,f,i,g){var h=a(this).data("jPlayer.cssId.loadBar");h!=null&&a("#"+h).width(b+"%");h=a(this).data("jPlayer.cssId.playBar");h!=null&&a("#"+h).width(c+"%");a(this)["jPlayerOnProgressChange"+a(this).data("jPlayer.config").i](b,c,f,i,g);a(this).jPlayerForceUpdate(); return true},jPlayerController:function(b,c){var f=0,i=0,g=0,h=0,d=0;if(b.data("jPlayer.config").audio.readyState>=1){f=b.data("jPlayer.config").audio.currentTime*1E3;i=b.data("jPlayer.config").audio.duration*1E3;g=100*f/i;h=b.data("jPlayer.config").audio.buffered?100*b.data("jPlayer.config").audio.buffered.end()/b.data("jPlayer.config").audio.duration:100;d=b.data("jPlayer.config").audio.buffered?100*b.data("jPlayer.config").audio.currentTime/b.data("jPlayer.config").audio.buffered.end():g}if(c)b.jPlayerOnProgressChange(h, 0,0,0,i);else{b.jPlayerOnProgressChange(h,d,g,f,i);if(b.data("jPlayer.config").audio.ended){clearInterval(b.data("jPlayer.interval.jPlayerController"));b.jPlayerOnSoundComplete()}}},volumeMin:function(){a(this).volume(0);return a(this)},volumeMax:function(){a(this).volume(100);return a(this)},volumeBar:function(b){var c=a(this).data("jPlayer.cssId.volumeBar");if(c!=null){var f=a("#"+c).offset();b=b.pageX-f.left;c=a("#"+c).width();c=100*b/c;a(this).volume(c)}},volumeBarValue:function(b){a(this).volumeBar(b)}, jPlayerVolume:function(b){var c=a(this).data("jPlayer.cssId.volumeBarValue");if(c!=null){a("#"+c).width(b+"%");a(this).jPlayerForceUpdate();return true}},onSoundComplete:function(b){a.fn["jPlayerOnSoundComplete"+a(this).data("jPlayer.config").i]=b;return a(this)},jPlayerOnSoundComplete:function(){a(this).trigger("jPlayer.setButtons",false);a(this)["jPlayerOnSoundComplete"+a(this).data("jPlayer.config").i]();return true},jPlayerBufferState:function(b){var c=a(this).data("jPlayer.cssId.loadBar");if(c!= null){var f=a(this).data("jPlayer.config").cssPrefix;b?a("#"+c).addClass(f+"_buffer"):a("#"+c).removeClass(f+"_buffer");return true}else return false},bufferMsg:function(){},jPlayerBufferMsg:function(b){var c=a(this).data("jPlayer.cssId.bufferMsg");if(c!=null){a("#"+c).html(b);return true}else return false},jPlayerForceUpdate:function(){var b=a(this).data("jPlayer.config").hid;a("#"+b).html(Math.random())},jPlayerRollOver:function(){var b=a(this).data("jPlayerId");b=a("#"+b).data("jPlayer.config").cssPrefix; a(this).addClass(b+"_hover")},jPlayerRollOut:function(){var b=a(this).data("jPlayerId");b=a("#"+b).data("jPlayer.config").cssPrefix;a(this).removeClass(b+"_hover")},jPlayerReady:function(){a(this)["jPlayerReady"+a(this).data("jPlayer.config").i]()},jPlayerGetInfo:function(b){return a(this).data("jPlayer.config")[b]}},function(b){a.fn[b]=this})})(jQuery);
