/**
 * HTHIEME
 */

function load(url)
{
  var d = new Date();
  if ( url.indexOf('?') > 0 ) {
    url = url + "&time=" +d.getTime();
  } else {
    url = url + "?time=" +d.getTime();
  }
  new Effect.toggle($('content'), 'blind', {
    afterFinish: function() {
      new Ajax.Request(url, {
        method: 'get',
        evalScripts: true,
        onCreate: function(xml, json) {
          new Effect.Appear($('carregando'), {
            duration: 0.5,
            beforeStart: function() {
              $('carregando').setStyle({
                position: 'absolute',
                top: '158px',
                left: '220px',
                zIndex: 30
              });
            }
          });
        },
        onSuccess: function(xml, json) {
          $('content').update(xml.responseText).hide();
          new Effect.toggle($('content'), 'blind', {
            beforeStart: function() {
              new Effect.Fade($('carregando'), {
                duration: 0.5
              });
            },
            afterFinish: function() {
              myLightbox.updateImageList();
            }
          });
        },
        onFailure: function(xml, json) {
          $('content').update('<h2>Erro</h2><br /><div class="msg error double">Ocorreu um erro durante sua requisição. '
            + 'Por favor, tente novamente. Caso o erro persista, entre em contato conosco.</div><br class="clear" />').hide();
          new Effect.toggle($('content'), 'blind', {
            beforeStart: function() {
              new Effect.Fade($('carregando'), {
                duration: 0.5
              });
            }
          });
        }
      });
    }
  });
}


function submitLink(form, url){
  formSerialize = $(form).serialize();
  load(url+'?'+formSerialize);
}

function submitForm(form, url){
  submitLink(form+'/',url)
}

function setHrefDirection(element){
  $$('#'+element+' a').each(function (item) {
      item.onclick = function() {
      load(this.href);
      return false;
    }
  });
}

//Ajax.Responders.register({
//  onCreate: function() {
//    $('content').update('<div style="text-align: center;"><img src="/assets/img/loading.gif" title="Carregando" /></div>').hide();
//    new Effect.toggle($('content'), 'blind');
//  }
//});
