var obj = null;
var clicked1 = false;
var clicked2 = false;

function closes()
{
	$('.b_close a').click(
		function(){
			$(this).parent().parent().remove();
			return false;
	});
}

function fn()
{
	obj.fadeOut(200);
	var id = obj.attr("id");
	var but_id = id.substring(0, id.length-5);
	$('#'+but_id).show();
	$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
	$('.service_item').removeClass('a_service_item');
}

$(document).ready(function(){
	$('body').pngFix( );

	if($('#serv_cont').height() < 600) $('#serv_cont').height(600);

/*	$('#s_about_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_about1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_about.png'); }
	);
	$('#s_control_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_control1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_control.png'); }
	);
	$('#s_publicity_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_publicity1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_publicity.png'); }
	);
	$('#s_clients_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_search_clients1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_search_clients.png'); }
	);*/

	$('.tab a').hover(
		function(){
			$(this).css('color', '#699C00');
			$(this).parent().css({'background': 'url(img_n/tab_bg.gif) repeat-x 0px -10px', 'background-color':'#F9F9FA'});
			$(this).parent().prev().css({'background-color':'#DDDFE1'});
			$(this).parent().prev().children().attr('src','img_n/emp.gif');
			$(this).parent().next().css({'background-color':'#DDDFE1'});
			$(this).parent().next().children().attr('src','img_n/emp.gif');
		},
		function(){
			$(this).css('color', '#666666');
			$(this).parent().css({'background': 'url(img_n/tab_bg.gif) repeat-x 0px 0px', 'background-color':'#F9F9FA'});
			$(this).parent().prev().css({'background-color':'#ffffff'});
			$(this).parent().prev().children().attr('src','img_n/tab_l.gif');
			$(this).parent().next().css({'background-color':'#ffffff'});
			$(this).parent().next().children().attr('src','img_n/tab_l.gif');
		}
	);

	$('.b_search').hover(
		function(){ $(this).attr('src', 'img_n/b_search1.png'); },
		function(){ $(this).attr('src', 'img_n/b_search.png'); }
	);
	$('.b_search').click(
		function(){
			if (($('#qwe').val()=='') || ($('#qwe').val()=='Что искать:')) {
				alert('Не задано значение для поиска!');
				$('#qwe').focus();
				return false;
			}
			else {
				$('#loading').show();
				return true;
			}
	});


	$('.b_search2').hover(
		function(){ $(this).attr('src', 'img_n/b_search1.png'); },
		function(){ $(this).attr('src', 'img_n/b_search.png'); }
	);
	$('.b_search2').click(
		function(){
			if (($('#qwe2').val()=='') || ($('#qwe2').val()=='Что искать:')) {
				alert('Не задано значение для поиска!');
				$('#qwe2').focus();
				return false;
			}
			else {
				$('#loading').show();
				return true;
			}
	});


	$(document).ready(
		function(){ 
			$('.b_search').attr('src', 'img_n/b_search.png');
			$('.b_search2').attr('src', 'img_n/b_search.png');
			$('#b_login').attr('src', 'img_n/b_login.png');
			$('#b_login2').attr('src', 'img_n/b_login.png');
	}); 


	$('#qwe').click(
		function(){
			if(!clicked1)
			{
				$(this).val('');
				clicked1 = true;
			}
	});
	$('#qwe2').click(
		function(){
			if(!clicked2)
			{
				$(this).val('');
				clicked2 = true;
			}
	});

	$('#qwe2').keyup(
		function(){
			$('#te_type').empty();
			$('#te_type').append($(this).val());
	});

	$('#region_f1').click(
		function(){
			$('#re_type').empty();
			$('#re_type').append('Россия, '+$('#region_f1 option:selected').text());
	});

	$('#tmark').click(
		function(){
			$('#utt_type').empty();
			$('#utt_type').append('Товары: '+$('#tmark option:selected').text());
	});

	$('#typeusl_0').click(
		function(){
			$('#utt_type').empty();
			$('#utt_type').append('Услуги: '+$('#typeusl_0 option:selected').text());
	});

	$('.service_item').hover(
		function(){
			id = $(this).attr("id");
			if($('#'+id+'_info').css('display')!='block')
			{
				$('#'+id+'_pic').attr('src', 'img_n/'+id+'1.png');
				$("a", this).each(function(){
					$(this).addClass('hov');
				});
			}
		},
		function(){
			id = $(this).attr("id");
			$('#'+id+'_pic').attr('src', 'img_n/'+id+'.png');
			$("a", this).each(function(){
				$(this).removeClass('hov');
			});
		}
	);

	$('.service_item').click(
		function(){
			//?ane?uaaai
			if(!$(this).hasClass('a_service_item'))
			{
				var item = $(this);
				$('.service_item').each(function(){
					if( $(this).attr('id') != item.attr('id')) $(this).hide();
				});
				$(this).animate({"top":"-70px"}, 400, "linear", function(){
																	$(this).addClass('a_service_item');
																}
				);
				$('#'+item.attr('id')+'_info').fadeIn(400);
			}
/*			else// cae?uaaai
			{
				$('.serv_info_table').fadeOut(200);
				var but_id = $(this).attr("id");
				$('#'+but_id).show();
				$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
				$('.service_item').removeClass('a_service_item');
			}*/

			return false;
		}
	);

/*	$('.serv_info_table').hover(
		function(){},
		function(){ obj = $(this); setTimeout( 'fn();', 1500);
	});*/


	$('.b_hide_text').click(
		function(){
			$('.serv_info_table').fadeOut(200);
			var but_id = $(this).attr("id");
			$('#'+but_id).show();
			$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
			$('.service_item').removeClass('a_service_item');
	});



	$('#tab1 a').click(
		function(){
			$('#atab1').show();
			$('#tab1').hide();
			$('#tab2').show();
			$('#atab2').hide();
			$('#atab3').hide();
			$('#tab3').show();

			$('#search_block').show();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').hide();
			$('#sale_block2').hide();
			$('#sale_block3').hide();
			$('#sale_block4').hide();

			return false;
	});

	$('#tab2 a').click(
		function(){
			$('#atab1').hide();
			$('#tab1').show();
			$('#tab2').hide();
			$('#atab2').show();
			$('#atab3').hide();
			$('#tab3').show();

			$('#search_block').hide();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').show();
			$('#sale_block2').show();
			$('#sale_block3').hide();
			$('#sale_block4').hide();

			return false;
	});

	$('#tab3 a').click(
		function(){
			$('#atab1').hide();
			$('#tab1').show();
			$('#atab2').hide();
			$('#tab2').show();
			$('#atab3').show();
			$('#tab3').hide();

			$('#search_block').hide();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').hide();
			$('#sale_block2').hide();
			$('#sale_block3').show();
			$('#sale_block4').show();

			return false;
	});


	$('.wide_search').click(
		function(){
			$('#search_block').hide();
			$('#wide_search_block').show();
			$('#wide_search_block2').show();
			$('#bsearch').pngFix();
			$('#bsearch2').pngFix();

			return false;
	});

	$('.back_tosearch').click(
		function(){
			$('#search_block').show();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#bsearch').pngFix();
			$('#bsearch2').pngFix();

			return false;
	});

	$('input[type=radio]').click(
		function(){
			var n = $(this).attr('name');
			var val = $(this).attr('value');
			if( (n=="type")&&((val=="1")||(val=="2")||(val=="3"))||(val=="4") )
			{
				$('#wshr').show();
				$('#ws_sh').show();
				$('#ws_opt').show();
				$('#ws_pro').show();
				$('#wtov1').show();
				$('#wtov2').show();
				$('#wuss1').hide();
				$('#wuss2').hide();

				$('#sh_type').empty();
				$('#sh_type1').show();
				if (val=='3') {	$('#sh_type').append('В описании товаров');	}				
				if (val=='1') {	$('#sh_type').append('В названии организации - товары');	}				
				if (val=='2') {	$('#sh_type').append('В адресе организации - товары');	}				
				if (val=='4') {	$('#sh_type').append('В ФИО руководителя - товары');	}	

				$('#utt_type').empty();
				$('#utt_type').append('Товары: '+$('#tmark option:selected').text());
			}
			if( (n=="type")&&((val=="5")||(val=="6")||(val=="7"))||(val=="8") )
			{
				$('#wshr').hide();
				$('#ws_sh').hide();
				$('#ws_opt').hide();
				$('#ws_pro').hide();
				$('#wtov1').hide();
				$('#wtov2').hide();
				$('#wuss1').show();
				$('#wuss2').show();

				$('#sh_type').empty();
				$('#sh_type1').hide();
				if (val=='5') {	$('#sh_type').append('В описании услуг');	}				
				if (val=='6') {	$('#sh_type').append('В названии организации - услуги');	}				
				if (val=='7') {	$('#sh_type').append('В адресе организации - услуги');	}				
				if (val=='8') {	$('#sh_type').append('В ФИО руководителя - услуги');	}				

				$('#utt_type').empty();
				$('#utt_type').append('Услуги: '+$('#typeusl_0 option:selected').text());
			}

			if( (n=="ptype")&&(val=="ro") )
			{
				$('#sh_type1').empty();
				if (val=='ro') { $('#sh_type1').append(', магазины');	}	
			}
			if( (n=="ptype")&&(val=="op") )
			{
				$('#sh_type1').empty();
				if (val=='op') { $('#sh_type1').append(', оптовые компании');	}	
			}
			if( (n=="ptype")&&(val=="pr") )
			{
				$('#sh_type1').empty();
				if (val=='pr') { $('#sh_type1').append(', производство'); }	
			}




	});


	$('.list div a').click( 
		function(){
			$(".pop_block").each(function(){
				$(this).remove();
			});

/*			$('#d'+num).html('<div class="pop_block"><div class="b_close">Iiai?aeoa, eaao caa?ocea ...</div></div>');
*/
			var num = $(this).attr('num')

			jQuery.ajax({url:'out_tov1.php', type:'get', data:'tmark='+num, success:function(data){ $('#d'+num).html(data); } });
			closes();
			return false;
	});

	$('.list2 div a').click(
		function(){
			var num = $(this).attr('num');
			if($('#sm'+num).css('display')=='none')
			{
				$('#sm'+num).show(300);
				$(this).addClass('act');
			}
				else
				{
					$('#sm'+num).hide(300);
					$(this).removeClass('act');
				}
			return false;
	});

	/*$('.list2').hover(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='none')
				{
					$('#sm'+num).show(300);
					$(this).addClass('act');
				}
			});
			$('#open_all_block').hide();
			$('#close_all_block').show();
			return false;
	},
		function(){}
	);*/


	$('#open_all_block').click(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='none')
				{
					$('#sm'+num).show(300);
					$(this).addClass('act');
				}
			});
			$('#open_all_block').hide();
			$('#close_all_block').show();
			return false;
	});


	$('#close_all_block').click(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='block')
				{
					$('#sm'+num).hide(300);
					$(this).removeClass('act');
				}
			});
			$('#open_all_block').show();
			$('#close_all_block').hide();
			return false;
	});


	$('#region_f').change(
		function(){

		var num1=$('#region_f').val();
/*	    alert('Auai? naaeai!'+num1);*/
		jQuery.ajax({url:'out_sel_1.php', type:'get', data:'id_region='+num1, success:function(data){ $('#u_city').html(data); } });
		return false;
	});

	$('#region_f1').change(
		function(){
		var num1=$('#region_f1').val();
		jQuery.ajax({url:'out_sel_1.php', type:'get', data:'id_region='+num1+'&tp=2', success:function(data){ $('#u_city1').html(data); } });
		return false;
	});

	$('#tmark').change(
		function(){
		var num1=$('#tmark').val();
		jQuery.ajax({url:'out_tov_1.php?tmark=', type:'get', data:'tmark='+num1, success:function(data){ $('#out_tov').html(data); } });
		return false;
	});

	$('#typeusl_0').change(
		function(){
		var num1=$('#typeusl_0').val();
		jQuery.ajax({url:'out_usl_1.php?typeusl_0=', type:'get', data:'typeusl_0='+num1, success:function(data){ $('#out_usl').html(data); } });
		return false;
	});


	$('.list2 div span a').click(
		function(){
			$(".pop_block").each(function(){
				$(this).remove();
			});

			var num1 = $(this).attr('num1');
			
			if (num1=='1000001') { top.location = "http://jobrapido.ru"; }
			else {
				jQuery.ajax({url:'out_uss1.php', type:'get', data:'id_typeusl_0='+num1, success:function(data){ $('#u'+num1).html(data); } });
			}
			closes();
			return false;
	});

	$('#qwe').click(
		function(){
			$('#where_search').show();
		}
	);


});



