$(document).ready(function(){


// sky ---------------------------------

/*	var dfgdg = (function(){
		$('.conteiner_sky_line').animate({'right': '-2200px'}, 40000, function(){
				$('.conteiner_sky_line').css({'right': '0px'});
				dfgdg();
			});
	}); dfgdg(); */

// sky ---------------------------------

/*
// фотогалерея wrap

	$('.foto_this img').wrap('<div class="frame_fg"></div>');
	$('.frame_fg').append('<i class="lt_f"></i><i class="rt_f"></i><i class="rb_f"></i><i class="lb_f"></i>');
	

	// фотогалерея

	NumberPL = 1;
	WFL = 0;
	//$('body').append('<div style="position: fixed; top: 16px; left: 16px; padding: 4px; background: white; color: black;" id="dot"></div>');


	$fot_leng = $('.conteiner_fotos').length;
	for (i=0; i<$fot_leng; i++) {

		lenThisFotos = $('.conteiner_fotos').eq(i).find('.foto_this').length;
		for (b=0; b<lenThisFotos; b++){
			WidthFotosLine = $('.conteiner_fotos:eq('+i+') .foto_this:eq('+b+')').innerWidth();
			WFL = WidthFotosLine + WFL;
		}
		$('.conteiner_fotos').eq(i).append('<div class="width_this_line" style="display: none; position: absolute; top: 0; left: 0; padding: 4px;">'+ WFL +'</div>');
		WFL = 0;

		$('.conteiner_fotos').append('<i class="left_shirma"></i><i class="right_shirma"></i>')

		if (Number($('.foto_gallery').eq(i).find('.width_this_line').html()) <= $('.conteiner_fotos').eq(i).innerWidth()){
			//alert(i);
			$('.foto_gallery').eq(i).find('.right_ar').addClass('r_n');
			$('.foto_gallery').eq(i).find('.right_ar').removeClass('r_a');
			$('.foto_gallery').eq(i).find('.left_ar').addClass('l_n');
			$('.foto_gallery').eq(i).find('.r_n').removeClass('right_ar');
			$('.foto_gallery').eq(i).find('.l_n').removeClass('left_ar');
			$('.foto_gallery').eq(i).find('.right_shirma').hide();
			
		};
		
	};

	var lefFotoAnimate = function(){
		$CNTN_f = $('.conteiner_fotos').innerWidth();
		$CNTN_f = $CNTN_f*NumberPL;
		ThisLeftPosition = Math.round($this.closest('.foto_gallery').find('.line_fotos').position().left);

		$('#dot').html(ThisLeftPosition-$CNTN_f);
		
		$NumberWL = -Number($this.closest('.foto_gallery').find('.width_this_line').html());
		
		$this.closest('.foto_gallery').find('.left_ar').addClass('l_a');
		$this.closest('.foto_gallery').find('.right_ar').addClass('r_a');
		$this.closest('.foto_gallery').find('.left_shirma').show();
		$this.closest('.foto_gallery').find('.right_shirma').show();
		
		
		if ($NumberWL >= -$CNTN_f) {
			ThisLeftPosition = 0;
			$CNTN_f = 0;
		}else if (ThisLeftPosition-$CNTN_f >= 0 ) {	
			ThisLeftPosition = 0;
			$CNTN_f = 0;
			$this.closest('.foto_gallery').find('.left_ar').removeClass('l_a');
			$this.closest('.foto_gallery').find('.left_shirma').hide();
		} else if ($NumberWL+$CNTN_f+32 >= ThisLeftPosition-$CNTN_f) {
			ThisLeftPosition = $NumberWL+$CNTN_f+32;
			$CNTN_f = 0;
			$this.closest('.foto_gallery').find('.right_ar').removeClass('r_a');
			$this.closest('.foto_gallery').find('.right_shirma').hide();
		};

		$this.closest('.foto_gallery').find('.line_fotos').stop().animate({'left': ThisLeftPosition-($CNTN_f/2) +'px'}, 'fast');
	};

	$('.right_ar').click(function(){
		$this = $(this);
		NumberPL = NumberPL * NumberPL;
		lefFotoAnimate();
	});

	$('.left_ar').click(function(){
		$this = $(this);
		NumberPL = -NumberPL * NumberPL;
		lefFotoAnimate();
	});

*/



var lenObj = $('.objeck_uk').length;
	showObj = 3;
	widthObj = 307;


	var numberObj = 0;
	
	var animate_line = (function(){
			
			$('.line_fotogallery').animate({'left': numberObj * -widthObj}, 500);
			
		});


	var aident_ar = (function(){
			
			$('.left_ar').removeClass('none_active_l');
			$('.right_ar').removeClass('none_active_r');
			
			if (numberObj <= 0) {
					$('.left_ar').addClass('none_active_l');
				} else if (numberObj >= lenObj - showObj){
						$('.right_ar').addClass('none_active_r');
					};
		});
		

	$('.right_ar').click(function(){
			if (numberObj >= lenObj - showObj) {
			} else {
				numberObj = numberObj + 1;
				animate_line();
				aident_ar();
				};
		});

	$('.left_ar').click(function(){
			if (numberObj <= 0) {
			} else {
				numberObj = numberObj - 1;
				animate_line();
				aident_ar();
				};
		});

	aident_ar();





var lenObj2 = imagesGallery.length;
 showObj2 = 3;
 widthObj2 = 130;

 numberList = showObj2-1;

 //iG = imagesGallery.length
 //alert(iG);

 var numberObj2 = 0;
 
 
 for (var nG=0; nG<lenObj2; nG++){
  $('.line_fotogallery2').append('<div class="objeck_uk2"></div>');
 };
 
 
 
 for (var i2nG=0; i2nG<lenObj2; i2nG++){
  $('.objeck_uk2').eq(i2nG).append('<a id="photo" rel="photos" href="'+ imagesGallery[i2nG] +'"><img src="" alt="" /></a>');
 };
 
 
 for (var inG=0; inG<showObj2; inG++){
  $('.objeck_uk2').eq(inG).html('<a id="photo" rel="photos" href="'+ imagesGallery[inG] +'"><img src="'+ imagesGallery[inG] +'" alt="" /></a>');
 };
 
 
 //<div class="objeck_uk2">
 // <a href="/_fish/foto6.jpg"><img src="/_fish/pest-sem.jpg" alt=""></a>
 //</div>
 
 
 
 var animate_line2 = (function(){
   $('.line_fotogallery2').animate({'left': numberObj2 * -widthObj2}, 500);
  });

 var aident_ar2 = (function(){
   
   $('.left_ar2').removeClass('none_active_l2');
   $('.right_ar2').removeClass('none_active_r2');
   
   if (numberObj2 <= 0) {
     $('.left_ar2').addClass('none_active_l2');
    } else if (numberObj2 >= lenObj2 - showObj2){
      $('.right_ar2').addClass('none_active_r2');
     };
  });

 $('.right_ar2').click(function(){
 	
   if (numberObj2 >= lenObj2 - showObj2) {
    } else {
     numberObj2 = numberObj2 + 1;
     animate_line2();
     aident_ar2();
     };
   numberList = numberList + 1;
   
   //alert(numberList);
   
   $('.objeck_uk2:eq('+ numberList +') a').html('<img src="'+ imagesGallery[numberList] +'" alt="" />');
   clickA();
   
  });

 $('.left_ar2').click(function(){
   if (numberObj2 <= 0) {
    } else {
     numberObj2 = numberObj2 - 1;
     animate_line2();
     aident_ar2();
     };

   numberList = numberList - 1;

  });

 aident_ar2();

 //conteiner_temp

 var clickA = function(){
 $('.objeck_uk2 a').click(function(){
   //alert('wef');
   //ImgTemp = $(this).attr('href');
   //$('.conteiner_temp').html('<img src="'+ ImgTemp +'" alt=""/>');
   
   //alert('asc');
   
   //$('head').append('<script type="text/javascript" src="/js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>');
   
   return false; 
  });
 }; clickA();

});


