jQuery.ajaxSetup({
    'beforeSend': function(xhr) {
        xhr.setRequestHeader("Accept", "text/javascript")
    }
});

$(document).ready(function() {
    if ($("table.tablesorter").length > 0) {
//        $("table.tablesorter").tablesorter();

//        $("div.pagination a").livequery("click", function() {
//            $.get(this.href, {},
//                function (data) {
//                    $(".tablesorter").html(data);
//                    $(".tablesorter").tablesorter();
//                }
//                );
//            return false;
//        });
    }
    if ($(".remove").length > 0) {
        $('.remove').livequery('click',function() {
            var target = '.' + $(this).attr('href').replace(/.*#/,'');
            $(this).closest(target).remove();
            if(hidden_input = $(this).closest("input[type=hidden]")) hidden_input.value = '1';
        });

        $('.remove_photo').livequery('click', function() {
           $(this).parent().remove();
        });
    }
  // hide our container div
  if ($("#flash-notice").length > 0) {
    $("#flash-notice").hide();
    // grab flash message from our div
    var flash_message = $("#flash-notice").html();
    // call our flash display function
    if(flash_message != ""){
      notify(flash_message);
    }
  }

});

function notify(flash_message) {
  // jQuery: reference div, load in message, and fade in
  var flash_div = jQuery("#flash-notice");
  flash_div.html(flash_message);
  flash_div.fadeIn(400);
  // use Javascript timeout function to delay calling
  // our jQuery fadeOut, and hide
  setTimeout(
    function(){
      flash_div.fadeOut(
      600,
      function(){
          flash_div.html("");
          flash_div.hide();
      })
    },
    1400);

}


function remove_field(element, item) {
    $(element).parent(item).remove();
    //element.up(item).remove();
}

var replace_ids = function(s){
    var new_id = new Date().getTime();
    return s.replace(/NEW_RECORD/g, new_id);
}