var EventCalendar = new Class({
	
	Extends: Calendar,
	
	
	initialize:	function(calendar, options)
	{
		this.parent(calendar, options);
		this.getEvents({"startDate":this.dayCollection.getFirst().getTimestamp(), "endDate":this.dayCollection.getLast().getTimestamp()})
	},
	
	setUp: function()
	{
		this.baseUrl = document.controllerUrl;
		
		this.calendarGenerator	= new CalendarGenerator();
		this.calendarGenerator.addEvent("onDayGeneration", this.addElementToCollection.bind(this));
		this.dayCollection		= new DayCollection();
		this.searchBus = new SearchBus();
		this.searchBus.registerCallback(this.addDayClass.bind(this)		, "dayHover");
		this.searchBus.registerCallback(this.removeDayClass.bind(this)	, "dayOut");
		
		this.searchBus.registerCallback(this.addDayClass.bind(this)		, "eventHover");
		this.searchBus.registerCallback(this.removeDayClass.bind(this)	, "eventOut");
		this.searchBus.registerCallback(this.rangeSelection.bind(this)	, "rangeSelection");
		
		this.selections			= new CalendarSelections(this.dayCollection);
		
		this.selections.addEvent("onDaySelectionHover"	, this.onSelectionHover.bind(this))
		this.selections.addEvent("onCreateRange"		, this.onRangeSelected.bind(this))
		this.selections.addEvent("onMouseEnter"			, this.dayCellMouseEnter.bind(this));
		this.selections.addEvent("onMouseLeave"			, this.dayCellMouseLeave.bind(this));
		this.selections.addEvent("onRangeSeted"			, this.onRangeSeted.bind(this));
		this.selections.addEvent("onInitSelection"		, this.onInitSelection.bind(this));
		
		document.addEvent("calendarEsc", this.unselectAll.bind(this));		
	},
	
	requestComplete: function(response, onCompleteFunctions)
	{
		
		this.parent(response, onCompleteFunctions);
		
		if($defined(response.ANSWER) && $defined(response.ANSWER.result) && $defined(response.ANSWER.result.events))
		{
			this.searchBus.trigger("eventsRecived", response.ANSWER.result.events);
		}
		this.dayCollection.removeClass(this.endTimestamp, "loading");
	},
	
	getEvents: function(data)
	{
		var url 	= "public/eventscontroller/getevents";
		var data 	= data;
		this.request(url, data);
	}
	
});