var uc = {type: null, // distinguish a comment from a preview
    is_fb_logged: false,
    aev_id: null,
    top_preview: 0,
    status: "",
    login: function(type){
        uc.type = type;
        if(!uc.is_fb_logged){
            $('#uc_box').slideToggle()
        }else{
            if(uc.status != ""){
                $("#post_uc_box").slideUp();
                uc.status = "";
                return;
            }
            uc.status = uc.type;
            uc.new_uc_box();
        }
    },
    fb_logged: function(){
        uc.is_fb_logged = true;
        $("#fb_box").slideUp();
        uc.new_uc_box();
    },
    new_uc_box: function(){
        var url;
        if(uc.type == "comment"){
            url = "/event/" + uc.aev_id + "/comments/new/"
        }else if(uc.type == "preview"){
            url = "/event/" + uc.aev_id + "/user_previews/new/"
        }else if(uc.type == "edit_preview"){
            url = "/event/" + uc.aev_id + "/user_previews/edit/"
        }
        $("#post_uc_box").load(url, null, function(){
                        $("#post_uc_box").slideDown();
                        $("#uc_form").ajaxForm({success: uc.show_uc_box});
                     });
    },
    show_uc_box: function(data, text_status){
        $("#post_uc_box").html(data);
        $("#uc_form").ajaxForm({success: uc.show_uc_box});
    },
    comment_posted: function(){
        /* no_comments is declared in artist.html to tell that there is no
         * comments for this page yet */
        if(typeof no_comments != "undefined" && no_comments){
            $("#comments_list_box").show();
            $("#comments_list").html($("#post_uc_box").html());
            no_comments = false;
        }else{
            $("#comments_list").prepend($("#post_uc_box").html());
        }
        $("#post_uc_box").slideUp();
        uc.status = "";
    },
    preview_posted: function(){
        $("#writeapreview_link").slideUp();
        if(uc.top_preview == 1){
            $("#see_all_previews").slideDown();
        }
        $("#previews_box").slideDown();
        uc.show_previews();
        uc.status = "";
    },
    show_previews: function(){
        // scrap the html, put the first one in its own box
        if(!this.showing){
            var url = "/event/" + uc.aev_id + "/user_previews/";
            $.get(url, null,
                    function (data, textStatus){
                        data = $(data);
                        ajax_top_preview = $(data.get(0)).html();
                        $("#top_preview").html(ajax_top_preview);
                        $(data.get(0)).html(" ");
                        $("#user_previews_list").html(data);
                    }, "html");
            $("#user_previews_list").slideDown();
        }else{
            $("#user_previews_list").slideUp();
        }
        this.showing = !this.showing;
    },
    edit_preview: function(){
        uc.login("edit_preview");
    },
};
uc.show_previews.showing = false; //begs to sit near its function
