var googleCallbacks = new Array();

var GooglePreview = {

    embedPreview: function(key, wrapperBase) {
        var ids = $J("#google_ids" + key).val();

        // Google's embedded preview does not load correctly if the div is hidden, so we'll try to load
        // the preview in a div offscreen, then attach it to the correct place in the DOM if it succeeds.
        var el = document.createElement("div");
        $J(el).addClass("google_preview");
        $J(el).css({"position": "absolute", "left": "-5000px"});
        var placeholder = $J("body");
        placeholder.append(el);

        var wrapperId = "#" + wrapperBase + key;
        var viewer = new google.books.DefaultViewer(el);
        viewer.load(ids,
            function() {
                // failed, probably because Google doesn't have an embeddable preview, remove everything from the DOM.
                $J(el).remove();
                $J(wrapperId + " .google_header").remove();
                $J(wrapperId + " .google_preview_wrapper").remove();
            },
            function() {
                // success, attach the preview to the proper place and show the Google Preview accordian
                $J(el).remove();
                $J(el).css({"position": "static", "left": null});
                $J("#google_wrapper" + key).append(el);
                $J("#google_header" + key).show("blind", {direction: "vertical"}, 500);
            });
    }

};
var googleCallbacks = new Array();

