/**
 * @author The One
 */

$(document).ready(function()
{
	$('.move-left').fadeOut(100);
		
	$('.loading').css({opacity: 0.85});
	
	$('.loading').fadeOut(100);
	
	/*
	 $('.foto-gallery img').each(function(){
		var this_pic = this;
		var this_url = this.src;
		$(this).attr('src','');
		this.onload = function(){
			$(this_pic).parents('li').eq(0).find('.loading').fadeOut(500);
		}
		$(this).attr('src', this_url);
	});*/

	$('.foto-gallery').each(function(){
		$(this).get(0).i = 0;
	})
	
	$('.foto-gallery').each(function()
	{
		var quant = $(this).find('.listalka>li').length;
		$(this).get(0).quantity = quant;
		$(this).append('<i class="counter">'+quant+'</i>');
	});
	
	var quantity = $('.listalka>li').length;
	
	$('.listalka').each(function()
	{
		var current = $(this).parents('.foto-gallery').eq(0);
		var quant = current.get(0).quantity;
		if (quant <= 3) {
			current.find('.move-left').css({opacity: 1}).get(0).className = 'move-l';
			current.find('.move-right').css({opacity: 1}).get(0).className = 'move-r';
		}
		$(this).css({width: quant*140 + 'px'});
	}) 
	
	$('.move-left').click(function(){
		$(this).parent().find('.move-right').fadeIn(100);
		
		$(this).parents('.foto-gallery').get(0).i--;
		var step = -$(this).parents('.foto-gallery').get(0).i*140 + 'px';
		$(this).parents('.foto-gallery').eq(0).find('.listalka').animate({marginLeft: step}, 140);
		
		if ($(this).parents('.foto-gallery').get(0).i == 0) {
			$(this).parents('.foto-gallery').eq(0).find('.move-left').css({display: 'none'});
			return false;
		}
			
	});
	
	$('.move-right').click(function(){
		$(this).parent().find('.move-left').fadeIn(100);
		
		$(this).parents('.foto-gallery').get(0).i++;
		var step = -$(this).parents('.foto-gallery').get(0).i*140 + 'px';
		$(this).parents('.foto-gallery').eq(0).find('.listalka').animate({marginLeft: step}, 140);
		
		if ($(this).parents('.foto-gallery').get(0).i == $(this).parents('.foto-gallery').get(0).quantity-3) {
			$(this).parents('.foto-gallery').eq(0).find('.move-right').css({display: 'none'});
			return false;
		}
			
	});

	$('.thickbox').fancybox({ 
		'zoomSpeedIn': 200, 
		'zoomSpeedOut': 200,
		'frameWidth': 100,
		'frameHeight': 100,
		'overlayShow': true 
	}); 
		
});