﻿var QuickEdit = {
    init: function() {
        $('div.preview-hover span.return a').click(function() {
            var r = $(this).parent().parent().parent().attr('class').match(/preview-hover\s(\d{1,10})/);
            QuickEdit.open(r[1]);
            return false;
        });

        $('div.chover').each(function() {
            if (!$(this).data('qinitted')) {
                $(this).click(function() {
                    if ($('body').hasClass('editing')) {
                        var el = $(this);
                        var r = el.attr('class').match(/chover\s(\d{1,10})/);

                        if (r.length > 0)
                            QuickEdit.open(r[1]);
                        return false;
                    }

                });
                $(this).data('qinitted', true);
            }
        });
    },
    open: function(id) {
        $.fn.colorbox({ width: "705px", height: "80%", iframe: true, open: true, href: "/admin/ContentItem_liveedit.aspx?ContentItem_id=" + id });
    }

};

$(document).ready(function() {
    QuickEdit.init();
    $(document).bind('page', QuickEdit.init);
});

// We hide flash elements as they interfere with the lightbox
$().bind('cbox_open', function() {
    $('.flash').hide();
    $('embed').hide();
});

// Reveal the flash elements again
$().bind('cbox_closed', function() {
    $('.flash').show();
    $('embed').show();
});
