$(function() {
  
  // Randomise the top margin of slides
  $("#home-slides img").each(function(index) {
    var max_height = 540,
        height = $(this).attr("height"),
        diff = max_height - height,
        margin_top;
    // Find a margin
    if (diff > 200) {
      margin_top = 72;
    } else {
      margin_top = diff > 100 ? 54 : 36;
    }
    // Don't let it be taller than the maximum
    if ((height + margin_top) > 540) {
      margin_top = 18;
    }
    // Set the margin
    $(this).css("margin-top", margin_top);
  });
  
  // Create slideshow
  $("#home-slides").cycle({
    fx: "fade",
    speed: 2000
  });
  
});
