Calendar = {
	init: function() {
		this.calendar = $('calendar');
		this.temp = $('temp');
		this.body = $(document.body);
		this.calendar.linkify(this.click.bindAsEventListener(this));
	},
	initLinks: function() {
		this.calendar.select('.calendar_header a').each(function(el) {
			el.linkify()
		});
	},
	click: function(e) {
		var el = e.findElement('a');
		if (!el) return;
		if (el.down().hasClassName('calendar_marked')) {
			this.link = el;
			this.link.el = this.link.down();
			if (!this.link.el.prototip) {
				new Ajax.Request(this.link.href, {
					onSuccess: this.success.bind(this),
					onFailure: this.failure.bind(this)
				});
			}
			e.stop();
		} else if (el.down().match('img') || el.down().tagName == 'shape' /*IE bug*/) {
			new Ajax.Updater(this.calendar, el.href);
			e.stop();
		}
	},
	success: function(response) {
		new Tip(this.link.el, response.responseText, PrototipOptions);
		this.link.el.prototip.show();
	},
	failure: function(response) {
//		location.href = response.request.url;
		// wrong - shows blank page
	}
};

Event.observe(window, 'load', Calendar.init.bind(Calendar));
