
/* - collective.flowplayer.js - */
(function($) {
        $(function() { 
            $('.autoFlowPlayer').each(function() {
                var config = {
    "canvas": {
        "backgroundGradient": "none"
    }, 
    "clip": {
        "scaling": "fit", 
        "autoBuffering": true, 
        "autoPlay": false
    }, 
    "toolbar_flash_controlsbar": true, 
    "fullscreenContentHeight": "20%", 
    "screen": {
        "top": 24
    }, 
    "vtumaster.flowplayer_installed": "", 
    "key": "#$d2ce644ac8c1f2017eb", 
    "plugins": {
        "content": {
            "style": {
                "body": {
                    "color": "#ffffff", 
                    "fontFamily": "Verdana", 
                    "fontSize": 18, 
                    "textAlign": "center"
                }
            }, 
            "backgroundColor": "transparent", 
            "bottom": 5, 
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bvtumaster.flowplayer/flowplayer.content-3.2.0.swf", 
            "button": {
                "top": 0
            }, 
            "height": 50, 
            "width": "90%", 
            "backgroundGradient": "none", 
            "border": 0, 
            "textDecoration": "outline"
        }, 
        "captions": {
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bvtumaster.flowplayer/flowplayer.captions-3.2.2.swf", 
            "button": {
                "right": 5, 
                "bottom": 5
            }, 
            "captionTarget": "content"
        }, 
        "audio": {
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.audio.swf"
        }, 
        "controls": {
            "fullscreen": true, 
            "all": false, 
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.controls.swf", 
            "top": 0, 
            "volume": false, 
            "autoHide": "never"
        }
    }
};
                var $self = $(this);
                if ($self.is('.minimal')) {
                    //config.plugins.controls = null; 
                    //vtu uses a different minimal approach so fare only no time shown
                    config.plugins.controls.time = false;                    
                };
                var audio = $self.is('.audio');                
                if (audio && !$self.is('.minimal')) {
                    //dont have 500 px here it likely break grid etc...
                    //$self.width(500);
                    config.plugins.controls.all = false;
                    config.plugins.controls.play = true;
                    config.plugins.controls.scrubber = true;
                    config.plugins.controls.mute = true;
                    config.plugins.controls.volume = true;
                }
                var video = $self.is('.video');
                portlet_parents = $self.parents('.portlet');
                if (video && portlet_parents.length<1 && config.plugins.captions.url) {
                    config.clip.url = $self.find('a').attr('href');

                    jq.ajax({
                        url:'getCaptionsUrl',
                        context:this,
                        type:'GET',
                        async: false,
                        data: {'video_url':config.clip.url},
                        error:
                            function(){
                                //console.info('Captions lookup failed at '+config.clip.url+' for.');
                                config.plugins.captions = null;
                            },
                        success:
                            function(data){
                                if (data.length > 0) {
                                    //console.info('Found captions at '+config.clip.url+' for .');
                                    //console.info('Setting captionUrl =  '+data);
                                    config.clip.captionUrl = data;
                                } else {
                                    //console.info('No captions found at '+config.clip.url+' for.');
                                    config.plugins.captions = null;
                                }
                            }
                        });
                } else {
                    config.plugins.captions = null;
                }
                if ($self.is('div')) {
                    config.clip.baseUrl = $('base').attr('href');
                    config.clip.url = $self.find('a').attr('href');
                    // Ignore global autoplay settings
                    if ($self.find('img').length == 0) {
                        // no image. Don't autoplay, remove all elements inside the div to show player directly.
                        config.clip.autoPlay = false;
                        $self.empty();
                    } else {
                        // Clip is probably linked as image, so autoplay the clip after image is clicked
                        config.clip.autoPlay = true;
                    }
                }
                flowplayer(this, {"src": "http://www.ui.dk/++resource++vtumaster.flowplayer/flowplayer.commercial-3.1.5.swf", "wmode": "opaque"}, config).onLoad( function() { this.setVolume(50); })
.onFullscreen( function() { this.getPlugin("content").css({height:"20%"}); })
.onFullscreenExit( function() { this.getPlugin("content").css({height:50}); });
                $('.flowPlayerMessage').remove();
            });
            $('.playListFlowPlayer').each(function() {
                var config = {
    "canvas": {
        "backgroundGradient": "none"
    }, 
    "clip": {
        "scaling": "fit", 
        "autoBuffering": true, 
        "autoPlay": false
    }, 
    "toolbar_flash_controlsbar": true, 
    "fullscreenContentHeight": "20%", 
    "screen": {
        "top": 24
    }, 
    "vtumaster.flowplayer_installed": "", 
    "key": "#$d2ce644ac8c1f2017eb", 
    "plugins": {
        "content": {
            "style": {
                "body": {
                    "color": "#ffffff", 
                    "fontFamily": "Verdana", 
                    "fontSize": 18, 
                    "textAlign": "center"
                }
            }, 
            "backgroundColor": "transparent", 
            "bottom": 5, 
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bvtumaster.flowplayer/flowplayer.content-3.2.0.swf", 
            "button": {
                "top": 0
            }, 
            "height": 50, 
            "width": "90%", 
            "backgroundGradient": "none", 
            "border": 0, 
            "textDecoration": "outline"
        }, 
        "captions": {
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bvtumaster.flowplayer/flowplayer.captions-3.2.2.swf", 
            "button": {
                "right": 5, 
                "bottom": 5
            }, 
            "captionTarget": "content"
        }, 
        "audio": {
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.audio.swf"
        }, 
        "controls": {
            "fullscreen": true, 
            "all": false, 
            "url": "http%3A//www.ui.dk/%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.controls.swf", 
            "top": 0, 
            "volume": false, 
            "autoHide": "never"
        }
    }
};
                var $self = $(this);
                var audio = $self.is('.audio');
                if (audio) { config.plugins.controls.fullscreen = false; }
                if ($self.is('.minimal')) { config.plugins.controls = null; }
                if ($self.find('img').length > 0) { 
                    // has splash
                    config.clip.autoPlay = true;
                }
                portlet_parents = $self.parents('.portlet');
                var playlist_selector = 'div#flowPlaylist';
                if (portlet_parents.length > 0) {
                    var portlet = true;
                    // playlist has to be bound to unique item
                    playlist_selector_id = portlet_parents.parent().attr('id')+'-playlist';
                    $self.parent().find('.flowPlaylist-portlet-marker').attr('id', playlist_selector_id);
                    playlist_selector = '#'+playlist_selector_id;
                    if (audio && !$self.is('.minimal')) {
                        config.plugins.controls.all = false;
                        config.plugins.controls.play = true;
                        config.plugins.controls.scrubber = true;
                        config.plugins.controls.mute = true;
                        config.plugins.controls.volume = false;
                    }
                } else {
                    var portlet = false;
                }
                if (!portlet) {
                    $("#pl").scrollable({items:playlist_selector, size:4, clickable:false});
                }
                // We dont support captions in playlists yet
                config.plugins.captions = null;

                // manual = playlist is setup using HTML tags, not using playlist array in config
                flowplayer(this, {"src": "http://www.ui.dk/++resource++vtumaster.flowplayer/flowplayer.commercial-3.1.5.swf", "wmode": "opaque"}, config).playlist(playlist_selector, {loop: true, manual: true}).onLoad( function() { this.setVolume(50); })
.onFullscreen( function() { this.getPlugin("content").css({height:"20%"}); })
.onFullscreenExit( function() { this.getPlugin("content").css({height:50}); });
                
                $self.show();
                $('.flowPlayerMessage').remove();

            });
        });
})(jQuery);


