jQuery.noConflict();
//$(function() {
jQuery(document).ready(function($){
    jQuery(document).click(function() {
        jQuery(".sendtoblogg_text").each(function() {
            jQuery(this).hide();
        });
    });
    jQuery(".sendtoblogg_button").each(function(index) {
        // Add image and text
        jQuery(this).append('<img src="/media/systemimages/sendtoblogg.gif" alt="" />');
        jQuery(this).append('<span class="small sendtoblogg_text">Skicka till min blogg</span>');
        jQuery(this).attr("id", "sendtoblogg_button_"+index);
        
        // Add click event listener
        jQuery(this).click(function(event) {
            // Open inner span
            jQuery(this).find(".sendtoblogg_text").each(function() {
                jQuery(this).show();
                jQuery(this).click(function() {
                    // Change image
                    var parent = jQuery(this).parent();
                    var img = parent.find("img:first");
                    img.attr("src", "/media/systemimages/sendtoblogg_spinner.gif");
                    // Change text
                    jQuery(this).text("Skickar...");
                    
                    // Make AJAX call
                    // Data
                    var title = parent.attr("sendtoblogg:title");
                    var data = {
                        title: title
                    };
                    // Send AJAX
                    jQuery.ajax({
                        type: "POST",
                        url: "/blogs/ajax/qp/",
                        data: data,
                        success: function(data, textStatus, XMLHttpRequest) {
                            if (data.success) {
                                // This is great
                            } else {
                                // Something went wrong. Show error msg?
                            }
                        },
                        complete: function(XMLHttpRequest, textStatus) {
                            // Hide whole container
                            setTimeout('jQuery("#'+parent.attr("id")+'").fadeOut();', 1000);
                        }
                    });
                    
                });
            });
            // Stop propagation
            event.stopPropagation();
            return false;
        });
    });
});

