function project_initCallback(carousel) {
    jQuery('.carousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('.carousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function startSlideshow(){
}

function loadProfile($target) {
  $('#bio')
    .hide()
    .html($target.siblings('.bio').html())
    .fadeIn('fast');
  $("ul.people .person.active").removeClass("active");
  $target.addClass('active'); 
}

function updateSlideshowNav(){
  var target = $(this).attr('id');
  $('#shownav a.active').removeClass('active');
  $('#shownav a[href="#'+target+'"]').addClass('active');
}

function slideshowPagerClick(idx, slideElement){
  updateSlideshowNav( $('#slideshow li:eq(' + idx + ')').attr('id') );
}

$(document).ready(function() { 
	/* Homepage Slideshow */
	
	// initialize the slideshow
	$("#homepage #slideshow")
		.cycle({
			fx: 'fade',
			pause: 1,
			timeout: 9000,
			before: updateSlideshowNav
		});
  
  // cycle the slideshow when clicking the slide nav
  $('#homepage #shownav a').click(function(){
    // go to the slide that we clicked
    $('#homepage #slideshow').cycle(
      $(this).index('#shownav a') + 1 // add one to the index because there's one slide that's not in the nav
    );
    return false;
  })
  
  // pause when hovering over the slideshow
  $('#slideshow, #shownav').hover(function(){
    $('#homepage #slideshow').cycle('pause');
  }, function(){
    $('#homepage #slideshow').cycle('resume');
  });		
			
	/* Nav */
	// Add search
	$("#nav_search").addClass('nav_search');
	$("#nav ul:first").append('<li class="searchcontainer"></li>')
	//$("#nav ul:first").append('<li class="searchcontainer">' + $('#searchcontainer').html() + '</li>');
	
	// Get the style right
	$("#nav a").wrapInner('<span></span>');
	
	// Identify the first item in each list
	$("#nav ul").each(
		function() { $(this).find("li:first").addClass("first") });	
	
	// Open the next sub menu below the active menu 
	$("#nav .here > ul, #nav .herelast > ul").addClass("open");
	
	// Open any parent menus and sub menus above the active menu 
	$("#nav .here, #nav .herelast").parents("ul").addClass("open");
	// Highlight the active menu path
	//$("#nav .here, #nav .herelast").parents("li").children("a").addClass("active");
	
	// Open next lowest subnav when hovering
	$("#nav ul.open:last li")
		.hover( 
		  function() { 
		    $(this).addClass("hovering"); 
		    $(this).children("ul:first").show();
		  }, 
		  function() { 
		    $(this).removeClass("hovering"); 
		    $(this).children("ul:first").hide();
		  } 
		);
	
	// Hide all but two levels of nav in the sidebar subnav
	/*
	var numNav = $("#alpha div").length;
	if (numNav > 2) {
    var hideNav = numNav - 2;
    $("#alpha div:lt("+hideNav+")").hide();
	}
	*/
	
	// Save Form Field Prompts 
	// If you have form fields with default values like "Enter search term"
	// this code will save that value, hide it when a user focuses on the field
	// and restores it when they leave the field if they didn't enter anything.
	// Select the fields you want to save
  var $fields = $("form .keywords");
  
  // No need to change anything below here
  $fields.each(function(){
	$(this)
		.data("val",$(this).val()) 	// save the initial value
		.focus(function(){
			$(this).val(''); 		// clear the field on focus
		})
		.blur(function(){
			// reset the field to the original value if the user didn't input anything
			if ($(this).val()=='') {
    			$(this).val($(this).data("val")); 
    		}
		});
  });
  
  $("form .keywords")
  .focus(function(){
      $(this).addClass("focus");  
    })
  .blur(function() {
      $(this).removeClass("focus");
    });
	
	/* Carousels */
	$(".carousel-nav").fadeIn("fast");

/*
	$(".carousel.projects").jcarousel({
		buttonNextHTML: '<div class="carousel-next">More Projects &gt;</div>',
		buttonPrevHTML: '<div class="carousel-prev">&lt; Previous Projects</div>',
		scroll: 3
	});
*/

  $(".scrollable.projects").scrollable({circular: true});

  
/*
	$(".carousel.project").jcarousel({
    initCallback: project_initCallback,
    buttonNextHTML: null,
    buttonPrevHTML: null,
    scroll: 1
	});
*/
	/* Accordians */
	$(".accordion").accordion({  
    header: 'h3', 
    autoHeight: false, 
    collapsible: true,
    alwaysOpen: false,
    active: false
	});
	$(".accordion h3:first, #sections h3:first:not('.selected')").addClass("first");
	$(".accordion .ui-accordion-right").html("+");
	$(".accordion .selected .ui-accordion-right").html("- ");
	$('.accordion').bind('accordionchange', function(event, ui) {
		$(".accordion .ui-accordion-right").html("+");
		$(".accordion .selected .ui-accordion-right").html("- ");
	});	
	
    // add hover effect to accordion header
    $('#sections h3.ui-accordion-header').hover(function(){
      $(this).addClass('hover');
    }, function(){
      $(this).removeClass('hover');
    });
  
  if (window.location.hash) {
    // if there's a hash on the url, open that accordion element
    $(".accordion").activate(window.location.hash);
  }
  
  // $("ul.people li:lt(2)").addClass('firstrow');

  /* Contact Page */
  $("#contactpage .location:last").addClass("last");
  
  $.cookie("repeat", "true", { path: '/' });
  
  /* Style Mailto links */
  $('a[href^=mailto:]').addClass('mailto');
}); 

