function init_tabs() {
  if (!$('ul.tabs').length) {
    return;
  }
  $('div.tab_content_wrap').each(function() {
    $(this).find('div.tab_content:first').show();
  });

  // Functionaliteit wanneer op een tab wordt geklikt
  $('ul.tabs a').click(function() {
    // Is het de huidige tab?
    if (!$(this).hasClass('current')) {
      $(this).addClass('current').parent('li').siblings('li').find('a.current').removeClass('current');
      $($(this).attr('href')).show().siblings('div.tab_content').hide();
      this.blur();
      return false;
    }
  });
}

$(document).ready(function() {
  init_tabs();

  $('#update').change(function() {
    $.ajax({
      type: 'GET',
      url: 'ajax_artistphoto.php?id=' + $(this).val(),
      datatype: 'text',
      success: function(output, textStatus) {
        $('#picture').attr('src', 'images/artiesten/' + output);
        $('#picture').attr('height', 150);
      },
      error: function(xhr, textStatus, errorThrown) {
        alert(errorThrown ? errorThrown : xhr.status);
      }
    });
  });

  $('#frmDemotePromote').validate({
    messages: {
      txtArtist: {
        required: "Vereist veld"
      },
      txtTitle: {
        required: "Vereist veld",
      },
      txtSender: {
        required: "Vereist veld"
      },
      txtArguments: {
        required: "Vereist veld"
      },
      txtCheck: {
        required: "Vereist veld"
      }
    }
  });

  $('#frmDemotePromote').live('submit', function(){
    var numSelected = $(this).find('#update option:selected').length;
    if (numSelected == 0) {
      alert('Er is geen titel geselecteerd!');
      return false;
    }
    var x = $(this).find(':hidden[id="x"]').val();
    var check = $(this).find(':text[id="check"]').val();
    if (check != x) {
      alert('Code is onjuist overgenomen');
      return false;
    }
    theText = $(this).find('textarea#arguments').val();
    if (theText.toLowerCase().indexOf("href") > 0) {
      return false;
    }
    return true;
  });

});
