window.addEvent('domready', function() {

    //vpc = new VideoPageController();

    //vpc.run();

    /**
    * photo & album slider
    */
    //MDC (walk to item)

    if ($('box_mdcslider') != null) {
        var topslider = new noobSlide({
            box: $('box_mdcslider'),
            items: $$('#box_mdcslider div.video'),
            addButtons: {
                previous: $('prev_mdcslider'),
                next: $('next_mdcslider')
            },
            size: 121,
            groupsize: 3,
            onWalk: function(currentItem) {
            }
        });
    }       //MDC (walk to item)

    if ($('box_mdcslider9') != null) {
        var topslider2 = new noobSlide({
            box: $('box_mdcslider9'),
            items: $$('#box_mdcslider9 div.morevids'),
            itemsId: '#box_mdcslider9 div.morevids',
            addButtons: {
                previous: $('prev_mdcslider9'),
                next: $('next_mdcslider9')
            },
            size: 363,
            groupsize: 1,
            onWalk: function(currentItem) {
            }
        });
    }

    //MDC (walk to item)
    if ($('box_mdcslider4') != null) {
        _mdc_slider_albums = new noobSlide({
            box: $('box_mdcslider4'),
            items: $$('#box_mdcslider4 div.album'),
            addButtons: {
                previous: $('prev_mdcslider4'),
                next: $('next_mdcslider4')
            },
            size: 114,
            groupsize: 1,
            minGroupsDisplay: 4,
            onWalk: function(currentItem) {
                console.log(arguments);
                $each($$('div.v_toggle.active'), function(item, idx, o) { $(item).removeClass('active'); });
                $(currentItem).addClass('active');
                VPC.toggleAlbum(currentItem);
            }
        });
    }

    // TODO: this shouldn't be a global variable, figure out a better way - neeraj
    bottomslider_fav = new noobSlide({
        box: $('box_mdcslider_fav'),
        items: $$('#box_mdcslider_fav div.fav'),
        itemsId: '#box_mdcslider_fav div.fav',
        addButtons: {
            previous: new Array($$('#favelist .favbuttons .previousbutton'), $$('#favelist .favbuttons #secondset .previousbutton')),
            next: new Array($$('#favelist .favbuttons .nextbutton'), $$('#favelist .favbuttons #secondset .nextbutton'))
        },
        nextItemToFetch: 2,
        size: 200,
        groupsize: 1,
        onWalk: function(currentItem) { },
        onNext: function() {
            var me = this;
            var myRequest = new Request.HTML({
                method: 'get',
                url: '/getfavorites/' + me.nextItemToFetch + '/5/3/1',
                onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
                    me.nextItemToFetch++;
                    me.ajaxUpdate(responseTree); //must call this to add response to dom.
                }
            }).send();
        },
        refresh: function() {
            var me = this;
            var myRequest = new Request.HTML({
                method: 'get',
                url: '/getfavorites/0/5/3/1',
                onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
                    for (var i = 0; i < me.buttons.previous.length; i++) {
                        //console.log("hide previous");

                        if (me.buttons.previous[i].style != null) {
                            me.buttons.previous[i].style.visibility = 'hidden';
                        }
                        if ($type(me.buttons.previous[i]) == 'array') {
                            for (var j = 0; j < me.buttons.next[i].length; j++) {
                                if (me.buttons.previous[i][j].style != null) {
                                    me.buttons.previous[i][j].style.visibility = 'hidden';
                                }
                            }
                        }
                    }
                    // remove all current items
                    me.nextItemToFetch = 1;
                    me.currentIndex = 0;
                    me.box.empty();
                    me.fx.start(me.size * -me.currentIndex);
                    // refetch first group and add it to items
                    me.ajaxUpdate(responseTree); //must call this to add response to dom.

                    // walk to the first item and kick off prefetching
                    me.next();


                }
            }).send();
        }
    });



    //MDC (walk to item)
    //        try {
    if ($('box_mdcslider_top') != null) {
        var bottomslider_top = new noobSlide({
            box: $('box_mdcslider_top'),
            items: $$('#box_mdcslider_top div.fav'),
            itemsId: '#box_mdcslider_top div.fav',
            addButtons: {
                previous: new Array($$('#toplist .favbuttons .previousbutton'), $$('#toplist .favbuttons #secondset .previousbutton')),
                next: new Array($$('#toplist .favbuttons .nextbutton'), $$('#toplist .favbuttons #secondset .nextbutton'))
            },
            size: 200,
            groupsize: 1,
            onWalk: function(currentItem) {
                //  if (this.c
            }
        });

    }
    // } catch(e) {
    // }

    //2008-10-10 change bio section display
    //MDC (walk to item)
    //var bottomslider_bio = new noobSlide({
    //	box: $('box_mdcslider_bio'),
    //	items: $$('#box_mdcslider_bio div.bio_page'),
    //	addButtons: {
    //		previous: $('prev_mdcslider_bio'),
    //		next: $('next_mdcslider_bio')
    //	},
    //	size: 290,
    //	groupsize: 1,
    //	onWalk: function(currentItem){
    //
    //	}
    // });

    /**
    * tabs
    * Element with id 'demo-block' is the container and all h4-elements
    * inside are fetched as tab headers. The following elements are their
    * content.
    */

});

$j(document).ready(function()
{
    if ($j("#box_mdcslider4").children().length == 0)
        $j("#box_mdcslider4").parents(".section").hide();
});