		
MBmedia = function () {
	return {
        loadYtVideo: function (videoUrl, autoplay,n) {
            swfobject.embedSWF(videoUrl + '&rel=1&border=0&fs=1&autoplay=' + 
                (autoplay?1:0), 'videoplayer'+n, '640', '385', '9.0.0', false, 
                false, {allowfullscreen: 'true'});
        },
        buildYtList: function (data,n) {
            var feed = data.feed;
            var entries = feed.entry || [];
            var html = ['<div class="videoplayer" id="','videoplayer'+n,'"></div>','<div class="videolist">'];
            for (var i = 0; i < entries.length; i++) {
                var entry = entries[i];
                var title = entry.title.$t;
                var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
                var videoUrl = entries[i].media$group.media$content[0].url;
                html.push('<div class="videoentry" onclick="MBmedia.loadYtVideo(\'', videoUrl, '\', true,\'',n,'\')">',
                  '<img class="videothumb" src="',thumbnailUrl, '"/>', '<div class="videotitle">',title, '</div></div>');
            }
            html.push('</div>');
            document.getElementById('videocontainer'+n).innerHTML = html.join('');
            if (entries.length > 0) {
                MBmedia.loadYtVideo(entries[0].media$group.media$content[0].url, false,n);
            }
        },
        loadOwnVideo: function (videoURL, autoplay,containerId) {
            $f(containerId, "/static/scripts/flowplayer-3.1.5.swf",
                    {
                        clip:{
                            url:videoURL,
                            scaling:'fit',
                            accelerated:true,
                            autoBuffering:true,
                            autoPlay:autoplay
                        }
                    }); 
        },
        buildOwnList: function (listURL,n) {
            var req = new Request({
                url: listURL,
                method:'get',
                onSuccess: function (t,feed) {
                    var playlist=feed.getElement('playlist');
                    var entries = playlist.getElement('tracklist').getElements('track');
                    var html = ['<div class="videoplayer" id="','videoplayer'+n,'"></div>','<div class="videolist">'];
                    for (var i = 0; i < entries.length; i++) {
                       var entry = entries[i];
                       var title = entry.getElement('title').get('text');
                       var summary = entry.getElement('annotation');
                       if (summary) summary=summary.get('text');
                       var thumbnailUrl = entry.getElement('image');
                       if (thumbnailUrl) thumbnailUrl = thumbnailUrl.get('text');
                       var videoUrl = entry.getElement('location').get('text');
                        html.push('<div class="videoentry" onclick="MBmedia.loadOwnVideo(\'', videoUrl, '\', true,','\'videoplayer\'+\'',n,'\');">',
                            '<img class="videothumb" src="');
                        if (thumbnailUrl) {
                            html.push(thumbnailUrl);
                        } else {
                            html.push('/static/images/logo_image.png');
                        } 
                        html.push('"/>','<div class="videotitle">');
                        if (summary) {
                            html.push('<p>',title, '</p><p>',summary,'</p>');
                        } else {
                            html.push(title);
                        }
                        html.push('</div></div>');
                     }
                    html.push('</div>');
                    document.getElementById('videocontainer'+n).innerHTML = html.join('');
                    if (entries.length > 0) {
                        MBmedia.loadOwnVideo(entries[0].getElement('location').get('text'), false,'videoplayer'+n);
                    }
                      
                   
                }
            });
            req.send();
        },
        loadOwnAudio: function (audioURL, containerId) {
            $f(containerId, "/static/scripts/flowplayer-3.1.5.swf", {
                playlist: [ 
                    // first entry in a playlist work as a splash image for the MP3 clip 
                    '/static/images/audio_player.png', 
                    { 
                        // our song 
                        url: audioURL, 
                        autoPlay: false
                    } 
                ], 
                plugins:  { 
                   // and a bit of controlbar skinning   
                    controls: { 
                        backgroundColor:'#4A7EB5', 
                        fullscreen: false 
                    } 
                }         
     
            });
        }
	}
}();
