var SearchBit = new Class(
{
	initialize: function(id,data,type,title)
	{
		this.id = id;
		this.data = data;
		this.type = type;
		this.title = title;
	}
}
);

var SearchBitManager = new Class(
{
	initialize: function(cssSelector, observerFunction)
	{
		this.searchBits = {};
		this.cssSelector = cssSelector;
		this.observerFunction = observerFunction;
	},
	pingObserver: function()
	{
		if (this.observerFunction != null) this.observerFunction();
		this.markSearchBits();
	},
	getHash: function()
	{
		var theHash = {};
		for (key in this.searchBits)
		{
			var bit = this.searchBits[key];
			theHash[bit.id] = {'type':bit.type,'value':bit.data};
		}
		return theHash;
	},
	has: function(id)
	{
		return this.searchBits[id] != null;
	},
	clear: function()
	{
		this.searchBits = {};
		this.pingObserver();
	},
	markSearchBits: function()
	{
		if (this.cssSelector != null)
		{
			$$(this.cssSelector).each(
				function (bit)
				{
					bit.removeClass('toggled');
				}
			);
		}
		for (id in this.searchBits)
		{
			if ($(id))
				$(id).addClass('toggled');
		}
		
	},
	addBits: function(bits)
	{
		var t = this;
		bits.each(function(bit)
		{
			if (bit.data != '')
				t.searchBits[bit.id] = bit;
		});
		this.pingObserver();
	},
	add: function(bit)
	{
		this.searchBits[bit.id] = bit;
		this.pingObserver();
	},
	removeType: function(type)
	{
		var t = this;
		bits.each(function(bit)
		{
			if (bit.type == type)
				delete t.searchBits[bit.id];
		});
		this.pingObserver();
	},
	remove: function(id)
	{
		delete this.searchBits[id];
		
		this.pingObserver();
	}
});