//============================================================================
// EXECUTE ON STARTUP
//============================================================================

$(document).ready(function() {
  clearInputs();
  // fixDiscographies();
})

//============================================================================
// EMPTY INPUTS
//============================================================================

function clearInputs() {
  $('input[type="text"]').focus(function() {
    if (this.value != "") this.value = "";
  });
}

//============================================================================
// FIX RELEASES LISTS
//============================================================================

function fixDiscographies() {
  $('ul.releases').each(function() {
    var itemsPerRow = 3;
    var numberOfReleases = $(this).find('li').length;
    var numberOfRows = Math.ceil(numberOfReleases / itemsPerRow);
    
    if (numberOfRows > 1) {
      for (r = 1; r < numberOfRows; r++) {
        var highest = 0;
      
        // Loops through all the items to find the highest
          for (i = 1; i < itemsPerRow; i++) {
            var releaseId = (r * itemsPerRow) - i;
        
            var newHeight = $(this).find('li:eq(' + releaseId + ')').height();
            if (newHeight > highest) highest = newHeight;
          }
      
        // Loops through all the items to set the highest height to all
          for (i = 1; i <= itemsPerRow; i++) {
            var releaseId = (r * itemsPerRow) - i;

            $(this).find('li:eq(' + releaseId + ')').css('height', highest + 'px');
          }
      }
    }
  });
}
