function screenshots(timeout) {
  if (timeout  === undefined)
    timeout = 4000;
  
  $('#screenshot').cycle({
      fx:     'fade',
      speed:   200,
      timeout: timeout,
      next:   '#screenshot',
      pause:   0,
      pager:   '#pager',
      pagerAnchorBuilder: function(idx, slide) {
	  return '<a id="slide-' + idx + '" href="#">' + (idx + 1) + '</a>';
      },
      before:   updateBlurb
  });
}
function updateBlurb(inn, out, options) {
  $('#screenblurb div').addClass('hidden');
  $('#screenblurb div.blurb-' + out.id).removeClass('hidden');
}

$('.pauser').bind('click', function(event) {
    var pauser = $(this);
    if (pauser.hasClass('paused')) {
      $('#screenshot').cycle('resume');
      $('#screenblurb').cycle('resume');
      pauser.removeClass('paused');
    }
    else {
      $('#screenshot').cycle('pause');
      $('#screenblurb').cycle('pause');
      pauser.addClass('paused');
    }
 });

$('#button-bar a')
.bind('mouseover', function(event) {
  $('#button-current').html(this.title);
})
.bind('mouseout', function(event) {
  $('#button-current').html("");
})
;

$('#quick-links a')
.bind('mouseover', function(event) {
  $('#quick-links .current').html(this.title);
})
.bind('mouseout', function(event) {
  $('#quicklinks .current').html("");
})
;
$('#screenblurb')
.bind('mouseover', function(event) {
  var pauser = $('.pauser');
  if (!pauser.hasClass('paused')) {
    $('#screenshot').cycle('pause');
    $('#screenblurb').cycle('pause');
    pauser.addClass('paused').addClass('hover-paused');
  }
})
.bind('mouseout', function(event) {
  var pauser = $('.pauser');
  if (pauser.hasClass('hover-paused')) {
    pauser.removeClass('hover-paused');
    if (pauser.hasClass('paused')) {
      $('#screenshot').cycle('resume');
      $('#screenblurb').cycle('resume');
      pauser.removeClass('paused');
    }
  }
})
;

$('a[rel=external]').attr("target", "_blank");

/* Contact link toggles the form */
$("#contact-link").bind('click', function(event) {
		$("#contact").toggle(400);
		return false;
});

/* Validate the form */
function validate(target) {
	var authorVal = $("#author").val();
	if(authorVal == '') {
		$("#author").addClass('error');
		return false;
	}
	var emailToVal = $("#email").val();
	if(emailToVal == '') {
		$("#email").addClass('error');
		return false;
	}
	return true;
	
}

/* Clicking set email validates and then posts email, on - TODO handle errors - success hit button and display sent message */
$("#sendEmail").bind('click', function(event) {
		if (validate(this))
			$.post("email-us.php",
   				{ author: $("#author").val(), email: $("#email").val(), message: $("#message").val(), website: $("#url").val() },
   					function(data){
   						$("#contact").slideUp("normal", function() {				   
							$("#contact-success").slideDown("normal").delay(1000).slideUp("normal");
						});						
   					}
				 );
		return false;
});
$("#author").bind('focus', function(event) { $(this).removeClass("error"); } );
$("#email").bind('focus', function(event) { $(this).removeClass("error"); } );


