YUI({
    gallery: 'gallery-2010.03.30-17-26'
}).use('node', 'gallery-effects', function(Y) {
    Y.on('contentready', function() {
        var scrollArea = Y.one('#content');
        var content = Y.one('#content-scrollable');

        var scrollHeight = parseInt(scrollArea.getComputedStyle('height'));
        var contentHeight = parseInt(content.getComputedStyle('height'));
        var scrollPosition = 0;


        if (contentHeight > scrollHeight) {
            Y.one('#content-scroll-controls').setStyle('display', 'block');

            var scrollUpButton = Y.one('#content-scroll-controls .content-scroll-up-button');
            var scrollDownButton = Y.one('#content-scroll-controls .content-scroll-down-button');

            //enableControls();

            scrollUpButton.on('click', function(e) {
                if (scrollPosition > 0) {
                    scrollPosition -= scrollHeight;
                    disableControls();
                    content.move({ x:0, y:scrollHeight, mode: "relative", easing: Y.Easing.easeIn, duration: 0.5, afterFinish: enableControls });
                }
            });
            
            scrollDownButton.on('click', function(e) {
                if ((contentHeight - scrollPosition) > scrollHeight) {
                    scrollPosition += scrollHeight;
                    disableControls();
                    content.move({ x:0, y:-scrollHeight, mode: "relative", easing: Y.Easing.easeIn, duration: 0.5, afterFinish: enableControls });
                }
            });

            function disableControls() {
                scrollUpButton.addClass('disabled');
                scrollDownButton.addClass('disabled');
            }

            function enableControls() {
                if (scrollPosition > 0) {
                    scrollUpButton.removeClass('disabled');
                } else {
                    scrollUpButton.addClass('disabled');
                }
                if ((contentHeight - scrollPosition) > scrollHeight) {
                    scrollDownButton.removeClass('disabled');
                } else {
                    scrollDownButton.addClass('disabled');
                }
            }
        }

    }, 'body');
});
