function processSubscribe() {
  $.get('subscribe.php',
		{'emma_member_email': $("[name=emma_member_email]").val()},
		function(data) {
		  $("#subscribe-box").html(data);
	    });
  return false;
}


/* Slideshow - this version looks within a container for items of type <li> */

function slideshow() {
  var active = $('#slideshow li.active');

  if ( active.length == 0 ) active = $('#slideshow li:last');

  var next = active.next().length ? active.next() : $('#slideshow li:first');
  animate(active, next);
}


function slideLeft() {
  window.clearInterval(slideshow.interval);

  var active = $('#slideshow li.active');
  if (active.length == 0)
	active = $('#slideshow li:first');

  var next = active.prev();
  if (!next.length)
	next = $('#slideshow li:last');
	
  animate(active, next);
}

function slideRight() {
  window.clearInterval(slideshow.interval);

  var active = $('#slideshow li.active');
  if (active.length == 0)
	active = $('#slideshow li:first');

  var next = active.next();
  if (!next.length)
	next = $('#slideshow li:first');

  animate(active, next);
}

function animate(active, next) {
  active.addClass('last-active')
  .animate({opacity: 0}, 900, function() {
	active.removeClass('active last-active')
  });

  next.css({opacity: 0.0})
      .addClass('active')
      .animate({opacity: 1.0}, 1000);
}


 /* Slideshow: display the first image in the set.
  * And start the slideshow if there is in fact more than one image.
  * Also set up the left and right arrows to go left and right one image.
  *
  * Subscription box: the first click clears the contents and removes formatting.
  */

$(function() {

  $('#subscribeform input').click( function() {
	$(this).val('');
	$(this).css('font-style', 'normal');
	$(this).unbind('click');
  });

  $('#slideshow li:first').addClass('active');
  if ($('#slideshow li').length > 1) {
	slideshow.interval = window.setInterval( "slideshow()", 5000 );
	$('.arrow-left').click(slideLeft);
	$('.arrow-right').click(slideRight);

	$('.arrow-left').mouseover( function() {
	  $(this).attr('src', 'images-home/arrow-left-active.png');
	  $(this).css('cursor', 'hand');
	});

	$('.arrow-right').mouseover( function() {
	  $(this).attr('src', 'images-home/arrow-right-active.png');
	  $(this).css('cursor', 'hand');
	});

	$('.arrow-left').mouseout( function() {
	  $(this).attr('src', 'images-home/arrow-left-inactive.png');
	  $(this).css('cursor', 'default');
	});

	$('.arrow-right').mouseout( function() {
	  $(this).attr('src', 'images-home/arrow-right-inactive.png');
	  $(this).css('cursor', 'default');
	});
  }
  
});


