function hideMgs() {
    $(".msg").slideUp();
}

$(document).ready(function() {
    $(".login_link").click(function() {
        $("#login_frm").dialog("open").dialog({
            "title": "Log In",
            "width": 220
        });
        
        return false;
    });
    
    $("#new_comment").click(function() {
        $("#comment_frm").dialog("open").dialog({
            "title": "Post a Text Comment",
            "width": 220
        });
        
        return false;
    });
    
    $("a.popup_img").fancybox({
        'overlayShow': true,
        'frameWidth': 770,
        'frameHeight': 320
    });
    
    $("a.text_box").fancybox({
        'overlayShow': true
    });
    
    if($(".msg").html()!='') {
        setTimeout("hideMgs()", 3000);
    }
    
    $("#comment_submit_btn").click(function() {
        $("#comment_frm").dialog("close");
        
        $.blockUI({
            message: "Please, wait...",
            css: { 
                border: 'none',
                padding: '15px',
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: '.5', 
                color: '#fff' 
            }
        });
        
        var txt=$("#commentText").val();
        
        JsHttpRequest.query(
            '/ajax2.php',
            {
                "text": txt,
                "video": $("#video_number").val(),
                "addComment": 1
            },
            function(result, errors) {
                $("#debug").html(errors);
                if (result) {
                    $.unblockUI({
                        onUnblock: function(){
                            $("#gray_block_comments").prepend("<p class='comment_name'>"+result['name']+"</p><p class='comment_text'>"+txt+"</p>");
                        }
                    });
                }
            },
            false
        );
    });
    
    $("#already_registered").click(function() {
        if($(this).attr("checked")) {
            $(".add_rows").show();
        } else {
            $(".add_rows").hide();
        }
    })
    
    $(".toggle_link").click(function() {
        var id=$(this).attr("id");
        
        $("#table_"+id).toggle();
        
        if($(this).data("flag")==1) {
            $(this).data("flag", 0);
            $("#img_"+id).attr("src", "/img/blue_arrow.gif");
        } else {
            $(this).data("flag", 1);
            $("#img_"+id).attr("src", "/img/blue_arrow_2.gif");
        }
        
        return false;
    });
});