// KJSLib SelectionItem
if (typeof __KJSLib_SelectionItem == "undefined")
{
var __KJSLib_SelectionItem = true;
//--- start of include guard

var kSelectionItemPrototype = {
	bind : function(derived, onSelectActionObject, onSelectActionMethod)
	{
		kBindable.bind.call(this, derived);

		derived.__private = {
			flags : 0,
			onSelectActionObject : onSelectActionObject,
			onSelectActionMethod : onSelectActionMethod
		}
		derived.style.cursor = "pointer";
	},
	unbind : kBindable.unbind,
	// flag constants
	HIGHLIGHTED : 0x01,
	FOCUSED : 0x02,
	DISABLED : 0x04,

	prototype : {
		disable : function()
		{
			this.disabled = true;
		},
		enable : function()
		{
			this.disabled = false;
		},

		render : function()
		{
			this.innerHTML = "missing";
		},
		showHighlight : function()
		{
		},
		hideHighlight : function()
		{
		},
		showFocus : function()
		{
		},
		hideFocus : function()
		{
		},
		showDisabled : function()
		{
		},
		hideDisabled : function()
		{
		},

		isHighlighted : function()
		{
			return (this.__private.flags & kSelectableItemPrototype.HIGHLIGHTED) != 0;
		},

		//--- Event handlers
		onmouseover : function(evt)
		{
			if (!(this.__private.flags & kSelectionItemPrototype.HIGHLIGHTED))
			{
				this.__private.flags |= kSelectionItemPrototype.HIGHLIGHTED;
				this.showHighlight();
			}
		},
		onmouseout : function(evt)
		{
			if (this.__private.flags & kSelectionItemPrototype.HIGHLIGHTED)
			{
				this.__private.flags &= ~(kSelectionItemPrototype.HIGHLIGHTED);
				this.hideHighlight();
			}
		},
		onclick : function(evt)
		{
			if (typeof this.__private.onSelectActionObject == "object" && typeof this.__private.onSelectActionMethod == "function")
			{
				this.__private.onSelectActionMethod.call(this.__private.onSelectActionObject, this);
			}
		}
	}
}


var kCommandItemPrototype = {
	bind : function(derived, action)
	{
		derived.__private = {
			action : action,
			doAction : function(selectionItem)
			{
				if (this.action && this.action.trim().length > 0)
				{
					eval(this.action);
				}
			}
		}

		kSelectionItemPrototype.bind(derived, derived.__private, derived.__private.doAction);
		//kBindable.bind.call(this, derived);
	},
	unbind : kBindable.unbind
}


var kSelectableItemPrototype = {
	bind : function(derived, onSelectActionObject, onSelectActionMethod)
	{
		kSelectionItemPrototype.bind(derived, onSelectActionObject, onSelectActionMethod)
		kBindable.bind.call(this, derived);

		derived.__private.selected = false;
	},
	unbind : kBindable.unbind,
	// flag constants
	SELECTED : 0x08,

	prototype : {
		showSelected : function()
		{
		},
		hideSelected : function()
		{
		},

		isSelected : function()
		{
			return (this.__private.flags & kSelectableItemPrototype.SELECTED) != 0;
		},
		select : function()
		{
			if (!this.isSelected())
			{
				if (this.__private.owner && this.__private.owner.onitemselect)
				{
					this.__private.owner.onitemselect(this);
				}
				this.__private.flags |= kSelectableItemPrototype.SELECTED;
				this.showSelected();
			}
		},
		unselect : function()
		{
			if (this.isSelected())
			{
				this.__private.flags &= ~(kSelectableItemPrototype.SELECTED);
				this.hideSelected();
			}
		}

		//--- Event handlers
	}
}


var kToggleItemPrototype = {
	bind : function(derived, onSelectActionObject, onSelectActionMethod)
	{
		kSelectableItemPrototype.bind(derived, onSelectActionObject, onSelectActionMethod);
		kBindable.bind.call(this, derived);
	},
	unbind : kBindable.unbind,

	prototype : {
		//--- Event handlers
		onclick : function(evt)
		{
			if (!this.isSelected())
			{
				this.select();
				kSelectionItemPrototype.prototype.onclick.call(this, evt);
			}
			else
			{
				this.unselect();
			}
		}
	}
}


var kExclusiveSelectItemPrototype = {
	bind : function(derived, onSelectActionObject, onSelectActionMethod)
	{
		kSelectableItemPrototype.bind(derived, onSelectActionObject, onSelectActionMethod);
		kBindable.bind.call(this, derived);
	},
	unbind : kBindable.unbind,

	prototype : {
		//--- Event handlers
		onclick : function(evt)
		{
			if (!this.isSelected())
			{
				this.select();
				kSelectionItemPrototype.prototype.onclick.call(this, evt);
			}
		},
		onotheritemselect : function(selectedItem)
		{
			this.unselect();
		}
	}
}

//--- end of include guard
}
