
// pre-cache images
var num_header_images = 8;
for(i=0;i<num_header_images;i++) {
  $('<img/>').attr('src', '/wp-content/themes/trhaynes/images/head-'+i.toString()+'.jpg');
}

$(document).ready(function() {
    num = Math.floor(Math.random()*num_header_images);
    bg = "url('/wp-content/themes/trhaynes/images/head-"+num.toString()+".jpg')";
    $("div#picture").css('background-image', bg);
    $("div#picture").css('cursor', 'pointer');
    $("div#picture").hoverIntent(
      function () {
        $(this).animate({height: "200px"}, 300);
      }, 
      function () {
        $(this).animate({height: "12px"}, 300);
      }
    );
    $("div#picture").click( function() {
        num = (num+1) % num_header_images;
        bg = "url('/wp-content/themes/trhaynes/images/head-"+num.toString()+".jpg')";
        $(this).fadeOut("normal", function() {
            $(this).css('background-image', bg);
        });
        $(this).fadeIn("normal");
        $("div#picture").css('cursor', 'pointer');
        // $(this).animate({backgroundImage: bg});
    });
});  