$(document).ready(function() {
	
	// search field function
	var search_text = $(".search_bar .search_text").val();

	$(".search_bar .search_text").focus(function() {
		$(".search_bar .search_text").val('');
	})

	$(".search_bar .search_text").blur(function() {
		$(".search_bar .search_text").val(search_text);
	})	

  	// activate homepage slider
  	rotatePics(1);

	// projects page accordian
	$('#projects > div').hide();
	$('#projects > div:first').show();
	
	$('#projects h2').click(function() { 
		$(this).next().animate( { 'height':'toggle' }, 'slow', 'swing' );
	});
});

// homepage image fader
function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#slider ul li').length;
  currentPhoto = currentPhoto % numberOfPhotos;
	
  $('#slider ul li').eq(currentPhoto).fadeOut(function() {
		// re-order the z-index
    $('#slider ul li').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    $(this).show();
    setTimeout(function() {rotatePics(++currentPhoto);}, 4000);
  });
}