
(function($) {
    var params = {src: "/++resource++collective.flowplayer/FlowPlayerDark.swf"};
    function randomOrder() { return (Math.round(Math.random())-0.5); }
    function updateConfig(config, minimal, audio, splash) {
        if(minimal) {
            config.showFullScreenButton = false;
            config.showStopButton = false;
            config.showVolumeSlider = false;
            config.showScrubber = false;
            config.showMenu = false;
            config.usePlayOverlay = false;
            if(audio) {
                config.showMuteVolumeButton = false;
                config.controlsOverVideo = null;
                config.showScrubber = false;
            }
        } else if(audio) {
            config.showFullScreenButton = false;
            config.showMenu = false;
            config.usePlayOverlay = false;
            config.controlsOverVideo = null;
            config.showScrubber = true;
        }
        if(splash) {
            config.splashImageFile = splash;
        }
    }
    $(function() { 
        
        $('.autoFlowPlayer').each(function() {
            var config = { controlsOverVideo:'ease',
controlBarBackgroundColor:-1,
showVolumeSlider:false,
controlBarGloss:'low',
useNativeFullScreen:true,
autoBuffering:false,
initialVolumePercentage:50,
initialScale:'fit',
usePlayOverlay:true,
loop:false,
autoPlay:false };
            var minimal = $(this).is('.minimal');
            var audio = $(this).is('.audio');
            var splash = null;
            
            var aTag = this;
            if(!$(aTag).is("a"))
                aTag = $(this).find("a").get(0);
            if(aTag == null)
                return;
            config.videoFile = aTag.href;
            
            var img = $(this).find("img").get(0);
            if(img != null) {
                $(this).height($(img).height());
                $(this).width($(img).width());
                splash = $(img).attr('src');
            }
            
            updateConfig(config, minimal, audio, splash);
            flashembed(this, params, {config:config});
            $('.flowPlayerMessage').remove();
        });
        
        $('.playListFlowPlayer').each(function() {
            var config = { controlsOverVideo:'ease',
controlBarBackgroundColor:-1,
showVolumeSlider:false,
controlBarGloss:'low',
useNativeFullScreen:true,
autoBuffering:false,
initialVolumePercentage:50,
initialScale:'fit',
usePlayOverlay:true,
loop:false,
autoPlay:false };
            var minimal = $(this).is('.minimal');
            var audio = $(this).is('.audio');
            var random = $(this).is('.random');
            var splash = null;
            
            var playList = new Array();
            $(this).find('a.playListItem').each(function() {
                playList.push({url: $(this).attr('href')});
            });
            
            var img = $(this).find("img").get(0);
            if(img != null) {
                splash = $(img).attr('src');
            }
            
            if(random) playList.sort(randomOrder);
            
            updateConfig(config, minimal, audio, splash);
            config.showPlayListButtons = (playList.length > 1);
            config.playList = playList;
            flashembed(this, params, {config:config});
            
            $(this).show();
            $('.flowPlayerMessage').remove();
        });
    });
})(jQuery);

