$j = jQuery;

self.MediaSetCommentsManager = {
    sSlug: "",
    iActiveIndex: 0,
    init: function() {
        var oSelf = self.MediaSetCommentsManager;
        // parse url
        var aUrlBits = document.location.pathname.substr(1).split("/");
        // aUrlBits[0] should be "blog"
        // aUrlBits[1] is the person or institution slug or whatever slug
        oSelf.sSlug = aUrlBits[1];

        // disabled due to mockups 
        //$j(".editPost a").click(oSelf.editPost);
        $j(".refuseComment a").click(oSelf.refuseComment);
        $j(".acceptComment a").click(oSelf.acceptComment);
        $j(".markAsSpamComment a").click(oSelf.markAsSpamComment);
        
        // init the commentManagers Url for Ajax Blog Comments
        self.CommentManager.setCommentAddUrl(oSelf.obj_dir() + "comments/add_ajax/");
    },
    
    obj_dir: function() {
      	var obj_dir = document.location.pathname.split(/$&\/(.+)$/im);
    	return obj_dir[0];
    },
    
    rel_root_dir: function() {
      	return document.location.pathname.replace(
            /\/portfolio\/.+/,
            "/portfolio/"
        );
    },
    
    refuseComment: function() {
        var aM = $j(this).parent("li").addClass(
            "in_progress"
        ).attr("id").match(/_(.+)$/);

        var iCommentId = aM[1];
        
        open_popup(
            gettext('Refuse Comment'),
            532, "auto",
            self.MediaSetCommentsManager.rel_root_dir() + "helper/comment/" +  iCommentId + "/refuse/",
            true
        );
        return false;
    },
    
    acceptComment: function() {
        var aM = $j(this).parent("li").addClass(
            "in_progress"
        ).attr("id").match(/_(.+)$/);

        var iCommentId = aM[1];
        
        open_popup(
            gettext('Accept Comment'),
            532, "auto",
            self.MediaSetCommentsManager.rel_root_dir() + "helper/comment/" +  iCommentId + "/accept/",
            true
        );
        return false;
    },
    
    markAsSpamComment: function() {
        var aM = $j(this).parent("li").addClass(
            "in_progress"
        ).attr("id").match(/_(.+)$/);

        var iCommentId = aM[1];
        
        open_popup(
            gettext('Mark as Spam'),
            532, "auto",
            self.MediaSetCommentsManager.rel_root_dir() + "helper/comment/" +  iCommentId + "/mark_as_spam/",
            true
        );
        return false;
    },

    destruct: function() {
        self.MediaSetCommentsManager = null;
    }
};

$j.get(
    settings.media_url + "js/website/comment.js",
    function(sData) {
        eval(sData);
        $j(document).ready(function(){
            self.MediaSetCommentsManager.init();
        });
    }
);

$j(window).unload(function() {
    self.MediaSetCommentsManager.destruct();
});
