$(function(){
	
	
	(function(){
		
		var $labels = $('label._autohide');
		
		$labels.each(function() {

			var $label = $(this);
			var id = $label.attr('for');
			var $input = $('#'+id);
			
			$input.focus(function(){
				$label.hide();
			}).blur(function(){
				if(!$input.val()){
					$label.show();
				}
			}).change(function(){
				if($input.val()){
					$label.hide();
				}else{
					$label.show();
				}
			});
			
			if ($input.val()) {
				$label.hide();
			}
			
		});

	})();
	

	(function(){
		
		var $MenuItems = $('.menuTop ul li');
		$MenuItems.bind('mouseenter', function(e){
			this.className== 'act' ? this.className = 'act cur': this.className = 'cur';
			
		}).bind('mouseleave', function(e){
			
			this.className== 'act cur' ? this.className = 'act': this.className = '';
			
		});
		
	})();
	
	
	(function(){
	
		var $News = $('.newsBlock');
		var $NewsDatesCont = $News.find('.dateBlock .lentaCont ul');
		var $NewsDates = $NewsDatesCont.find('li');
		var $NewsItems = $News.find('dl');
		var $NextNews = $News.find('.next');
		var $PrevNews = $News.find('.prev');
		
		var curIndx = $NewsDates.filter('.cur').index() || 0;
		var newsLength = $NewsDates.length;
		var itemWidth = 59;
		
		$NewsDates.bind('click', function(e){
			var $this = $(this);
			var indx = $NewsDates.index(this);
			
			showNewsItem(indx);
			
			return false;
		});
		
		$NextNews.bind('click', function(e){
			if (curIndx + 1 < newsLength) {
				curIndx++;
				showNewsItem(curIndx);
			}
			return false;
		});
		
		$PrevNews.bind('click', function(e){
			if (curIndx > 0) {
				curIndx--;
				showNewsItem(curIndx);
			}
			return false;
		});
		
		function showNewsItem(indx){
			curIndx = indx;
			
			$NewsItems.hide();
			$NewsItems.eq(indx).show();
			
			$NewsDates.removeClass('cur');
			$NewsDates.get(indx).className = 'cur';
			
			upNewsBtns();
		}
		
		function upNewsBtns(){
			if (curIndx == 0) {
				$PrevNews.addClass('prev_hide');
			} else {
				$PrevNews.removeClass('prev_hide');
			}
			if (curIndx == newsLength - 1) {
				$NextNews.addClass('next_hide');
			} else {
				$NextNews.removeClass('next_hide');
			}
			
			if (curIndx < 3) {
				$NewsDatesCont.css({
					left: 0
				});
				return;
			}
			if (curIndx > newsLength - 4) {
				$NewsDatesCont.css({
					left: -itemWidth * (newsLength - 5)
				});
				return;
			}
			
			$NewsDatesCont.css({
				left: -itemWidth * (curIndx - 2)
			});
			
		}
		
	})();
	
	
	(function(){
		
		var $MainLenta = $('.mainPhotoLenta');
		var $MainLentaItems = $MainLenta.find('> *');
		var itemWidth = 641;
		var fullWidth = $MainLentaItems.length * itemWidth + 10;
		var interval;
		if($MainLentaItems.length>1)
		{
		$MainLenta.css({ width:fullWidth });
		interval = setInterval(slidePhoto, 4000);
		
		function slidePhoto(){
			$MainLenta.animate({ left:-itemWidth }, 600, function(){
				$MainLenta.append($MainLentaItems.eq(0)).css({ left:0 });
			});
		}
		}
	})();
	
	
	(function(){
	
		var $images = $('a[rel=manual_photo]');
		$images.somebox();
	
	})();
	
	
	(function(){
		
		var $SelectCategory = $('#sel');
		$SelectCategory.bind('change', function(e){
			var url = $SelectCategory.val();
			window.location = url;
		});
		
	})();
	
	
	(function(){
		
		var $FaqList = $('.faqList');
		var $Question = $('.question');
		
		$Question.each(function(i){
			
			var $this = $(this);
			var $Reply = $this.parent().find('.reply');
			
			$this.bind('click', function(e){
				$Reply.slideToggle(300);
			});
		
		});
		
	})();
	
	
	(function(){
		
		var $ResetForm = $('.reset');
		
		$ResetForm.bind('click', function(e){
			$("input:not(input#fdate), textarea, select").val('').change();
			$("select").val('didnt');
		});
		
	})();
	
	
});

