function addPictureInput() {
	$('.pictureInput').change(function(){
	  $(this).parents("fieldset").append('<p><input type="file" name="pictures[]" class="pictureInput" /></p>').change(addPictureInput);
	})
}

function hijackDeleteBookmarkLinks() {
    $('a.delete').bind('click', function() {
        var deleteLink = $(this);
        if(!confirm("Are you sure you want to continue")) return false;
        $.ajax({
            type: 'DELETE',
            url: deleteLink.attr('href'),
            success: function(){deleteLink.parents(".employee, .vehicle_row").remove()}
        })
        return false
    })
}

function addNewItem() {
	$('a.addLink').bind('click',function() {
		var hidden = '.'+$(this).attr('name');
		if ($(hidden).is(':hidden')){
			$(hidden).show();
		} else {
			$(hidden).hide();
		}
	})
	$('.addMake').hide();
	$('.addColor').hide();
	$('.addOption').hide();
	$('a.addNew').bind('click', function() {
      var addNew = $(this);
			var type = addNew.prev();
      if(!confirm("Are you sure you want create "+ type.attr('value'))) return false;
      $.ajax({
          type: 'POST',
          url: addNew.attr('href')+'.js',
					data: type.attr('name')+"="+type.attr('value'),
          success: function(response){eval("" + response + "");}
      })
      return false
  })
}


function adminDeletePicture() {
    $('.admin img.pictureDelete').bind('click', function() {
        var deletePicture = $(this);
        if(!confirm("Are you sure you want to delete this")) return false;
        $.ajax({
            type: 'DELETE',
            url: deletePicture.attr('name'),
            success: function(){deletePicture.remove()}
        })
        return false
    })
}

function displayError(request, errorType) {
    var msg = '<div class="error">'+request.responseText+'(click to close)</div>'
    $('#bookmarks-list').append(msg)
    $('.error').click(function(){$(this).hide()})
}
