
jQuery.fn.moScroller = function() { // FIXME: nicns kész

    function MOScroller(e) {

        var parent = this;
        this.element = $(e);
        this.scrolling = null;

        var speed = 50;
        var step = 5;
        var height = 55;
        
        var dec = $('<div class="dec" />');
        var inc = $('<div class="inc" />');

        e.css({
            overflow: 'hidden',
            position: 'relative'
        });
        dec.css({
            width: '100%',
            height: height + 'px',
            position: 'absolute',
            //backgroundColor: '#fff',
            //opacity: '0.15',
            top: '0px'
            //cursor: 'url(/images/cursors/cursor_arrow_left.cur), w-resize'
        });
        inc.css({
            width: '100%',
            height: height + 'px',
            position: 'absolute',
            //backgroundColor: '#fff',
            //opacity: '0.15',
            bottom: '0px'
        });
        
        this.scrollUp = function() {
            
            parent.element.scrollTop(parent.element.scrollTop() - step);
            parent.refreshThumbs();

            parent.scrolling = window.setTimeout(function() {
                parent.scrollUp();
            }, speed);
        };

        this.scrollDown = function() {
            
            parent.element.scrollTop(parent.element.scrollTop() + step);
            parent.refreshThumbs();

            parent.scrolling = window.setTimeout(function() {
                parent.scrollDown();
            }, speed);
        };

        this.stop_scroll = function() {

            window.clearTimeout(parent.scrolling);
        };

        this.refreshThumbs = function() {

            dec.css('top', parent.element.scrollTop() + 'px');
            inc.css('bottom', '-' + parent.element.scrollTop() + 'px');

            if(parent.element.scrollTop() < 1)
                dec.hide();
            else
                dec.show();

            if(parent.element.scrollTop() >= parent.element[0].scrollHeight - parent.element.height())
                inc.hide();
            else
                inc.show();
        };

        inc.mouseover(this.scrollDown);
        dec.mouseover(this.scrollUp);
        inc.mouseout(this.stop_scroll);
        dec.mouseout(this.stop_scroll);

        $(e).prepend(dec);
        $(e).append(inc);

        this.refreshThumbs();
    }

    this.each(function(i, el){
        new MOScroller($(this));
    });
}

/* rolloverImage */
var rolloverImage = {

    className: "rolloverImage",

    init: function(matchBy) {

        $(matchBy ? matchBy : 'img.' + rolloverImage.className).each(function(i) {

            $(this).bind({
                mouseenter: function() {rolloverImage.over(this);},
                mouseout: function() {rolloverImage.out(this);}
            });
            /*$(this).find('*').each(function(i) { // FIXME
                $(this).bind(rolloverImage.binds);
            });*/
        });
    },

    over: function(o) {

        if(o.tagName.toLowerCase() == 'img')
            o.src = o.src.replace(/_normal./, "_over.");
        else
            $(o).find('img').each(function(i) {
                this.src = this.src.replace(/_normal./, "_over.");
            });

        document.body.style.cursor = 'pointer';
    },

    out: function(o) {

        if(o.tagName.toLowerCase() == 'img')
            o.src = o.src.replace(/_over./, "_normal.");
        else
            $(o).find('img').each(function(i) {
                this.src = this.src.replace(/_over./, "_normal.");
            });

        document.body.style.cursor = 'default';
    }
};
/* /rolloverImage */
