/*
 * eTeanga Playlist for jQuery.jPlayer Plugin
 * http://www.jplayer.org
 *
 * Copyright (c) 2011 Happyworm Ltd
 * Dual licensed under the MIT and GPL licenses.
 *  - http://www.opensource.org/licenses/mit-license.php
 *  - http://www.gnu.org/copyleft/gpl.html
 *
 * Author: Mark J Panaghiston
 * Version: 1.1.0 (jPlayer 2.1.0)
 * Date: 20th September 2011
 */

(function(a){eTeangaPlaylist=function(c){var b=this;this.options=c||{};this.cssSelector={jPlayer:"#jquery_jplayer",container:"#jp_container"};this.cssClass={audio:"jppl-audio",playing:"jppl-playing",download:"jppl-download"};this.current=-1;this.playlist=[];this.androidFix=this.isPlaying=!1;this.options.cssSelectorAncestor=this.cssSelector.container;this.options.supplied="mp3";this.options.wmode="window";a(this.cssSelector.jPlayer).bind(a.jPlayer.event.ready,function(){b.getPlaylist()});a(this.cssSelector.jPlayer).bind(a.jPlayer.event.ended,
function(){a(this).trigger(a.jPlayer.event.pause)});a(this.cssSelector.jPlayer).bind(a.jPlayer.event.play,function(){b.playlist[b.current].button.addClass(b.cssClass.playing).attr("title","Stop");b.isPlaying=!0});a(this.cssSelector.jPlayer).bind(a.jPlayer.event.pause,function(){b.playlist[b.current].button.removeClass(b.cssClass.playing).attr("title","Play");b.isPlaying=!1});a(this.cssSelector.jPlayer).bind(a.jPlayer.event.progress,function(){if(b.androidFix)b.androidFix=!1,a(b.cssSelector.jPlayer).jPlayer("play")});
a(this.cssSelector.jPlayer).bind(a.jPlayer.event.error,function(b){b.jPlayer.error.type===a.jPlayer.error.URL&&a(this).trigger(a.jPlayer.event.pause)});a("."+this.cssClass.audio).click(function(){var c=a(this).data("index");if(b.current!==c)b.playlistChange(c);else if(b.isPlaying){if(a(b.cssSelector.jPlayer).jPlayer("stop"),a.jPlayer.platform.android)b.androidFix=!1,a(b.cssSelector.jPlayer).trigger(a.jPlayer.event.pause)}else a.jPlayer.platform.android?b.playlistChange(c):a(b.cssSelector.jPlayer).jPlayer("play");
a(this).blur();return!1});a(this.cssSelector.jPlayer).jPlayer(this.options)};eTeangaPlaylist.prototype={getPlaylist:function(){var c=this,b=0;this.current=-1;this.playlist=[];a("."+this.cssClass.audio).each(function(){a(this).data("index",b).attr("title","Play");c.playlist[b]={mp3:a(this).attr("href"),button:a(this)};b++});c.playlistInit(!1)},playlistInit:function(a){a?this.playlistChange(0):this.playlistConfig(0)},playlistConfig:function(c){this.playlist[this.current]&&this.playlist[this.current].button.length&&
this.playlist[this.current].button.removeClass(this.cssClass.playing).attr("title","Play");this.current=c;return this.playlist[this.current]?(a(this.cssSelector.jPlayer).jPlayer("setMedia",this.playlist[this.current]),!0):!1},playlistChange:function(c){return this.playlistConfig(c)?(a.jPlayer.platform.android?(this.androidFix=!0,a(this.cssSelector.jPlayer).trigger(a.jPlayer.event.play)):a(this.cssSelector.jPlayer).jPlayer("play"),!0):!1}}})(jQuery);
