function clearDefault(elem){ if( elem.value==elem.defaultValue )
elem.value = ''}

function restoreDefault(elem){ if( elem.value=='' ) elem.value =
elem.defaultValue}

$(document).ready(function() {

	$('#slider > ul').cycle({ 
	    fx:    'fade',
	    pause:  1,
	    width: '1000px',
	    fit: 1,
	    after: onafter
	});
	
	
	function onafter(curr, next, opts, fwd) {
	  // on the first pass, removeSlide is undefined (plugin hasn't yet created the fn yet)
	  if (!opts.removeSlide) {return;}
	 	
	  if ($('#slider > ul li:eq(0)').hasClass('intro')) {
	  	// Remove the first slide
	  	opts.removeSlide();
	  }
	}	
		
	$('#slider > ul').css('width', '100%');
	$('#slider > ul > li').css('width', '100%');
	$('#slider li img').css('width', '100%');
	
	
	$(window).resize(function() {
/*   		$('body').prepend('<div>' + $(window).width() + '</div>'); */
	});
	
	
	$(".person").hover(function(){
	    $(this).children('.info').fadeIn("slow");
	},
	function(){
	    $(this).children('.info').fadeOut();
	});
	
	$('#sliderNav a:eq(0)').addClass('one');
	$('#sliderNav a:eq(1)').addClass('two');
	$('#sliderNav a:eq(2)').addClass('three');
	
	/* Join Us Accordion */
	
	$('.accordion > h3:not(.open)').next().hide();
	
	$('.accordion > h3').click(function(){
		var self = $(this);
		if (self.hasClass('open')) {
			self.removeClass('open');
    		self.next().slideUp();
		} else {
/* 		if (self.next().css("display") == "none") { */
			self.siblings('div').slideUp();
    		self.next().slideDown();
    		self.addClass('open');

/*     	} */
		}
		self.siblings('h3').removeClass('open');
	});
	
	/* Upcoming Events Accordion */
	$('.moreInfo').hide();
	
	
	$('.page #events li').click(function(){
		$(this).children('.moreInfo').slideToggle();
	});
	
	/* Homepage Events Accordion */
	
	$('.home #events li').click(function(){
		var eventTitle = $(this).children('.title').text();
		var eventInfo = $(this).children('.moreInfo').html();
		$(this).parent().siblings('#eventBox').children('h4').text(eventTitle);
		$(this).parent().siblings('#eventBox').children('p').html(eventInfo);
		$(this).parent().siblings('#eventBox').fadeIn('fast');
	});
	
	$('#eventBox').click(function(){
		$(this).fadeOut('fast');
	});
	
	/* Image Resizing */
	
	$('.program a img').mouseenter(function(){
		$(this).animate({width: '200px', height: '200px', left: 0, top: 0}, 100);
	});
	$('.program a img').mouseleave(function(){
		$(this).animate({width: '190px', height: '190px', left: 5, top: 5}, 100);
	});
	
	$('.staff a img').mouseenter(function(){
		$(this).animate({width: '326px', height: '326px', left: 0, top: 0}, 100);
	});
	$('.staff a img').mouseleave(function(){
		$(this).animate({width: '314px', height: '314px', left: 6, top: 6}, 100);
	});
	
	
	/* Sitemap */
	$('#sitemapBtn').click(function() {
	  $('#sitemap').slideToggle('fast', function() {
	    	$("body,html,document").animate({ scrollTop: $(document).height() }, "fast");
  			return false;

	  });
	});
		
	
	/* Staff Nav */
	
	var staffNumber = $('.staff-link').size();
	var staffNavWidth = staffNumber * 180;
	var hiddenArea = staffNavWidth - 900;
	$('.nav-inner').css("width", staffNavWidth +'px');
	
	var speedPerItem = 800;
	var startScrollSpeed = speedPerItem *(staffNumber - 5);
	
	$('#nextArrow').mouseenter(function(){
		var offset = parseInt($('.nav-inner').css("left"));
		var offsetWhole = Math.floor(offset);
		var scrollSpeed = (( offsetWhole + hiddenArea )/hiddenArea)*startScrollSpeed;
		$('.nav-inner').animate({left: '-'+ hiddenArea}, scrollSpeed);
	});
	$('#nextArrow').mouseleave(function(){
		$('.nav-inner').stop();
	});
	
	$('#backArrow').mouseenter(function(){
		var offset = parseInt($('.nav-inner').css("left"));
		var offsetWhole = Math.floor(offset);
		var scrollSpeed = ((-offsetWhole)/hiddenArea)*startScrollSpeed;
		$('.nav-inner').animate({left: 0}, scrollSpeed);
	});
	$('#backArrow').mouseleave(function(){
		$('.nav-inner').stop();
	});
	
	/* Mission Video */
	$('#missionVideo a').mouseenter(function(){
		$('#missionVideo').stop().animate({height:'121px'}, 500);
	});
	$('#missionVideo a').mouseleave(function(){
		$('#missionVideo').stop().animate({height:'44px'}, 500);
	});
	
	
});


