var ContactBook = new Class({
	contacts: [],
	filtered: [],
	initialize: function(container) {
		this.container = container;
	},
	addContact: function(id, contactdata) {
		contactdata.id = document.id(id);
		this.contacts.push(contactdata);
	},
	filter: function(selection, property) {
		if(!property) return this.contacts;

		this.filtered = this.contacts.filter(function(item, index){
    			return item[property].toLowerCase().contains(selection.toLowerCase());
		}).sort(function(contact1, contact2) {
			contact1 = contact1[property].toLowerCase(); 
			contact2 = contact2[property].toLowerCase();
			if (contact1 < contact2) return -1;
			if (contact1 > contact2) return 1;
			return 0;
		});
		return this.filtered;
	},
	show: function() {
		var app = this;
		document.id(this.container).getChildren().setStyle('display', 'none');
		this.filtered.each(function(item, key) {
			item.id.setStyle('display', 'block');
		});
		return this.filtered;
	}
});
