Bw.Widgets.Checkbox = 
{
	superclassName: "Bw.Widgets.Editable",
	selfclassName: "Bw.Widgets.Checkbox",
			
	create: function (val)
	{
		var obj = document.createElement ('div');
		obj.setAttribute ("value", val);
		
		Bw.Core.bootstrap (obj, Bw.Widgets.Checkbox);
		
		return obj;
	},
	
	initialize: function ()
	{
		Bw.Widgets.Widget.initialize.call (this);
		
		this.draw();
		
		this.setValue (this.getAttribute ("value"));
		
		this.onupdate = this.getAttribute ("onupdate");
		this.onfocus = this.getAttribute ("onfocus");
		
		var self = this;
		this.button.onclick = function () { self.toggle(); };
		this.button.onfocus = function () { self.focused(); };
	},
	
	draw: function ()
	{
		this.style.display = 'inline';
		
		var b = document.createElement ("button");
		var c = Bw.Widgets.BooleanLabel.create();
		b.appendChild (c);
		this.appendChild (b);
		
		this.checkMark = c;
		this.button = b;
	},
	
	focused: function ()
	{
		Bw.Util.call (this, this.onfocus);
	},
		
	toggle: function ()
	{
		this.setValue (!this.getValue());
		Bw.Util.call (this, this.onupdate);
	},
	
	setValue: function (val)
	{
		this.checkMark.setValue (val);
	},

	getValue: function ()
	{
		return this.checkMark.getValue();
	}
};

