$('.answer_to_comment').live('click',
function(eve) {	
	eve.preventDefault();
    id = $(this).attr('id');
    a = $(this);    
        
    $('#edit_form_' +  id).hide();
    $('#comment_' + id).show(0);
    $('#answer_form_' + id + ' textarea[name=\'comment\']').val('');
    $('#answer_form_' +  id).show();        
    $('#answer_form_' + id + ' [name=\'comment\']').focus();
});

$('.answer_form_close').live('click',
		function(eve) {	
			eve.preventDefault();
		    id = $(this).attr('id');		        		    		    		    
		    $('#answer_form_' +  id).hide(0);
		    $('#answer_form_' + id + ' textarea[name=\'comment\']').val('');		        
		    $('#answer_form_' + id + ' [name=\'comment\']').focus();
		});

$('.edit_form_close').live('click',
		function(eve) {	
			eve.preventDefault();
		    id = $(this).attr('id');		        		    		    		    
		    $('#edit_form_' +  id).hide(0);
		    $('#comment_' +  id).show(0);
		    $('#edit_form_' + id + ' textarea[name=\'comment\']').val('');		        
		    $('#edit_form_' + id + ' [name=\'comment\']').focus();
		});

$('.edit_comment').live('click',
		function(eve) {	
			eve.preventDefault();
		    id = $(this).attr('rel');		    
		    
		    comment = $('#comment_' + id);
		    a = $(this);		    		    
	    	txt = $.trim(comment.html()).br2nl();	    		    	
	    	
	    	$('#comment_' +  id).hide(0);
	    	$('#answer_form_' +  id).hide();
			$('#edit_form_' +  id).show();			    				
			$('#edit_form_' + id + ' textarea[name=\'comment\']').val(txt);
			$('#edit_form_' + id + ' [name=\'comment\']').focus();
			$('#edit_form_' + id + ' textarea[name=\'comment\']').higit_textarea_expander();
		});

$('.comment').live('dblclick',
		function(eve) {	
			eve.preventDefault();
		    id = $(this).attr('rel');		    
		    comment = $('#comment_' + id);		    		    		    
	    	txt = $.trim(comment.html()).br2nl();	    		    		    	
		    if($('#edit_' + id).text().length) {
		    	$('#comment_' +  id).hide(0);
		    	$('#answer_form_' +  id).hide();
				$('#edit_form_' +  id).show();				
				$('#edit_form_' + id + ' textarea[name=\'comment\']').val(txt);
				$('#edit_form_' + id + ' [name=\'comment\']').focus();
				$('#edit_form_' + id + ' textarea[name=\'comment\']').higit_textarea_expander();
		    }
		});


$('.item_info_text > div.form > form')
.live(
    'submit',
    function(eve) {
        eve.preventDefault();        
        var form_block = $(this).closest(
            'div.form');
        var url = $(this).attr('action');
        var dataString = $(this)
        .serializeObject();
        $
        .ajax({
            type : "POST",
            url : url,
            data : {
                data : dataString
            },
            dataType : 'json',
            beforeSend : function() {
                form_block
                .block({
                    css : {
                        width : '50%'
                    },
                    message : '<div class="loader"><div class="image"> </div></div>'
                });
            },
            success : function(obj) {
                break_callback = callback_json_parse(obj);
                if (break_callback == null) {
                    form_block
                    .unblock();
                    return;
                }
                $('#comment_form > a.show_form')
                .show();
                //$('#comment_form > div.form')
                //.remove();
                if (obj.html != null) {
                	if (obj.edit == 1) {
                		$('#comment_' + obj.comment_id).html(obj.html);
                		$('#comment_' + obj.comment_id).show(0);
                		//$('#answer_form_' + obj.comment_id + ' input[name=\'edit\']').val(0);
                	} else {
                    $('#comment_answers_' + obj.comment_id + ' > ul')
                    .prepend(
                        obj.html                        
                        );
                	}
                } else {
                    if (obj.error != null)
                        $('#comment_answer_form')
                        .append(
                            obj.error);
                }
                
                $('#comment_content textarea').higit_textarea_expander();
//                
                // unblock textarea
                form_block.unblock();
                //cleaning content in textarea
                if (obj.edit==1){
                	$('#edit_form_' + obj.comment_id + ' [name=\'comment\']').val('');
                	$('#edit_form_' + obj.comment_id).hide();
                } else {
                	$('#answer_form_' + obj.comment_id + ' [name=\'comment\']').val('');
                	$('#answer_form_' + obj.comment_id).hide();
                }                                                                
            },
            error : function() {
                form_block.unblock();
            }
        });
    });
