
// If we have problems with repsond_to try this: http://pastie.org/212866
// add Accept:text/javascript header to jQuery ajax requests
//jQuery.ajaxSetup({ 
//  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} 
//})

$(document).ajaxSend(function(event, request, settings) {
  if (typeof(AUTH_TOKEN) == "undefined") return;
  if (settings.type == 'GET') return;
  // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});


$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};


/* document js */

$(document).ready(function() {
    
    // ---- apply facebox ----
    $('a[rel*=facebox]').livequery(function() {
      $(this).facebox();
    });
    
    if(!navigator.cookieEnabled) {
        if($('#login-form').size() > 0) {
            $('#cookie-warning').wait(200).slideDown('slow');
        }
    }
    
    /* Add auto select behavior to text input fields */
    $('input.autoselect').click(function() {
      this.select();
    });
    
    /* Add slideshow behaviour */
    $('.alljo-slideshow#how-it-works').alljoSlideShow();
    
    /* Ajaxify Links */
    
    $('#edit-company-info-form #delete-logo-link').attr('onclick', null).click(function() {
        var link = $(this).attr('href');
        $('#edit-company-logo').find('.loader').addClass('active');
        $('#edit-company-logo').load(link, {'_method':'delete'});
        return false;
    });
    
    
});


