jQuery(document).ready(function($) {


	// scrollable
	$("#dl").scrollable({
		size: 1,
		loop: true,
		vertical: true,
		navi: "#navi",
		speed: 750,
		easing: 'easeInOutExpo',
		interval: 7500,
		onBeforeSeek: function() {
			
			// fade everything down to 0 the first time through
			if (!this.getItemWrap().hasClass("faded") ) {
				this.getVisibleItems().addClass("notme");
				this.getItems().not(".notme").css('opacity', '0');
				this.getItemWrap().addClass("faded");
			}
			
			this.getVisibleItems().fadeTo(750, 0);
			
			
		},
		onSeek: function() { 
		            this.getVisibleItems().fadeTo(1500, 1);
		        }
	});
	
	// prepare each icon with titles
	$("#navi a").each(function(index) {
		$(this).attr('rel', ttip[$(this).attr("href")]);
	});

	// icon title popups
	$("#navi a").hover(function() {
		var tipText = $(this).attr("rel");
		$(this).append("<span class='tip-wrap'><span class='tip'>"+ tipText +"</span></span>");
		var tipWidth = $(this).find(".tip-wrap").width();
		var thisWidth = $(this).width();
		var tipOffset = -(tipWidth - thisWidth) / 2;
		
		
		$(this).find(".tip-wrap").css('left', tipOffset );
			
		
	}, function() {
		$(this).find(".tip-wrap").remove();
	});;


	// clear search field on click
	$("input[type='text']").focus(function() {
		if (!$(this).attr("rel")) {
			$(this).attr("rel", $(this).attr("value"));
		}
		if ($(this).attr("rel") == $(this).attr("value") ) {
			$(this).attr("value", "");
		}
	})
	.blur(function() {
		if ($(this).attr("value") == "") {
			$(this).attr("value", $(this).attr("rel") );
		}
	});
	
	// cycle
	$(".cycle").each(function(index) {
		
		// get the first child's height to ensure that the parent element has its height set and doesn't bung up the layout.
		var childHeight = $(this).children(":first").outerHeight();
		$(this)
			.height(childHeight)
			.cycle();
	});
	
	// set a group of elements to equal height.
	$.fn.equalHeights = function() {
			var currentTallest = 0;
			$(this).each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
			// for ie6, set height since min-height isn't supported
			if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentTallest}); }
			$(this).css({'min-height': currentTallest}); 

		return this;
	};
	
	// equal heights for sidebar columns
	$("#content, #container > .aside").equalHeights();
	

	// prepare calendar for popups
	$("table.calendar tbody tr").each(function(index) {
		// add a class of "right" to Friday & Saturday so tooltips stay onscreen
		$(this).find("td:gt(4)").addClass("right");
	});

	
	// popups
	$("table.calendar .event a").hover(function() {
		var bottomPad = $(this).outerHeight() + 18;
		
		$(this).next(".tooltip").css('bottom', bottomPad).fadeIn(500);
	}, function() {
		$(this).next(".tooltip").fadeOut(100);
	});

	// IE6 doesn't read Unicode chars correctly. Replace em.
	if ($.browser.msie && $.browser.version == 6) {
		$(".nav-next em").text("»");
		$(".nav-previous em").text("«");
		
		// also, pseudo-superfish
//*
		$(".menu ul li").hover(function() {
			$(this).find("ul").show();
		}, function() {
			$(this).find("ul").hide();
		});
//*/		
	}
	
	// menu fadein/out. Only good browsers need apply.

	if (!$.browser.msie || ($.browser.msie && $.browser.version > 7) ) {
		$(".menu ul > li:has(ul)").hover(function() {
			$(this).find("ul").stop().css({display: "block", opacity: 0}).fadeTo(150, 1);
		}, function() {
			$(this).find("ul").stop().fadeOut(400, 0, function(){
				$(this).find("ul").hide();
			});
		});
	}
	
	// more tags display
	$('.moretagslink a').click(function() {
		$('.moretags').slideToggle(200);
		return false;
	});

	
	
	
	
	
	
	
	
	
});