﻿function ScrollBar(orientation, min, max)
{
    switch(orientation)
    {
        case ScrollBar.VERTICAL:
        case ScrollBar.HORIZONTAL:
            break;
        default:
            throw new Error("ScrollBar.ScrollBar(orientation = " + orientation + ", min = " + min + ", max = " + max + ") - invalid scrollbar type");
    }
    
    if(!isNumber(min) || !isNumber(max))
    {
		raise("Minimum value (" + min + ") or maximum value (" + max + ") not valid");
    }
     
    this.value         	= min;
    this.minValue      	= min;
    this.maxValue      	= max;
    this.orientation	= orientation;
    this.scrollButton	= new Widget();
    
    this.onValueChanged = new EventDelegate();
    this.onRangeChanged = new EventDelegate();
    
    extend(this, Container);
};

ScrollBar.prototype = new Container();

// public Widget getScrollButton();
ScrollBar.prototype.getScrollButton = function()
{
	return this.scrollButton;
}

ScrollBar.prototype.setScrollButtonVisible = function(visible)
{
	if(visible)
	{
		this.add(this.scrollButton);
		this.scrollButton.getDOMContainer().style.zIndex = 1;
	} else
	{
		this.remove(this.scrollButton);
	}
}

// public void setValue(int value);
ScrollBar.prototype.setValue = function(value)
{
    if(value < this.minValue || value > this.maxValue)
    {
        throw new Error("ScrollBar.setValue(value = " + value + ") - value outside of range");
    } else
    {
        this.value = value;
        this.onValueChanged.fireEvent(this, value);
    }
};

// public int getValue();
ScrollBar.prototype.getValue = function()
{
    return this.value;
};

// public int getMinValue();
ScrollBar.prototype.getMinValue = function()
{
    return this.minValue;
};

// public int getMaxValue();
ScrollBar.prototype.getMaxValue = function()
{
    return this.maxValue;
};

// public String getWidgetName();
ScrollBar.prototype.getWidgetName = function()
{
    return "scrollBar";
};

// public int getOrientation();
ScrollBar.prototype.getOrientation = function()
{
    return this.orientation;
};

ScrollBar.prototype.toString = function()
{
	return "Widget/ScrollBar";
}

ScrollBar.HORIZONTAL    = 0x01;
ScrollBar.VERTICAL      = 0x02;
