$(document).ready(function() {

    $("div.inner-right a img").parent().each( function() { if( /(gif|png|jpg|jpeg)$/.test( $(this).attr('href') ) ) this.lightBox() } )
    $(".question").next().css("display","none").end().toggle(
        function() {
            $(this).addClass("answer-active");
            $(this).next().slideDown();
        },
        function() {
            $(this).removeClass("answer-active");
            $(this).next().slideUp();
        }
    );
    $(".item-faq .answer").next().css("display","none").end().toggle(
        function() {
            $(this).parent().addClass("answer-active");
            $(this).next().slideDown();
        },
        function() {
            $(this).parent().removeClass("answer-active");
            $(this).next().slideUp();
        }
    );
    $(".open-item h2").next().css("display","none").end().toggle(
        function() {
            $(this).addClass("open-active");
            $(this).next().slideDown();
        },
        function() {
            $(this).removeClass("open-active");
            $(this).next().slideUp();
        }
    );
    $("ul.menu li + li ul").parent().addClass("menu-marker");
    $("ul.menu li + li.h ul").parent().addClass("menu-marker-h");
    $("ul.menu li:first").addClass("menu-marker");
    $("ul.menu li.h:first").addClass("menu-marker-h");
    $(".inner-right .tab tr").each(
        function() { 
            $(this).find(">*:odd").addClass("odd"); 
        }
    );
    $(".inner-right .tab tr").each(
        function() { 
            $(this).find("th:odd").addClass("odd-th"); 
        }
    );
    
    inputValue8 = 'наименование услуги'
    $('div.search-service form input.service-name').focus( function(){ if($(this).attr('value') == inputValue8) $(this).attr('value', ''); });
    $('div.search-service form input.service-name').blur( function(){ if($(this).attr('value') == '') $(this).attr('value', inputValue8); });
    
    inputValue9 = 'код'
    $('div.search-service form input.service-code').focus( function(){ if($(this).attr('value') == inputValue9) $(this).attr('value', ''); });
    $('div.search-service form input.service-code').blur( function(){ if($(this).attr('value') == '') $(this).attr('value', inputValue9); });
    
    inputValue10 = 'ФИО'
    $('div.search-service form input.letter-fio').focus( function(){ if($(this).attr('value') == inputValue10) $(this).attr('value', ''); });
    $('div.search-service form input.letter-fio').blur( function(){ if($(this).attr('value') == '') $(this).attr('value', inputValue10); });
    
    //sakkada
    //custom select tag
    //select:item imulation
    $('.drop-down ul li a').click(function(){
        var p = $(this).parent().parent().parent();
        p.find(':hidden').attr('value', $(this).attr('title'));
        p.find('.sel-block').html($(this).html());
        p.find('ul').slideUp('fast');
        if( p.attr('_change') ) {
            eval( p.attr('_change') );
            f( $(this).attr('title'), $(this).html() );
        }
        return false; 
    })

    $('.drop-down-short ul li a').click(function(){
        var p = $(this).parent().parent().parent();
        p.find(':hidden').attr('value', $(this).attr('title'));
        p.find('.sel-block-short').html($(this).html());
        p.find('ul').slideUp('fast');
        if( p.attr('_change') ) {
            eval( p.attr('_change') );
            f( $(this).attr('title'), $(this).html() );
        }
        return false; 
    })

    
    //select click
    $(".sel-type, .sel-category").click(function() {
        ul = $(this).find('ul')
        ul.css('display') == 'none' ? ul.slideDown('fast') : ul.slideUp('fast')
    });
    
    //select mouseleave
    $(".sel-type, .sel-category").mouseleave(function() {
        ul = $(this).find('ul')
        ul.css('display') != 'none' && ul.slideUp('fast')
    });
    
    //auto fill inputs
    $('input.autofill').focus( function(){ if($(this).attr('value') == $(this).attr('title')) $(this).attr('value', ''); });
    $('input.autofill').blur( function(){ if($(this).attr('value') == '') $(this).attr('value', $(this).attr('title')); });
    
    //auto fill form behavior
    $('form.autofill').submit(function(){
        $(this).find(':text.autofill').each(function(){
            $(this).attr('value') == $(this).attr('title') && $(this).attr('value', '');
        });
    })
}); 

