/**
 * flowplayer.playlist.js 3.0.0-beta1. Flowplayer JavaScript plugin.
 * 
 * This file is part of Flowplayer, http://flowplayer.org
 *
 * Author: Tero Piirainen, <support@flowplayer.org>
 * Copyright (c) 2008 Flowplayer Ltd
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version: 3.0.0-beta1 - Mon Nov 03 2008 15:39:01 GMT-0000 (GMT+00:00)
 */
(function($){$f.addPlugin("playlist",function(wrap,options){var self=this;var opts={playingClass:'playing',pausedClass:'paused',progressClass:'progress',template:'<a href="${url}">${title}</a>',loop:false};$.extend(opts,options);wrap=$(wrap);var manual=self.getPlaylist().length<2;var els=null;if(!manual){var template=wrap.is(":empty")?opts.template:wrap.html();wrap.empty();$.each(self.getPlaylist(),function(){var clip=this;var el=template;$.each(clip,function(key,val){el=el.replace("$\{"+key+"\}",val).replace("$%7B"+key+"%7D",val);});el=$(el);el.click(function(){return play(el,clip.index);});wrap.append(el);});els=wrap.children();}else{els=wrap.children();if(els.eq(0).hasClass("__scrollable")){els=els.children();}els.each(function(){var el=$(this);el.click(function(){return play(el,el.attr("href"));});});self.getClip(0).update({url:els.eq(0).attr("href")});}function play(el,clip){if(el.hasClass(opts.playingClass)||el.hasClass(opts.pausedClass)){self.toggle();}else{el.addClass(opts.progressClass);self.play(clip);}return false;}function clearCSS(){els.removeClass(opts.playingClass);els.removeClass(opts.pausedClass);els.removeClass(opts.progressClass);}function getEl(clip){return(manual)?els.filter("[@href="+clip.url+"]"):els.eq(clip.index);}self.onStart(function(clip){clearCSS();getEl(clip).addClass(opts.playingClass);});self.onPause(function(clip){getEl(clip).removeClass(opts.playingClass).addClass(opts.pausedClass);});self.onResume(function(clip){getEl(clip).removeClass(opts.pausedClass).addClass(opts.playingClass);});self.onFinish(function(clip){var el=getEl(clip);if(!el.next().length){if(opts.loop){els.eq(0).click();}else{self.unload();}}else if(manual){el.next().click();}el.removeClass(opts.playingClass);});self.onUnload(function(){clearCSS();});return self;});})(jQuery);