// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function include(file, onload) {
    var html_doc = document.getElementsByTagName('head')[0];
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', file);
    html_doc.appendChild(js);

    js.onreadystatechange = function () {
        if (js.readyState == 'complete') {
            onload();
        }
    }

    js.onload = function () {
        onload();
    }
    return false;
}

Event.observe(window, 'load', function() {
  var tags = getElementsByClassName('rich-text', 'textarea', document);
  if (tags.length > 0)
  {
    tinyMCE.init({
      mode: 'specific_textareas',
      editor_selector: 'rich-text',
      theme : "advanced",  
      elements : "content",  
      theme_advanced_toolbar_location : "top",  
      theme_advanced_buttons1 : "bold,italic,underline,separator,list,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,separator,image,link,separator,code",  
      theme_advanced_buttons2 : "",  
      theme_advanced_buttons3 : "",
    });
  }
});
