$(function(){
	
		 var browser = navigator.appName;
		  if (browser == "Microsoft Internet Explorer"){
		    var b_version = navigator.appVersion;
		    var re = /\MSIE\s+(\d\.\d\b)/;
		    var res = b_version.match(re);
		    if (res[1] <= 6){
		      (function(){
		    	  var $child = $('.menuTop ul li');
		    	  var $childli = $('.submenu li');
		    			  $child.bind('mouseenter',function(e)
		    					  {
		    					  this.className ='cur hover';
		    			
		    					  }).bind('mouseleave',function(e)
		    						{
		    							this.className='';
		    					    });
		    			  $childli.bind('mouseenter',function(e)
		    					  {
		    					  this.className ='cur2 hover';
		    			
		    					  }).bind('mouseleave',function(e)
		    						{
		    							this.className='';
		    					    });
		      })();
		    }
		  }


	
	
	(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 cal= $('.calendarBlock');
		   cal.calendarLite();
		   var call= $('.ccalendarBlock'); 
		   call.calendarLiteLine();  
    })();
   


   
   (function(){
	   $('.table th:gt(4)').addClass("weekend");
   })();
   
   
	(function(){
		
		var $MenuItems = $('.submenu li');
		$MenuItems.bind('mouseenter', function(e){
			this.addClass('cur2');
			
		}).bind('mouseleave', function(e){
			this.removeClass('cur2');
		});
		
	})();
	
	(function()
	        {
	            var $photoBlock = $('.photoOneBlock');
	            var $lentaBlock = $photoBlock.find('.lentaBlock');
	            var $mainp      = $photoBlock.find('.mainp');
	            var $lentaWrap  = $lentaBlock.find('.lentaWrap');
	            var $lenta      = $lentaWrap.find('.lenta');
	            var preview     = $lenta.find('img');
	            var click = 0;
	            
	            var prev        = $lentaBlock.find('.prev');
	            var next        = $lentaBlock.find('.next');

	            var mainPhoto =  {
	                index : preview.eq(0).attr('src'),
	                iCounter : 0 
	            }
	            
	            preview.not(':first').css('opacity','0.3');
	            
	            preview.click(function()
	            {
	                var $this = $(this);
	                var index = $this.index();
	                var i = 0;
	                var width = 0;
	                while(i!=index)
	                {
	                    width += $(preview.eq(i)).width()+3;
	                    i++;
	                    if((i+4)==preview.length)
	                    {
	                        break;
	                    }
	                } 
	                
	                mainPhoto.src = $this.attr('src');
	                $lenta.animate({left:-width},100,function()
	                {
	                    preview = $lenta.find('img');
	                    var to = $this.index();
	                    if($this.index()!=0)
	                    {
	                        var iC=0;
	                        while(iC!=to)
	                        {
	                            iC++;
	                            preview = $lenta.find('img');
	                            $lenta.append(preview.eq(0)).css({ left:0 });
	                        }
	                    }
	                });
	                preview.animate({opacity:0.3},100).removeClass('cur');
	                $this.animate({opacity:1},100).addClass('cur');

	                changePos()
	            });
	            
	            next.click(function()
	            {
	               var width = $(preview[0]).width();
	               
	               $lenta.animate({left:-width},100,function()
	               {
	                   preview = $lenta.find('img');
	                   preview.animate({opacity:0.3},100).removeClass('cur');
	                   preview.eq(1).animate({opacity:1},100).addClass('cur');
	                   $lenta.append(preview.eq(0)).css({ left:0 });
		               preview = $lenta.find('img');

		               changePos();
	               })
	               mainPhoto.src = preview.eq(1).attr('src');

	            });
	            
	            var bPh = $mainp.find('img');
	            bPh.click(function()
	            {
	               var width = $(preview[0]).width();
	               
	               $lenta.animate({left:-width},100,function()
	               {
	                   preview = $lenta.find('img');
	                   preview.animate({opacity:0.3},100).removeClass('cur');
	                   preview.eq(1).animate({opacity:1},100).addClass('cur');
	                   $lenta.append(preview.eq(0)).css({ left:0 });
		               preview = $lenta.find('img');

		               changePos();
	               })
	               mainPhoto.src = preview.eq(1).attr('src');

	                
	            });
	            
	            prev.click(function()
	            {
	               var l = preview.length;
	               var width = $(preview[l-1]).width();
	               
	               $lenta.animate({left:width},100,function()
	               {
	                   preview = $lenta.find('img');
	                   preview.animate({opacity:0.3},100).removeClass('cur');
	                   $lenta.prepend(preview.eq(l-1)).css({ left:0 });
	                   preview.eq(l-1).animate({opacity:1},100).addClass('cur');
		               preview = $lenta.find('img');
		               
	                   changePos();
	               })
	               mainPhoto.src = preview.eq(l-1).attr('src');

	               
	            });
	            
	            function changePos()
	            {
	                var bigPhoto = $('.mainp img');
	                if(bigPhoto.length>1)
	                {
		                	var src = $lenta.find('.cur').attr('src');
		                	console.log($lenta.find('.cur'));
		                	bigPhoto.fadeOut(100);
		                	$('.mainp img[src="'+src+'"]').fadeIn();

	                }
	                else
	                {
	 	                bigPhoto.fadeOut(100);
		                var splitpath = mainPhoto.src.split('/');
		                var path = '/'+splitpath[1]+'/'+splitpath[2]+'/';
		                var bigimage = splitpath[3].split('_');
		                mainPhoto.src = path+'original_'+bigimage[1];
		                bigPhoto.attr('src',mainPhoto.src).fadeIn(100);
	                	
	                }
	            };
	        })();

	
//	(function(){
//		var $mainb = $('.mainp').find('img');
//		var $lentai = $('.lenta img');
//		var $lenta = $('.lenta');
//		var $lentaBlock = $('.lentaBlock');
//		var $prev = $lentaBlock.find('.prev');
//		var $next  = $lentaBlock.find('.next');
//		var curIndx = $mainb.filter('.cur').index() || 0;
//		var itemWidth = 80 ;		
//		var newsLength = $lentai.length;
//			
//
//			
//			$next.bind('click',function(e){
//				var y =true;
//				if (curIndx + 1 < newsLength) {
//					curIndx++;
//					showNewsItem(curIndx);
//				}
//				return false;
//			});
//			$prev.bind('click',function(e){
//				var y =false;
//				if (curIndx > 0) {
//					curIndx--;
//					showNewsItem(curIndx);
//				}
//				return false;
//			});	
//			
//			
//			
//			function showNewsItem(indx){
//				curIndx = indx;
//				$mainb.hide();
//				$mainb.eq(indx).show();
//				
//
//				
//				upNewsBtns();
//			}
//			
//			function upNewsBtns(){
//				if (curIndx == 0) {
//					$prev.hide()
//				} else {
//					$prev.show()
//				}
//				if (curIndx == (newsLength-1)) {
//					$next.hide();
//				} else {
//					$next.show();
//				}
//				
//				if (curIndx < 4) {
//					$('.lenta').css({
//						left: 0
//					});
//					return;
//				}
//				if (curIndx > newsLength - 4) {
//					$('.lenta').css({
//						left: -itemWidth * (newsLength - 5)
//					});
//					return;
//				}
//				
//				$lentai.css({
//					left: -itemWidth * (curIndx - 2)
//				});
//				
//			}
//
//	})();
	
	(function(){
		var $note = $('.note');
		var $mainb = $('.mainp').find('img').length;
		if($mainb > 0)
		{
		$note.html('' + $mainb + '  photos');
		}
	})();
	
	(function(){
		
		var $ResetForm = $('.ibutton reset');
		
		$ResetForm.bind('click', function(e){
			$("input, textarea").val('').change();
		});
		
	})();

	(function(){
		var block = $('.block2 ul li:last-child');
		var newmain = $('.newsListBlock li:last-child'); 
		block.addClass('last');
		newmain.addClass('last');
	})();
		
});
