var editorial = {

    currentPanelIndex:0,

    chooseContent : function(anchor, index, currentTopicItemId) {

        var popupPanel = $('#choose-content');
        popupPanel.hide();

        editorial.currentPanelIndex = index;

        var pos = $(anchor).offset();
        var height = $(anchor).height();
        var width = $(anchor).width();
        var popupPanelWidth = popupPanel.width();

        $("input[value='"+currentTopicItemId+"']", popupPanel).attr("checked", "checked");


        popupPanel.css({
            display: "block",
            left: (pos.left - (popupPanelWidth - width)) + "px",
            top: (pos.top+ height) + "px"
        });
        $(".okBtn", popupPanel).click(editorial.onSelectTopic);
        $(".cancelBtn", popupPanel).click(function() {
            $('#choose-content').hide();
        });
        popupPanel.show();
        return false;
    },


    onSelectTopic : function() {
        var popupPanel = $('#choose-content');

        var topics = $.cookie('edfront');
        var ids = topics.split(",");
        var newValue = $('input[name=topic]:checked', popupPanel).val();
        ids[editorial.currentPanelIndex] = newValue;
        $.cookie('edfront', ids.join(","), { expires: 60 * 24 * 365, path: '/'});
        popupPanel.hide();
        window.location.reload();
    }
}