function BinarySwitch(parentElement)
{
	this.ParentElement = parentElement;
	this.SwitchesElement = this.ParentElement.children[0];
	this.InputElement = this.ParentElement.children[1];

	var switches = this.SwitchesElement.children;
	for (var i = 0; i < switches.length; i++)
	{
		switches[i].__BinarySwitch = this;
		switches[i].addEventListener("change", function(e)
		{
			this.__BinarySwitch.update();
		}, true);
	}

	this.update = function()
	{
		var value = 0;
		var switches = this.SwitchesElement.children;
		for (var i = 0; i < switches.length; i++)
		{
			if (System.ClassList.Contains(switches[i], "uwt-selected"))
			{
				if (this.ParentElement.getAttribute("data-endianness") == "little")
				{
					value += (2 ** (switches.length - i - 1));
				}
				else
				{
					value += (2 ** i);
				}
			}
		}

		this.InputElement.value = value;
	};
}

window.addEventListener("load", function()
{
	var items = document.getElementsByClassName("uwt-binaryswitch");
	for (var i = 0; i < items.length; i++)
	{
		items[i].NativeObject = new BinarySwitch(items[i]);
	}
});