function SimpleScrollbar() {
    this.verticalScrollbar;
    this.verticalSlider;
    this._height = 0;
    this._width = 0;
    this._sliderCover = 0;//fraction of scrollbar's height
    this.dragOffsetY;
    this.createBody();
    this.createListeners();
}

SimpleScrollbar.prototype.sliderCover = function (newValue) {
    if (newValue) {
        this._sliderCover = newValue;
    } else
        return this._sliderCover;
};

SimpleScrollbar.prototype.createListeners = function () {
    var object = this;
    this.verticalSlider.mousedown(this.startDragHandler=function (event) {object.startDrag(event); });
};

SimpleScrollbar.prototype.startDragHandler;
SimpleScrollbar.prototype.startDrag = function (event) {
    var object = this;
    this.verticalSlider.unbind('mousedown', this.startDragHandler);
    this.dragOffsetY = event.pageY - this.verticalSlider.offset().top;
    $(window).mousemove(this.dragHandler = function (event) { object.drag(event); });
    $(window).mouseup(this.dragStopHandler = function (event) { object.stopDrag(event) ;});
};

SimpleScrollbar.prototype.dragHandler;
SimpleScrollbar.prototype.drag = function (event) {
    var topDistance = event.pageY - this.verticalScrollbar.position().top - this.dragOffsetY;
    if (topDistance < 0) {
        topDistance = 0;
    } else if (topDistance > this._height * (1 - this._sliderCover)) {
        topDistance = this._height * (1 - this._sliderCover);
    }

    this.verticalScrollbar.trigger({ type: 'sliderDrag', fraction: this.fraction() });
    this.verticalSlider.css('top', topDistance + 'px');
};

SimpleScrollbar.prototype.stopDragHandler;
SimpleScrollbar.prototype.stopDrag = function (event) {
    var object = this;
    this.verticalSlider.mousedown(this.startDragHandler = function (event) { object.startDrag(event); });
    $(window).unbind('mouseup', this.stopDragHandler);
    $(window).unbind('mousemove', this.dragHandler);
};

SimpleScrollbar.prototype.createBody = function () {
    this.verticalScrollbar = $('<div style="display:inline-block"></div>');
    var scrollBkg=$('<div class="simpleScrollbar" style="width:20%; height:100%; margin-left:40%"></div>');
    this.verticalScrollbar.append(scrollBkg);
    this.verticalSlider = $('<div style="cursor:pointer; position:relative; margin-left:-200%"><div class="simpleScrollbarSlider" style="height:100%; width:20%; margin-left:40%"></div></div>');
    scrollBkg.append(this.verticalSlider);
};

SimpleScrollbar.prototype.fraction = function () {
    return (this.verticalSlider.offset().top - this.verticalScrollbar.offset().top)
        / (this._height * (1 - this._sliderCover));
};

SimpleScrollbar.prototype.getBodyReference = function () {
    return this.verticalScrollbar;
};

SimpleScrollbar.prototype.height = function (newValue) {
    if (newValue) {
        this._height = newValue;
    } else {
        return this._height;
    }
};

SimpleScrollbar.prototype.width = function (newValue) {
    if (newValue)
        this._width = newValue;
    else
        return this._width;
};

SimpleScrollbar.prototype.refreshBody = function () {
    this.verticalScrollbar.width(this._width)
                            .height(this._height);
    this.verticalSlider.width(this._width)
                        .height(this._height * this._sliderCover)
                        .offset({ top: this.fraction() });
};

SimpleScrollbar.prototype.unload = function () {
    $(window).unbind('mousemove',this.dragHandler);
    $(window).unbind('mouseup', this.dragStopHandler);
    this.verticalSlider.unbind('mousedown', this.startDragHandler);
    this.verticalScrollbar.remove();
    
};
