$(document).ready(function(){
	/*поиск*/
	$('#search_button a img').click(function(e){	
		/*откл пеерход по ссылке*/
		e.preventDefault();	
		/*если поиск уже открыт, то закрываем
		иначе открываем*/
		if ($('#top_button #search').css("display") == 'none')
		{
			$(this).attr('src','i/search_icon.jpg');
			$('#top_button #search').fadeIn(300);			
		}
		else{
			$('#top_button #search').fadeOut(300);
			$(this).attr('src','i/search_button.jpg');
		}
	});
	
	$('#close_search').click(function(e){
			$('#top_button #search').fadeOut(300);
			$('#search_button a img').attr('src','i/search_button.jpg');
	});
	function search(){
			/*строка поиска*/
	 var search = document.getElementById('search_input').value;
		/*Не работает в IE*/
	if (navigator.appName =='Microsoft Internet Explorer'){
		location.replace('http://' + document.domain + '/search.html?search=' + search +'&ie=true');
	}else{
		/*лоадер*/
		$('#text_block').html('<img src="images/loading1.gif" style="margin-left: 40%;position: absolute;">');	
		/*запрос*/
		$.ajax({
			type: "GET",
			url: "/_tpl/search.tpl.php",
			data:{search:search},
			success: function(html){			
			/*вывод найденногг текста*/
			$('#text_block').html(html);
		   }		   
		});
		};
	}
	
	/*нажатие на кнопку поиска*/
	$('#search_input').keypress(function(e) {
		if(e.keyCode == 13) {
			search();
		}
	});

	
	$('#search_btn').click(function(){	
	search();
	});
	/*Не работает в IE*/
	if (navigator.appName !='Microsoft Internet Explorer'){
	/*подписи под верхними кнопками*/
		$('#top_function_image a img').mouseover(function(){
			title=$(this).attr('alt');
			$(this).parent().prev('.title').html(title);
		});
		
		$('#top_function_image a img').mouseout(function(){
			title='';
			$(this).parent().prev('.title').html(title);
		});
	};
});
