function show_image_for (image, index)
{
	//detect the prefix and create image urls accordingly
	image_url = (eval(image.split(":")[0] == "default")) ? default_image : photo_for(image)
	$('image-frame').innerHTML = image_url;
}

function default_image ()
{
	image_url = "<img src='images/offenders/default/sample-tn.jpg' />"   
}


function sanitize_self (elem) {
	$(elem).value = $(elem).value.replace(/\s+/g, "_").toLowerCase();
}

function toggle_publish_date () {
	if ($("set-publish-date").checked) {
		Element.show("publish-date");
	}else{
		Element.hide("publish-date");
	};
}

function form_validation () {
	if ($("contact-form")) {
		$("contact-form").onsubmit = function(){
			error_message = "";
			error_message = ($F("contact_name") == "") ? (error_message + "Please enter in your name") : error_message;
			error_message = ($F("contact_email") == "") ? (error_message + "\nPlease enter in your email") : error_message;
			if ($F("contact_name") == "" || $F("contact_email") == "") {
				alert(error_message);
				return false;
			};
		}
	};
}

function load_events () {
  $$(".toggler").each(function(elem) {
    Event.observe(elem.id,'click', function(){
      Element.toggle(id_from_href(elem));
    })
  });

  $$('.hover-toggle').each(function(elem) {
    Event.observe(elem.id, 'mouseover', function(e) {
      console.log(Element.readAttribute(this,"rel"));
      Element.show($(Element.readAttribute(this,"rel")));
    });

    Event.observe(elem.id, 'mouseout', function(e) {
      Element.hide($(Element.readAttribute(this,"rel")));
    });
  });
  
  // all elements that use this function NEED an id!
  $$('.class-toggle').each(function(elem) {
    Event.observe(elem.id,'click', function(){
      elems = elem.readAttribute('rel');
      $$(elems).each(function(e){
        Element.toggle(e);
      })
    })
  });

  $$('.input-toggle').each(function(elem) {
    Event.observe(elem.id,'click', function(){
      $(id_from_href(this)).value = $(elem.id).innerHTML
      new Effect.Highlight(id_from_href(this))
      return false;
    })
  }); 
}

function id_from_href (elem) { 
  return $(elem).href.split("#")[1]; 
}

function enable_collapsible () {
	//enable all the collapsible elements here
	elems = document.getElementsByClassName("hidden");
	elems.each(function(e) {
		e.style.display="none";
	});
	
}

function load_tooltips () {
  $$(".show-tip").each(function(elem) {
    new Tooltip(elem, {
      backgroundColor: "#eee",
      borderColor: "#ccc",
      delay: 0,
      opacity: 100
    });
  });
}

function load_functions () {
  load_events();
	form_validation();
  // load_tooltips(); // can't use this right now...
}

Event.observe(window,"load",load_functions);

// Event.addBehavior({
//  '.hidden': function() { this.style.display="none"; },
//  '#complaint-btn:click': function() {
//    text = (this.innerHTML == "Close Complaint Form") ? "Add Complaint" : "Close Complaint Form"
//    Element.toggle("add-complaint");
//    this.innerHTML = text;
//  }
// })
