function check_flash() {
  if ($('flash')) { 
    $('flash').show();
    // new Effect.BlindDown('flash', {duration:.5});
    setTimeout("Effect.SlideUp('flash', {duration:.5})", 3000);
  }
}
Event.observe(window,"load",check_flash);

Object.extend(Ajax.InPlaceEditor.prototype, {
    onLoadedExternalText: function(transport) {
        Element.removeClassName(this.form, this.options.loadingClassName);
        this.editField.disabled = false;
        this.editField.value = transport.responseText;
        Field.scrollFreeActivate(this.editField);
    }
});

Object.extend(Ajax.InPlaceEditor.prototype, {
    getText: function() {
        return this.element.childNodes[0] ? this.element.childNodes[0].nodeValue : '';
    }
});

var loaderhtml = "<div class='loader'></div>";
var loaded=false;
var theform;

function hideFormFields() {
  // alert('running');
  var form = theform;
  form.getInputs().each(function(n) { 
    switch(n.readAttribute('type')) {
      case 'file':
        new Insertion.After(n,loaderhtml);
        n.hide();
        break;
      case 'submit':
        n.disable();
        n.value="Submitting...";
        n.style.fontStyle="Italic";
        break;
    }
  });
}

Event.observe(window,"load",function(n1){
 if(!loaded) {
  Element.getElementsBySelector(document, 'form').each(function(form){
    if (!form.readAttribute("onsubmit")) {
      // form.writeAttribute("onsubmit","return false;");
      Event.observe(form,"submit",function(myevent) {
        theform=form;
        if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
          new Ajax.Request("/ping/close", { asynchronous:false });
        }
        // form.submit();
        if ( BrowserDetect.browser != "Safari") {
          hideFormFields();
        }
      });
    }
  });
  // fix for firefox not showing the loading gif if it wasn't loaded/viewable yet
  var objBody = document.getElementsByTagName("body").item(0);
  new Insertion.After(objBody.immediateDescendants().last(),loaderhtml);
  // new Insertion.After(Element.getElementsBySelector(document, 'body').eachimmediateDescendants().last(),loaderhtml);
  objBody.immediateDescendants().last().hide();
  loaded=true;
}
});

function update_sort_classes(id, count) {
  var index=0;
  $(id).getElementsBySelector('div').each(function(n) {
    if ((index+1) %count == 0) {
      n.addClassName('last');
    } else {
      n.removeClassName('last');
    }
    index++;
  });
  if ($('gallery-list-first')) {
    $('gallery-list-first').src = $(id).getElementsBySelector('div')[0].getElementsBySelector("img")[0].src.gsub(/tiny/,"display");
  }
}