// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

jQuery.ajaxSetup({
  'beforeSend': function(xhr) {xhr.setRequestHeader('Accept', 'text/javascript')}
})

jQuery.fn.submitWithAjax = function() {
  $(this).submit(function() {
    $.post($(this).attr('action'), $(this).serialize(), null, 'script');
    return false;
  });
}

jQuery.fn.in_place_edit = function(model, attribute) {
  $(this).click(function(){
    e = $(this);
    
    e.unbind('click');
    e.click(function(){return false;});
    val = e.html();
    e.html('<input type="text" name="item[name]" value="' + val + '">');
    return false;
  });
}

$(document).ready(function() {
  $("#new_room").submitWithAjax();
  $("#new_box").submitWithAjax();
  $("#new_item").submitWithAjax();
 
  $("#cloud a").tagcloud({size: {start:10, end: 18, unit: 'pt'}});
  
  $(".edit_item").in_place_edit('item', 'name');
})
