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

var last_object_id = false;

function show_ajax_region(object_id, content) {
  if (last_object_id) {
    Effect.BlindUp(last_object_id);
    if (last_object_id != object_id) {
      setTimeout(function() { create_ajax_region(object_id, content) }, 1000);
    } else {
      last_object_id = false;
    }
  } else {
    create_ajax_region(object_id, content);
  }
}

function create_ajax_region(object_id, content) {
  if ($(object_id).innerHTML == '' && content != false) {
    Element.update(object_id, content);
    setTimeout(function() { enable_tinymce(object_id); }, 800);
  }
  Effect.BlindDown(object_id, 1000);
  last_object_id = object_id;
}

function enable_tinymce(object_id) {
  textareas = $(object_id).getElementsByTagName('textarea');
  for (x = 0; x < textareas.length; x ++) {
    tinyMCE.execCommand('mceAddControl', false, textareas[x].id);
  }
}
