var QuestionPanel = new Class({
	
	Implements : [Options, Events],
	
	options: {
		onAnswer: $empty
	},
	
	container: undefined,
	searchBus: undefined,
	
	questions: {},
	
	initialize: function(container, options)
	{
		this.container = $(container);
		this.setOptions(options);
		this.questions = new Hash(this.questions);
		this.setUp();
	},
	
	setUp: function()
	{
		this.searchBus = new SearchBus();
		this.searchBus.registerCallback(this.questionAnsweredCallback.bind(this), "onQuestionAnswered");
	},
	
	removeQuestions: function()
	{
		this.questions.each(function(question){
			question.destroy();
		}.bind(this))
		
		this.questions = new Hash({});
	},
	
	questionAnsweredCallback: function(params)
	{
		this.questions.erase(params.question.getId());
		params.question.destroy();
	},
	
	onAnswerQuestion: function(answer, question)
	{
		this.searchBus.trigger("onQuestionAnswered", {answer:answer, question:question});
		this.fireEvent("onAnswer", [answer, question]);
	},
	
	addQuestion: function(question)
	{
		if($defined(this.questions[question.getId()]))
		{
			return false;
		}
		
		this.questions[question.getId()] = question;
		question.removeEvents();
		question.addEvent("onAnswer", this.onAnswerQuestion.bind(this))
		question.inject(this.container);
		question.highlight();
	},
	
	loading: function()
	{
		this.container.addClass("loading");
	},
	
	loaded: function()
	{
		this.container.removeClass("loading");
	}
	
});