;(function($){
	
	$(document).ready(function() {
		var $slideshow = $('.home #hero #slide-show');

		if ($slideshow.length)
		{
			$slideshow
				.removeClass('clearfix')
				.slides({
					  effect: 'fade'
					, play: 12000
					, hoverPause: true
				});
		}
	});
	
	$('.event-detail .learn-more .tabs li a').live('click', function(e) {
		var   $this = $(this)
			, $allTabButtons = $('.event-detail .learn-more .tabs li a')
			, $allWindows = $('.event-detail .learn-more .tab');
			
		// make sure the click does not jump the window
		e.preventDefault();
		
		if ($this.hasClass('active'))
			// do nothing, we are already showing the content
			return;
		
		$allTabButtons.removeClass('active');
		$this.addClass('active');
		
		$allWindows.addClass('hide');
		$('#' + $this.metadata().id).removeClass('hide');
	});
	
	$('input.invalid, textarea.invalid, select.invalid').livequery(function() {
		var   $this = $(this)
			, $parent = $this.parent();
		
		$parent.addClass('invalid');
	}, function() {
		var   $this = $(this)
			, $parent = $this.parent();
		
		$parent.removeClass('invalid');
	});
	
	$('#body .lesson').livequery(function() {
		var $this = $(this);
		
		$this
			.hover(function(e) {
				$this.addClass('hover');
			}, function(e) {
				$this.removeClass('hover');
			}).click(function(e) {			
				if (e.target.nodeName != 'a')
					window.location = $this.find('a.lesson-link').attr('href');	
			});
	});
	
	$(".module.tips input[type=text]").livequery(function() {
		var   $this = $(this)
			, $label = $this.siblings("label").text();
		
		if (!$this.val().length)
		{
			$this.val($label);
			$this.addClass("blank");
		}
	
	}).live("focus blur", function() {
		var   $this = $(this)
			, $label = $this.siblings("label").text();
		
		if ($this.val() == $label)
		{
			$this.val("");
			$this.removeClass("blank");
		}
		else if (!$this.val().length)
		{
			$this.val($label);
			$this.addClass("blank");
		}
	});
	
	$(".module.tips form").livequery(function() {
		var $this = $(this);
		
		$this.submit(function(e) {
			$(".module.tips input[type=text]").each(function(index, element) {
				var   $element = $(element)
					, $label = $element.siblings("label").text();
				
				if ($element.val() == $label)
					$element.val("");
			});
		});
	});

})(jQuery);
