﻿
$(document).ready(function() {
    $('#nomer #form1').attr('action', "/" + $('#form1').attr('action'));


    var search_box = $('#content .right .search input');
    var search_btn = $('#content .right .search a');
    var search_pat = $('#content .right .search span b');
    // Копирование номера из раздела например в поле ввода
    search_pat.click(function() {
        search_box.val($(this).html());
    });
    // Поиск
    search_btn.click(function() {
    if ($.trim(search_box.val()) != '')
            document.location.href = "/" + search_box.val() + "/";
    });
    search_box.keypress(function(e) {
        if (e.which == 13) {
            search_btn.click();
            return false; // останавливаем срабатывание Enter'a внутри формы
        }
    });


    /* Главная страница *//**/
    // Всплывает подсказка с номером при наведении на картинку
    $('#main #content .lastphoto .item').hover(
        function() {
            $(this).children('a.hdr').slideDown('fast');
        },
        function() {
            $(this).children('a.hdr').slideUp('fast');
        });

    /* Страница с номером *//**/
    // Добавление комментария
    $('#nomer .newcomment a.link').click(function() {
        $('#nomer .newcomment .add div').slideToggle('fast');
    });
    // Добавление тегов
    $('#nomer .newcomment a.tag').click(function() {
        var tags = $('#nomer .newcomment .add input:eq(2)').val();
        var newtag = $(this).html();
        //проверка на существование
        var pos = tags.indexOf(newtag, 0);
        if (pos < 0) {
            // добавление
            tags = $.trim(tags);
            if (tags != '') {
                if (tags.charAt(tags.length - 1) != ',')
                    tags += ', ';
                else
                    tags += ' ';
            }
            tags += newtag;
            $('#nomer .newcomment .add input:eq(2)').val(tags);
        }
    });
    
    /* Страница с фотографиями *//**/
    // Растягивание фотографий
    $('#photos .slider').slider({ min: 100, max: 400, step: 2, animate: true })
                        .bind('slide', Slide)
                        .bind('slidestop', Slide);
});

function Slide(event, ui)
{
    var width = ui.value;
    $('#photos #content .list .item').stop().animate({'width' : width, 'height' : (width + 20)}, 'slow');
}
