$(document).ready(function() {
	$('.hmenu_table .item a').hover(function() {
		$(this).parent().addClass('hover')
	})
	$('.hmenu_table .item a').mouseout(function() {
		$(this).parent().removeClass('hover')
	})
	$('.hmenu_table .item a').click(function() {
		if ($(this).parent().parent().find('.item').hasClass('clicked')) {
			$(this).parent().parent().find('.item').removeClass('clicked')
			$(this).parent().parent().find('.left_c').removeClass('left_c_clicked')
			$(this).parent().parent().find('.right_c').removeClass('right_c_clicked')
		}	
		$(this).parent().toggleClass('clicked')
		$(this).parent().prev('.left_c').toggleClass('left_c_clicked')
		$(this).parent().next('.right_c').toggleClass('right_c_clicked')
	})
	$('.leftmenu li').click(function() {
//		$(this).toggleClass('active');
		$(this).parent().find('li').removeClass('active')
		$(this).addClass('active')
		location.href = $(this).find('a').attr('href');
	})
	$('.module_title').click(function() {
		$(this).toggleClass('vis')
		$(this).parent().find('.module_content').slideToggle('fast');
	})
	$('.lang a').click(function() {
		$(this).parent().find('a').removeClass('active');
		$(this).parent().find('span').removeClass('near_active');
		$(this).addClass('active');
		$(this).prev('span').addClass('near_active');
		$(this).next('span').addClass('near_active');
	})
	

	$('.basket_del_img').hover(function() {
		var w = $(this).attr('src');
		w = w.substr(0, w.length - 12);
		x = w + 'del_red.gif';
		$(this).attr('src', x);
	});
	$('.basket_del_img').mouseout(function() {
		var w = $(this).attr('src');
		w = w.substr(0, w.length - 11);
		x = w + 'del_grey.gif';
		$(this).attr('src', x);
	})
	$('.dotted').click(function() {
        if ($('.login_popup').css('display') == 'block')
        {
            $('.login_popup').css('display', 'none');
        }
		else {
            $('.login_popup').css('display', 'block');
        }
	})
	$('.login_popup_title').click(function() {
		$('.login_popup').css('display', 'none');
	})
	$('#close-up-win').click(function() {
		$('.login_popup').css('display', 'none');
	})
    $("#search_query").focus(function(){
          if(this.value == 'введите название')
               this.value = '';
     });
     $("#search_query").blur(function(){
          if(this.value == '')
               this.value = 'введите название';
     });

     $("#doctor_code").focus(function(){
          if(this.value == 'введите код врача')
               this.value = '';
     });
     $("#doctor_code").blur(function(){
          if(this.value == '')
               this.value = 'введите код врача';
     });
	  
	//if ($('#s_go').length > 0) {
		var options = { 
			serviceUrl:'/dbs5.files/i/pharmalad/requests/search_autocomplete.php', 
			minChars:3,
            width: 459,
            onSelect: function(text, data) {
                value = text.replace(/<[^>]+>/g, '');
                $("#search_query").parents('form').find('input[name=type]').val(data == 'atx' ? 'atx' : 'tovar');

                $("#search_query").attr('value', value);

                $("#search_query").parents('form').submit();
            },
            offset: {top:5, left:-4}
		};
		r_autocomp = $('#search_query').autocomplete(options);
	//}
	
})

