!window.jQuery && document.write('<script src="/jquery-1.4.2.min.js"><\/script>');

jQuery(document).ready(function($){
	var $hover, timeout, $section, headerWidth = $('#header').width();
	
	$.colorbox.settings.next = 'Next';
	$.colorbox.settings.previous = 'Previous';
	$.colorbox.settings.current = '';
	$.colorbox.settings.close = 'Close';
	$.colorbox.settings.opacity = 0.5;
	
	if($.fn.cycle){
		$('#splash').cycle({fx: 'fade'});	
	}
	
	function clear(){
		if($hover){ $hover.remove(); }
		if($section && $section.attr('href')){ $section.removeClass('current'); }
	}
	$('#nav h3 a').hover(function(){
		var left, top, $list;
		
		clearTimeout(timeout);
		clear();		
		$list = $(this).closest('div').find('ul').clone();
		
		if($list.html()){
			$section = $(this).addClass('current');
			
//			$list.find('li:first').hide();
			
			$hover = $("<div></div>")
			.append($list)
			.attr({id :'hovNav'})
			
			$hover.appendTo('#header')
			.hover(function(){
				$section.addClass('current');
				clearTimeout(timeout);
			}, function(){
				timeout = setTimeout(clear, 500);
			})
			.css({
				left :$(this).position().left + 247 + $hover.outerWidth() > headerWidth ? headerWidth - $hover.outerWidth() : $(this).position().left + 247,
				top :138,
				visibility :'visible'});
		}
	}, function(){
		timeout = setTimeout(clear, 500);
	});
	
	$('#email_form').submit(function(e){
		if(!$('#email_message').val()){
			$.colorbox({html:'<h3>A message is required.</h3>', transition:'none', opacity:0.5})
			e.preventDefault();
		}
	});
	
	var volunteer = {'input[name=volunteer_name]':'Your Name', 'input[name=volunteer_email]' :'Email Address', 'input[name=volunteer_phone]' :'Phone'};
	
	$('#volunteer_form').submit(function(e){
		var selector = 'input[name=volunteer_email]', address = $(selector).val()
		if(!address || address == volunteer[selector]){
			$.colorbox({html:'<h3>Please fill in your email address.</h3>', transition:'none', opacity:0.5})
			e.preventDefault();
		}
	});
	
	for (var selector in volunteer){
		(function(selector){
			$(selector)
			.val(volunteer[selector])
			.focus(function(){
				if($(this).val() == volunteer[selector]){
					$(this).val('');
				}
			})
			.blur(function(){
				if($(this).val() == ''){
					$(this).val(volunteer[selector]);
				}	
			});
		}(selector));
	}

	$('.gallery a').colorbox();
	$('.gallery1 a').colorbox();
	$('.award').colorbox();
	$(".video").colorbox({iframe:true, width:"75%", height:"80%"});
	$('.enrollment a').colorbox({width:"550px", inline:true, href:"#inline_example1"});
	$('.enrollment2 a').colorbox({width:"550px", inline:true, href:"#inline_example2"});
	$('.email_list').colorbox({width:"550px", inline:true, href:"#email_list1"});	
});

