Drupal.behaviors.ec_abuse = function(context) {

  /* if we have the confirmation hide the rest */
  $('#abuse-report-confirm-wrapper').each(function() {
    $('#abuse-report-wrapper fieldset div:not(#abuse-report-confirm-wrapper, #abuse-report-confirm), #edit-ec-abuse-submit, #edit-ec-abuse-close').hide();
  });

  $('#edit-ec-abuse-close2, #edit-ec-abuse-close').click(function(event) {
    event.preventDefault();
	$("#ec-abuse-report-form").hide();
  });

  $('.report-abuse:not(.ecra-processed)', context).addClass('ecra-processed').each(function() {$(this).attr("href", "#");} ).click(function(event) {
	
	event.preventDefault(); 

	/* place */
    var offset = $(this).offset();
	$("#abuse-report-wrapper").css("position","absolute").css("top",offset.top+$(this).height()+3).css("left",offset.left);

	/* if we have the confirmation from a previous form submission, hide it */
	$('#abuse-report-confirm-wrapper, #abuse-report-confirm, #edit-ec-abuse-close2').hide();
    $('#abuse-report-wrapper div:not(#abuse-report-confirm-wrapper,#abuse-report-confirm, #edit-ec-abuse-close2), #edit-ec-abuse-submit, #edit-ec-abuse-close').show();

	/* set our values */
    var parts = $(this).attr("id").split("-");
	$('#edit-ec-abuse-content-type').val(parts[1]);
    $('#edit-ec-abuse-content-id').val(parts[2]);
	
	/* reset form */
	$('#edit-ec-abuse-name').val("");
	$('#edit-ec-abuse-mail').val("");
	$('#edit-ec-abuse-abuse-comment').val("");
	$('#edit-ec-abuse-abuse-type option:selected').removeAttr('selected');
	$('#edit-ec-abuse-abuse-type option[value=0]').attr('selected','selected');
	
    $("#ec-abuse-report-form").show();
  });
};

