if($.browser.msie) {
  
} else {
  // ajaxify CRUD delete links
  $(function(){
    $('a.crud_delete_link').livequery('click', function(){
      if (!confirm('Weet u het zeker?'))
        return false
      var self = this
      $.ajax({
        // window.location.href should be ok most of the time unless the resource is nested...
        // in that case use the rel attribute 
        url: $(self).attr('rel') != '' ? $(self).attr('rel') : this.href, 
        data: { _method: 'DELETE' },
        type: 'POST',
        success: function() {
          if ($(self).hasClass('hide_li')) {
            $(self).parents('li.element').fadeOut('fast')
          } else if ($(self).hasClass('hide_div')) {
						$(self).parents('div.element_div').fadeOut('fast')
 					} else {
            if ($(self).hasClass('main')) {
              window.location = '/'
            } else {
              if ($(self).hasClass('reload')) {
                location.reload(true)
              } else {
                // trim off record identifer and return to "index" page or refresh page
                // example: /admin/clusters/1 => /admin/clusters
                // example: /account/logo => /account/logo
                var parts = window.location.pathname.match(/^(.*)\/(\d+)$/)
                window.location = (parts == null) ? window.location : parts[1]
              }
            }
          }

        }
      })
      return false
    });

    $('a.crud_update_link').livequery('click', function(){
      // if (!confirm('Weet u het zeker?'))
      //  return false
      var self = this
      $.ajax({
        // window.location.href should be ok most of the time unless the resource is nested...
        // in that case use the rel attribute 
        url: $(self).attr('rel') != '' ? $(self).attr('rel') : this.href, 
        data: { _method: 'PUT' },
        type: 'POST',
        success: function() {
          if ($(self).hasClass('hide_div')) {
						$(self).parents('div.element_div').fadeOut('fast')
 					} else {
            location.reload(true)
          }
				}
      })
      return false
    });

    $('a#show_details').click(function(){
      $('div#user_details').show('fast');
      $(this).parents('div.form_row').hide('fast');
      $('div#user_details').effect('highlight', {}, 1500);
      return false;
    });

    if($.cookie('hide-message') == null) {
      $('#first_message').show('slow').corner("cc:#FFF");

      $('#first_message a.yes').click(function(){
        $('#first_message_more').show('slow');
        $('#first_message > div.nav').hide();
        return false;
      });

      $('#first_message a.delete').click(function(){
        $('#first_message').hide('slow');
        $.cookie('hide-message', true);
        return false;
      });
    }

    $("input:visible:enabled:first").focus();

    $('form').submit(function(){

      $(this).find("button[type='image'], button[type='submit']").click(function(){
        return false;
      }).html("<span>Een moment geduld a.u.b. ... </span>");
    });
  }); 
}