EventCalendar = new Class({
	initialize: function(){
		this.months=['January','February','March','April','May','June','July','August','September','October','November','December'];
		this.cookie = Cookie.get('event_date');
		if(this.cookie)
		{
			var tmp=this.cookie.split('/');
			this.event_day=tmp[0];
			this.event_month=tmp[1];
			this.event_year=tmp[2];
		}
		else
		{
			var date=new Date();
			this.event_day=date.getDate();
			this.event_month=date.getMonth()+1;
			this.event_year=date.getFullYear();
		}
		this.div=$('calendar_html');
		this.date_display=$('event_date');
		this.month_display=$('event_month');
		this.year_display=$('event_year');
		this.drawCalendar();
		$('prev_month').onclick = function(){this.prevMonth()}.bind(this);
		$('next_month').onclick = function(){this.nextMonth()}.bind(this);
		$('prev_year').onclick = function(){this.prevYear()}.bind(this);
		$('next_year').onclick = function(){this.nextYear()}.bind(this);
		//window.addEvent('unload',function (){this.saveStyleSheet()}.bind(this));
	},
	drawCalendar: function(){
		var argString='day='+this.event_day+'&month='+this.event_month+'&year='+this.event_year;
		var myAjax=new Ajax('/events/index.php?task=ajax_calendar',{method:'post',data:argString,update:this.div,onComplete:function(){this.completeCalendar()}.bind(this)});
		myAjax.request();
		// set the current month, date and year
		this.date_display.innerHTML=this.event_day+'/'+this.event_month+'/'+this.event_year;
		this.month_display.innerHTML=this.months[this.event_month-1];
		this.year_display.innerHTML=this.event_year;
	},
	completeCalendar: function (){
		var myTips = new Tips($$('.eventTip'), {
		maxTitleChars: 50,offsets:{x:10,y:10}   //I like my captions a little long
		});
	},
	prevMonth:function(){
		if(this.event_month==1)
		{
			this.event_month=12;
			this.event_year--;
		}
		else
		{
			this.event_month--;
		}
		this.drawCalendar();
		this.saveEventDate();
	},
	nextMonth:function(){
		if(this.event_month==12)
		{
			this.event_month=1;
			this.event_year++;
		}
		else
		{
			this.event_month++;
		}
		this.drawCalendar();
		this.saveEventDate();
	},
	prevYear:function(){
		this.event_year--;
		this.drawCalendar();
		this.saveEventDate();
	},
	nextYear:function(){
		this.event_year++;
		this.drawCalendar();
		this.saveEventDate();
	},
	saveEventDate: function (){
		Cookie.set('event_date',this.event_day+'/'+this.event_month+'/'+this.event_year,{path:'/',duration:7});
	}
});
