/**
  * JavaScript
  *
  */

$(document).ready(function(){

    /* Tabs Panel */
    $(function(){
        $('.ajax-tabs dl dt').click(function(){
            $(this)
                .siblings().removeClass('selected').end()
                .next('dd').andSelf().addClass('selected');

            var needDd = $(this).find('a').parents('dt').next('dd').find('.content-block');
            $.get($(this).find('a').attr('href'), {}, function(data){
                needDd.html(data);
            });

            return false;
        });
        $('.ajax-tabs dl dt:first').click();
    });

    $('.company-catalog table tr:odd').addClass('odd');

    //убираем неннужные тогглеры с комментов
    $('.comments li').each(function() {
        if ($(this).children('ul').html()){
            
        }else{
            $(this).children('.c-toggle').remove();
        }
    })

    //Переходим к нужному коменту
    if (window.location.href.indexOf('#?c') != -1) {
        window.location.href = window.location.href.replace('?', '').replace('=', '')
    }
    
    //комменты
	$('.comments ul li .c-toggle').toggle(function(){
        
		if ($(this).parent().children('ul').html()) {
	    	$(this).addClass('open');
		}
	    $(this).parent().children('ul').hide();
		
	    return false;
	}, function(){
		if ($(this).parent().children('ul').html()) {
		    $(this).removeClass('open');
		}
	    $(this).parent().children('ul').show();
	    return false;
	});
    //скрыть/показать форму коммента
    $('a.show-comment-form').click(function(){
        $('div.comment-form').toggle();
        return false;
    })

    //Обработчик ответа на коммент
	$('.comments ul li .reply').click(function(){
        $('div.comment-form').show();
        $('div.comment-form input[name=path]').val($(this).attr('rel'));
        $('div.comment-form input[name=parent]').val($(this).parent('li').find('input[name=parent]').val());
        window.location.href = '#comment-form'
        return false;
	});

	//поиск
	$('.search-plate em .dashed').click(function(){
		$('.search-plate input[type=text]').attr('value', $(this).text());
	});

    
	
	return true;
})
