$(document).ready(function () {
    // показываем ответ на вопрос
    $('.question-link').click(function () {
        $('.answer', $(this).parent().parent()).toggleClass('hidden');
        $('.question-link').css('background', 'none');
        $('.question-link').css('color', '#000');
        $(this).css('color', '#18AAEF');
        return false;
    });
    // {{{ прокрутка внутри страницы
    // при загрузке
    var m = window.location.hash.match(/^#q(\d+)/i);
    if (m) {
        scrollToQuestion(m[0]);
    }
    // при клике на смотри также
    $('.smooth-scroll').click(function () {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
                && location.hostname == this.hostname) {
            return scrollToQuestion(this.hash);
        }
    });
    // }}} прокрутка внутри страницы
});
/**
 * Прокрутка окна до нужного вопроса
 *
 * @param string target_id
 */
function scrollToQuestion(target_id) {
    var target = $(target_id);
    $('.question-link').css('color', '#000');
    $('.answer', target.parent().parent()).removeClass('hidden');
    target.css('color', '#18AAEF');
    target = target.length && target || $('[@name=' + target_id.slice(1) +']');
    var targetOffset = target.offset().top;
    if (target.length) {
        $('html,body').animate({scrollTop: targetOffset}, 400);
        return false;
    }
}
/**
 * Голосование по вопросу
 */
function vote_do(form, id) {
    var vote_form = $('#vote-form-' + id);
    var vote_container = $('#vote-content-' + id);
    var checked_radio = $('.vote-value:checked', vote_form);
    var data = 'value=' + checked_radio.val();
    data += '&question_id=' + id;
    // скрываем кнопки
    vote_container.html($('#vote-thanks').html());
    // отправляем запрос
    $.post('/knowledge/vote/', data);
	return false;
}
