if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return - 1;
    };
}

// SETUP NAMESPACE
DIGISYND = {};

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function($) {
    $('.rounded').corners("6px");
    $('a[rel*=facebox]').facebox({
        loadingImage: '/images/facebox/loading.gif',
        closeImage: '/images/facebox/closelabel.gif'
    });
    // Extend Jquery to work with the normal Rails respond_to style responses.
    jQuery.ajaxSetup({
        'beforeSend': function(xhr) {
            xhr.setRequestHeader("Accept", "text/javascript");
        }
    });

    // Automatically insert the authtoken to outgoing requests
    $(document).ajaxSend(function(event, request, settings) {
        if (typeof(AUTH_TOKEN) == "undefined") {
            return false;
        }

        // 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);
        return true;
    });

    jQuery.fn.add_favorite = function(url, params, callback) {
        var options = {
            'authenticity_token': encodeURIComponent(AUTH_TOKEN)
        };
        jQuery.extend(options, params);
        jQuery.fn.make_favorite_request(url, options, callback);
    };

    jQuery.fn.remove_favorite = function(url, params, callback) {
        var options = {
            '_method': 'delete',
            'authenticity_token': encodeURIComponent(AUTH_TOKEN)
        };
        jQuery.extend(options, params);
        jQuery.fn.make_favorite_request(url, options, callback);
    };

    jQuery.fn.make_favorite_request = function(url, options, callback) {
      jQuery.post(url, options, callback, "json");
    };
});
