$(function() {

	var self=this,
		
		$questBlock = $('.block_m .block3 .filling .questions_block');
		$question = $('.questions a.open', $questBlock),
			
		$point = $('.department_block .map_big li a');


		$question.click(function() {
			$.thisLink = $(this);
			
			
			if(! $(this).parent().parent().hasClass('act')){

				$.thisLink.parent().parent().addClass('act');
				$.thisLink.parent().parent().find('.fulltxt').slideDown(500);
				
			} else {
				
				$.thisLink.parent().parent().removeClass('act');
				$.thisLink.parent().parent().find('.fulltxt').slideUp(500);
		
			}

			return false;	
		});

		


		      
	  
	  $point.hover(function(){
			$(this).parent().find('.name').show();
			$(this).parent().css({zIndex: 1});
		}, function(){
			$(this).parent().find('.name').hide();
			$(this).parent().css({zIndex: 0});
		});	
	  

      $('.inside > a.close').click(function(){
	  	  $('.department_block').hide();
	  });
    
	
	  $('a.open_depart, ul.links > #depart').click(function(){
	  	  $('.department_block').show();
		  $('div.map_big').hide();
		  $('.general_cont').show();
		  $('#map').removeClass();
		  $('#depart').addClass('act');
	  });
	  
	  $('a.map, ul.links > #map').click(function(){
	  	  $('.department_block').show();
		  $('div.map_big').show();
		  $('.depart_list').hide();
		  $('#depart').removeClass();
		  $('#map').addClass('act');
	  });

      
      $('div.okrug[id!=ser_depart_okrug] > ul > li > a').click(function(){
	  	  
		  var okrug  = parseInt($(this).attr('rel')),
		      that   = $(this);			  
			  
		  $.ajax({
		  		type     : 'post',
                url      : '/ajax.php',
				data     : 'okrug='+okrug,
                dataType : 'html',
				success  : function(data){
					if (data!=''){
						$('div.section ul').html(data);
						$('div.okrug > ul > li').removeClass();
						that.parent().addClass('act');				
					}
				}
			
		  })
		  
	  });
      
	  
	  
	  $('ul.menu1 li[class=\'act\']:last > a, ul.menu2 li[class=\'act\']:last > a ').click(function(){
	  	
		if ($('ul.menu1').attr('rel') !== 'none') {
		
			var ul = $(this).parent().find('ul');
			
			if (ul.length != 0) {
				if (ul.is(':hidden')) {
					ul.slideDown();
				}
				else {
					ul.slideUp();
				}
				return false;
			}			
		}
		
		
	  });

     
	 $('dl.faq_list a:not(.admin_q)').click(function(){
	 	
		$(this).parent().find('div:first').slideToggle();
		return false;
		
	 });
	 
	 
	 $('li.all_quest a').click(function(){
	 	
		
		if($(this).hasClass('open')){
			$('dl.faq_list div.li > div').slideUp();
			$(this).removeClass().addClass('closed');			
			$(this).parent().find('span').text('Показать все ответы');	 
		}else{
			$('dl.faq_list div.li > div').slideDown();
			$(this).removeClass().addClass('open');
			$(this).parent().find('span').text('Скрыть все ответы');		
		}		
		
		return false;
	 });
	 
	 
	 $('div.slide_block div.lenta img').click(function(){	 	
		
		var prev_src = $('#cur_foto').attr('src'),
		    prev_rel = $('#cur_foto_autor').text();
			
		$('#cur_foto').attr('src',$(this).attr('src'));
		$('#cur_foto_autor').text($(this).attr('rel'));
		
		$(this).attr('src',prev_src);	
		$(this).attr('rel',prev_rel);
	 });
	 
	 var count_report = $('div.slide_block div.lenta img').length,
	     counter = 3;
	 
		 	 
     $('div.slide_block a.next').click(function(){
	      
		  if (counter!=count_report && !$('div.lenta').is(':animated') && count_report>3){
		  	  var left = $('div.lenta').css('left'),
		      px   = parseInt(left.substring(0,left.length-2));			  
			  
			  $('div.lenta').animate({left: px-70},300);
			  counter++;
		  }		 
		  
	 });
	 
	 
	  $('div.slide_block a.prev').click(function(){
	      
		  if (counter!=3 && !$('div.lenta').is(':animated') && count_report>3){
		  	  var left = $('div.lenta').css('left'),
		      px   = parseInt(left.substring(0,left.length-2));			  
			 			  
			  $('div.lenta').animate({left: px+70},300);
			  
			  counter--;
		  }		 
		  
	 })	;		
	 
	jQuery.each($('#branches input:checked'), function() {         
		 $('#depart_selected').append("<li>"+$(this).parent().text()+"<span rel="+$(this).attr('id')+" title='Удалить поиск по  отделению'>Удалить поиск по отделению</span></li>");
	});
	
	jQuery.each($('#ser_chapters input:checked'), function() {         
		 $('#chap_selected').append("<li>"+$(this).parent().text()+"<span rel="+$(this).attr('id')+" title='Удалить поиск по разделу'>Удалить поиск по разделу</span></li>");
	}) ;
	
	
	$('#d_all').click(function()
			{
				if($('#d_all').attr('checked'))
				{
					$('#ser_chapters input').attr('checked', true);
				} else {
					$('#ser_chapters input').attr('checked', false);
				}
			});
	 
	 
	$('#open_ser_depart').click(function(){
		
		$('#ser_depart').show();
		$('#depart_index').css('z-index',10);
		
	});
	
	
	$('#close_ser_depart').click(function(){
		
		$('#ser_depart').hide();
		$('#depart_index').css('z-index',0);
		
	});
	
	
	$('#open_ser_chapters').click(function(){
		
		$('#ser_chapters').show();
		$('#chapters_index').css('z-index',10);
		
	});
	
	
	$('#close_ser_chapters').click(function(){
		
		$('#ser_chapters').hide();
		$('#chapters_index').css('z-index',0);
		
	});
	 
	 
	$('#ser_chapters input').click(function(){
		var text = $(this).parent().text(),
		    id   = $(this).attr('id');
		
		if (!$(this).is(':checked')){			
			$('#chap_selected span[rel='+id+']').parent().remove();
		}else{
			$('#chap_selected').append("<li>"+text+"<span rel="+id+" title='Удалить поиску по разделу'>Удалить поиск по разделу</span></li>");
		}		
		
	});
	
	$('#chap_selected span').live('click', function(){
		
		var id   = $(this).attr('rel');
	
		$('#'+id).attr('checked',0);
		$(this).parent().remove();
		
	});
	
	
	$('#ser_depart input').live('click',function(){
		var text = $(this).parent().text(),
		    id   = $(this).attr('id');
		
		if (!$(this).is(':checked')){			
			$('#depart_selected span[rel='+id+']').parent().remove();
		}else{
			$('#depart_selected').append("<li>"+text+"<span rel="+id+" title='Удалить поиск по отделению'>Удалить поиск по отделению</span></li>");
		}		
		
	});
	
	
	$('#depart_selected span').live('click', function(){
		
		var id   = $(this).attr('rel');
	
		$('#'+id).attr('checked',0);
		$(this).parent().remove();
		
	});
	
	
	$('#ser_depart #ser_depart_okrug ul > li > a').click(function(){
		
	   	 var okrug  = parseInt($(this).attr('rel'));
		 
		 $('#branches ul ').hide();
		 $('#branches #o'+okrug).show();
		 
		 $('div.okrug > ul > li').removeClass();
		 $(this).parent().addClass('act');			 
		
		
	});
	
	$('#mark_all').click(function(){
		$('input.operate_box').attr("checked","checked");
		return false;
	});
	
	$('#skip_all').click(function(){
		$('.operate_box').attr("checked","");
		return false;
	});
	
	
	$('div.preview_foto > a > img').hover(function(){
		
		var src     = $(this).attr('src'),
			rel     = $(this).parent().attr('rel'),
		    big_src = $('img.big_foto').attr('src');
		
		$('img.big_foto').attr('src',src);
		$('img.big_foto').parent().attr('href',rel);
		
	
	});
	  
	
	(function(){
		
		
	 	var $test_fil   = $('#test_fil'),
			$form       = $('#form_online'),
			$input      = $form.find('input'),
			$area       = $form.find('textarea'),
			$okr_select = $('#okr_select');
		
		
		
		
		if($okr_select.val() != "didnt"){
			$input.removeAttr("disabled");
			$area.removeAttr("disabled");
		};
		
		$test_fil.change(function(){
			if($test_fil.val() != "didnt"){
				$input.removeAttr("disabled");
				$area.removeAttr("disabled");
			}
			else{
				disable_form();
			}
		});
	
		$okr_select.change(function(){
		
			if($okr_select.val() != "didnt"){
				$test_fil.removeAttr("disabled");
			}
			else{
				$test_fil.attr("disabled","disabled");
			}
			
		});
		
		function disable_form(){
			$input.attr("disabled","disabled");
			$area.attr("disabled","disabled");
		};
		
		$('#okr_select').change(function(){
		  	  
			  var okrug  = parseInt($(this).val());
			
			  disable_form();	
						  
			  $.ajax({
			  		type     : 'post',
	                url      : '/ajax.php',
					data     : 'okrug_online='+okrug,
	                dataType : 'html',
					success  : function(data){
						if (data!=''){
							$test_fil.html(data);
						}
					}
				
			  })
		  })
		
	})();
	(function(){
		var $ph = $('#ph');
		$ph.focus(function(){
			$ph.val('')}).blur(function(){if($ph.val()==''){$ph.val('Код +')}})

	})();
	(function(){
		var $fx = $('#fx');
		$fx.focus(function(){
			$fx.val('')}).blur(function(){if($fx.val()==''){$fx.val('Код +')}})

	})();
})
