  var YoutubeVideoBox = new Class({
        box:null,
        scroll:null,
        current_scroll_side:0, /* Zero to pierwszy element */
        num_of_scroll_sides:null,
        width_scroll_side:90, /* Szerokosc elementu. */


        initialize: function(options){
            if(!$chk($(options.id)))
                return;

            this.box = $(options.id);

            var movies = this.box.getElements('td');

            this.scroll = new Fx.Scroll('videoBar', { //Na sztywno id
                wait: false,
                duration: 600,
                transition: Fx.Transitions.Back.easeInOut
            });

            this.scroll.toTop();
            $(this.box.id+'_list_next').addEvent('click', function(event) {
                event.stop();
                this.scrollNext();
            }.bind(this));
            $(this.box.id+'_list_prev').addEvent('click', function(event) {
                event.stop();
                this.scrollPrev();
            }.bind(this));

            this.num_of_scroll_sides = Math.ceil(movies.length/3);
        },

        scrollNext: function() {
            if(this.current_scroll_side < this.num_of_scroll_sides - 1) {
                this.current_scroll_side++;
                this.scroll.start(0, this.current_scroll_side * (this.width_scroll_side * 3));
            }
        },

        scrollPrev: function() {
            if(this.current_scroll_side > 0) {
                this.current_scroll_side--;
                this.scroll.start(0, this.current_scroll_side * (this.width_scroll_side * 3));
            }
        }
});


  function LoadVideoBar(initial_content) {
    var vbr;

//     function JKGSvideoBar() {}
//
//     JKGSvideoBar = new GSvideoBar();
    GSvideoBar.prototype.processResults = function(results) {
        if ( results && results.length > 0) {
            this.cssSetClass(this.barBox, this.CL_VIDEOBARBOXFULL);
            this.removeChildren(this.resultsBox);

            var cell;
            var table;
            var row = null;
            if (this.verticalMode) {
            table = this.createTable(this.CL_RESULTTABLE_VERTICAL);
            } else {
            table = this.createTable(this.CL_RESULTTABLE_HORIZONTAL);
            }
            table.setAttribute("align", "left");

            for (var i = 0; i < results.length; i++) {

            var res = results[i];
        //       alert(res);

            var imageScaler;
            var resultBoxHeight;
            var resultClass = null;
            if (this.thumbSize == GSvideoBar.THUMBNAILS_MEDIUM ) {
                // full size image
                imageScaler = {width:100,height:75};
                resultBoxHeight = this.resultBoxHeight;
                resultClass = this.CL_RESULTDIV;
            } else {
                // small size image
                imageScaler = {width:50,height:37};
                resultBoxHeight = this.smallResultBoxHeight;
                resultClass = this.CL_RESULTDIV_SMALL;
            }
            var scaled = GSearch.scaleImage(res.tbWidth, res.tbHeight, imageScaler);
            var img = this.createImage(res.tbUrl, scaled.width, scaled.height, null);

            if (this.externalMaster) {
                img.onclick = this.methodClosure(this.externalMaster, this.externalMaster.playVideo, [res]);
            } else {
                img.onclick = this.methodClosure(this, this.playVideo, [res]);
            }

            // manually set the top padding
            if ((resultBoxHeight - scaled.height) > 0) {
                var padTop = Math.round((resultBoxHeight - scaled.height)/2);
                img.setAttribute("vspace", padTop);
            }

            // compute duration
            var seconds = res.duration;
            var minutes = parseInt(seconds/60);
            var durationString;
            if (minutes > 0) {
                durationString = minutes + "m";
                var remainder = seconds%60;
                if (remainder > 20) {
                durationString += " " + remainder + "s";
                }
            } else {
                durationString = seconds + "s";
            }

            var toolTip = res.titleNoFormatting + " ( " + durationString + " )";
            var div = this.createDiv(null, resultClass);
            div.title = toolTip;
            div.appendChild(img);
            div.onclick = img.onclick;

            var div1 = this.createDiv(null, 'title_description');
            div1.innerHTML += res.titleNoFormatting;
            div.appendChild(div1);

            // create a new row for each result when in vertical mode
            // otherwise, jam everything into a single row.
            if (this.verticalMode) {
                row = this.createTableRow(table);
            } else {
                if (row == null) {
                row = this.createTableRow(table);
                }
            }
            cell = this.createTableCell(row, this.CL_RESULTCELL);
            cell.setAttribute("align", "center");
            cell.appendChild(div);
            }
            this.resultsBox.appendChild(table);
        } else {
            this.cssSetClass(this.barBox, this.CL_VIDEOBARBOXEMPTY);
        }

        if(initial_video_content != '') {
            this.playerInnerBox.innerHTML = initial_video_content;
        }

        new YoutubeVideoBox({id:'multimedia_youtube_box'});
    }

    var options = {
        largeResultSet : true,
        horizontal : true,
        thumbnailSize : GSvideoBar.THUMBNAILS_MEDIUM
    }

    vbr = new GSvideoBar(
                document.getElementById("videoBar"),
                document.getElementById("videoPlayer"),
                GSvideoBar.PLAYER_ROOT_FLOATING,
                options
            );
    vbr.execute("ytchannel:jkaczynskiinfo");

}

