
var FeatureListItem = Class.create(
{
	element: null,
	
	featureUpdater: null,
	
	_checkedInitially: true, 
	
	initialize: function( element, featureUpdater )
	{
		this.element = $( element );
		this.featureUpdater = featureUpdater;
		
		this.initDOM();
		this.initOther();
		this.initEvents();
	},
	
	initDOM: function()
	{
		this.checkbox = this.element.down( "input" );
	},
	
	initOther: function()
	{
		this._checkedInitially = this.checkbox.checked;
	},
	
	initEvents: function()
	{
		this.checkbox.observe( "mouseup", this.handleCheckboxMouseUp.bind( this ) );
	},
	
	wasModified: function()
	{
		return this.checkbox.checked !== this._checkedInitially;
	},
	
	isChecked: function()
	{
		return this.checkbox.checked;
	},
	
	activate: function()
	{
		this.element.removeClassName( "inactive" );
		return this;
	},
	
	deactivate: function()
	{
		this.element.addClassName( "inactive" );
		return this;
	},
	
	getCheckbox: function()
	{
		return this.checkbox;
	},
	
	isLocked: function()
	{
		return this.checkbox.disabled;
	},
	
	getName: function()
	{
		return this.checkbox.getAttribute( "name" );
	},
	
	getValue: function()
	{
		return $F( this.checkbox );
	},
	
	destroy: function()
	{
		this.featureUpdater.dom.tbody.removeChild( this.element );
	},
	
	getRealId: function()
	{
		var id = this.getName().replace( FeatureListUpdater.FEATURE_MASK, "" );
		//console.log( "REAL ID: " + id );
		id = parseInt( id );
		return id = isNaN( id ) ? null : id;
	},
	
	handleCheckboxMouseUp: function( e )
	{
		Event.stop( e );
		this.element.blur();
		
		if( !this.checkbox.checked )
			this.activate();
		else
			this.deactivate();
	}
});