/*
 * All JavaScript to be fired when the DOM is ready
 */
$(document).ready(function() {

	/*
	 * Set up menu fade
	 */
	var originalOpacity = 0.25,
		originalDuration = 600;
	$("#menu li:not(.selected) a")
		.unbind()
		.css({
				"opacity":"0.25",
				"color":"white"
			})
		.bind({
				"mouseover":function(){
						$(this)
							.animate({"opacity":"0.95"},originalDuration);
					},
				"mouseout":function(){
						$(this)
							.animate({"opacity":originalOpacity},originalDuration)
							.dequeue()
							.clearQueue();
					}
			});

	/*
	 * Initiate the thumbbox plugin
	 */
	$('.flickr-photos').thumbBox();

	/*
	 * Display modal windows for gallery events
	 */
	$(".show-date")
		.bind("click", function(e){
				e.preventDefault();
				var $overlay = $("<div>")
						.addClass("modal-overlay")
						.bind("click",function(){
								$(".modal-overlay,.modal-window")
									.fadeOut(300, function(){$(this).remove();});
							})
						.appendTo("body")
						.css({
								"opacity":"0"
							})
						.fadeTo(300, ".6"),
					$content = $(this)
						.siblings(".dates")
							.html(),
					$close = $("<a>")
						.addClass("modal-close-btn")
						.attr("href","#")
						.bind("click", function(e){
								e.preventDefault();
								$(".modal-overlay, .modal-window")
									.fadeOut(300, function(){ $(this).remove(); });
							})
						.html("&#215;"),
					$modal = $("<div>")
						.addClass("modal-window")
						.css({
								"top":$(window).scrollTop()+85+"px"
							})
						.html(function(){
								if ( !$content )
								{
									return "<ul><li>No events on this date.</li></ul>";
								}
								else
								{
									return "<ul>"+$content+"</ul>";
								}
							})
						.append($close)
						.appendTo("body");
			});

	/*
	 * Technically valid workaround for target="_blank"
	 */
	$('a[rel="external"]').attr('target', '_blank');

});