Event.observe(window,"load",function() {
	$$("#event_type").invoke("observe","change",function(ev) {
		new Ajax.Updater("featured_upcoming_events","http://www.idfa.org/_ajax/get-filtered-events.php", { method: "post", parameters: { type: type, category: this.value }, onComplete: function(ev) { refreshHooks(); } });
	});
	$$(".save_to_calendar").invoke("observe","click",function(ev) {
		ev.stop();
		new Ajax.Request("http://www.idfa.org/modules/save-event.php?event=" + this.readAttribute("name"), { evalScripts: true });
	});
});

function refreshHooks() {
	$$(".save_to_calendar").invoke("observe","click",function(ev) {
		ev.stop();
		new Ajax.Request("http://www.idfa.org/modules/save-event.php?event=" + this.readAttribute("name"), { evalScripts: true });
	});

	// Email Links
	$$(".email_link").invoke("observe","click",function(ev) {
		ev.stop();
		if ($("email_window"))
			$("email_window").remove();
		ethis = new Element("span", { style: "position: absolute; padding-left: 5px; margin-top: -37px;" });
		ethis.id = "email_window";
		
		if (this.readAttribute("href") != "#")
			url = this.readAttribute("href");
		else
			url = document.location.href;
		
		ethis.innerHTML = '<div style="float: left; width: 10px;"><img src="http://www.idfa.org/images/email-this-arrow.gif" alt="" style="margin-top: 32px;" /></div><div style="float: left; width: 218px; background: #0076C7; padding: 8px; color: #FFF; font-size: 16px; font-family: Georgia; margin-left: -2px;"><span style="float: left; padding-bottom: 8px; padding-left: 3px;">Email This</span><a style="display: block; width: 21px; margin: -3px 0 0 0; height: 21px; float: right;" onclick="$(\'email_window\').remove();"><img src="http://www.idfa.org/images/close-email.jpg" alt="" /></a><div style="clear: both; width: 202px; background: #FFF; padding: 8px; color: #333; font-size: 12px; font-family: Arial;"><form method="post" onsubmit="emailThisForm(); return false;" id="email_form"><input type="hidden" name="url" value="' + url + '" />Your Name:<br /><input name="your_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Email:<br /><input name="your_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Name:<br /><input name="friend_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Email:<br /><input name="friend_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Message:<br /><textarea name="message" style="background: #F6F6F6; border: 1px solid #83B9E6; width: 194px; height: 64px; margin: 0; padding: 2px; margin-top: 3px;"></textarea><br /><input type="image" src="http://www.idfa.org/images/submit_button.png" alt="Submit" style="width: auto; height: auto; border: 0; margin: 7px 0 0 0; padding: 0; float: right;" /></form><br class="clear" /></div></div>';
		
		this.insert({ after: ethis });
	});
}