jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {
		//xhr.setRequestHeader("Accept", "text/javascript")
		xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
	}
})

jQuery(document).ajaxSend(function(event, request, settings) {
  if (typeof(AUTH_TOKEN) == "undefined") return;
	if (settings.type == 'GET') return;
  // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
 
jQuery.fn.submitWithAjax = function() {
  this.live('submit', function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

jQuery.fn.ajaxLink = function() {
	this.click(function() {
		$.ajax({
			url: this.href,
			dataType: "script"
		});
		return false
	});
}
 
jQuery.fn.confirmRequired = function() {
  this.live('click', function (){
    return confirm('Are are you sure');
  });
}

jQuery(document).ready(function($) {
	
	//employement toggle
	
	$('.job_expanded').hide();
	$('a.show_more').click(function() {
		if ( $(this).siblings('.job_expanded').is(":hidden"))
	     {
	      	$(this).siblings('.job_expanded').slideDown("slow");

	  } else {
	        $(this).siblings('.job_expanded').slideUp(800);
	     }
	});

	//trinaing form toggle

	$('#trainingForm').hide();
	$('#training').click(function() {
		if ( $('#trainingForm').is(":hidden"))
	     {
	      	$('#trainingForm').slideDown("slow");

	  } else {
	        $('#trainingForm').slideUp(800);
	     }
	});
	
	// sortable references

	$('#draggableList.references').sortable({items:'.reference', containment:'parent', axis:'y', update: function() {
	  $.post('/references/sort', '_method=put&authenticity_token='+AUTH_TOKEN+'&'+$(this).sortable('serialize'));
	}});

});



