
function removeNewState(){
    var new_comm = $('.new_comm, .new_view');
    new_comm.removeClass('new_comm');
    new_comm.removeClass('new_view');
}
function updateRPanelCounter(){
    NEW_COMMENTS_JQ = $('.new_comm, .new_view');
    new_comm_count = NEW_COMMENTS_JQ.length;
    comm_number_field = $('#right_panel img[src$=next.gif]').closest('tbody').children(':first').children();
    comm_number_field.text(new_comm_count);
    curr_comm = 0;
}

$(document).ready(function() {
	$('#right_panel').show();//показываем боковую панельку
	$('#right_panel img[src$=open.gif]').parent().click(function() {
		$('table.comm_close').show();$('table.comm_open').hide();
		return false;
	});
	//тоже самое для закрыть всё
	$('#right_panel img[src$=close.gif]').parent().click(function() {
		$('table.comm_close').hide();$('table.comm_open').show();
		return false;
	});
	//вешаем обработчик для перехода на следующий коментарий
	updateRPanelCounter();

	var next_link = $('#right_panel img[src$=next.gif]').parent();
	next_link.click(function() {
	    var new_comm = NEW_COMMENTS_JQ;

            if(new_comm_count>0){
                    new_comm_count-=1;
                    comm_number_field.text(new_comm_count);
                    if($(new_comm[curr_comm]).is('.new_comm')){//если обычный коментарий
                        var hidden = $(new_comm[curr_comm]).closest('table:hidden');
                        if(hidden){
                                hidden.show().prev().hide();
                        }
                        $(new_comm[curr_comm]).children('.text').effect('pulsate', { times:1 }, 400);

                    }else{//если новое мнение
                        $(new_comm[curr_comm]).children().children().children().children('div.text').effect('pulsate', { times:1 }, 400);
                    }

                    $(new_comm[curr_comm]).removeClass('new_comm');
                    $(new_comm[curr_comm]).removeClass('new_view');

                    $.scrollTo($(new_comm[curr_comm]),200, {offset:{left:0, top:-100}});
                    curr_comm+=1;

            }
            return false;
	});
});

