var imagesAmount = 6;
var currentImage = 1;
var selectedImage = 1;
var selectedRelImage = 1;

jQuery(function() {
	
	$('.thumbnails > img').fadeTo(1000, 0.25, function() {	});
	$('.thumbnails > img#foto1').fadeTo(1000, 1, function() {	});
	
	
	$('.thumbnails > img').click(function () {
	  var alt = $(this).attr('alt');
	  var rel = $(this).attr('rel');
	  $('#foto'+selectedImage).fadeTo(500, 0.25, function() {	});
	  selectedImage = $(this).attr('id').substring(4);
	  $('#foto'+selectedImage).fadeTo(500, 1, function() {	});
		
	  
	  
	  
	  $('#bigFoto'+selectedRelImage).fadeTo(500, 0, function() {
		  $('#bigFoto'+selectedRelImage).css('display', 'none');
		  selectedRelImage = rel;
		  $('#bigFoto'+rel).css('opacity', '0');
		  $('#bigFoto'+rel).css('display', '');
		  
		  $('#ajaxLoader').css('display', '');
		 
		  $('#bigFoto'+rel+' > img').attr('src', base_url+'catalog/page'+page_id+'/big_'+alt).load(function(){
			  $('#ajaxLoader').css('display', 'none');
			  $('#bigFoto'+rel).fadeTo(500, 1, function() {	});
		  });;
		  
		  
//		  $('#bigFoto'+rel).animate({
//				opacity: 1,
//		  }, 500, function() {
//			  
//		  });
		  
		  $('.mainFoto a').lightBox({fixedNavigation:true});
		  
		  
	  });
	  
	  
	  
	  
	  
//      $('#mainFoto').animate({
//			opacity: 0,
//	  }, 500, function() {
//		  $('#mainFoto').attr('src', base_url+'catalog/page'+page_id+'/big_'+rel);
//		  $('#mainFoto').animate({
//				opacity: 1,
//		  }, 500, function() {
//			  
//		  });
//	  });
    });
	
	
	
	
	
	
	
	$(".thumbnails > img").hover(
	  function () {
		  $(this).fadeTo(500, 1, function() {	});
	  },
	  function () {
		  if($(this).attr('id') != 'foto'+selectedImage) {
			  $(this).fadeTo(500, 0.25, function() {	});
		  }
		  
	  }
	);
});

function nextImage() {
	
	
	if(currentImage < imagesAmount - 3) {
		currentImage += 1;
		p = $('#foto'+currentImage);
		var position = p.position();
		
		$('.thumbnails').css('left', -position.left);
		
//		$('.thumbnails').animate({
//			left: -position.left,
//		}, 1000, function() {});
		
	}
}
function prevImage() {
	if(currentImage != 1) {
		currentImage -= 1;
		p = $('#foto'+currentImage);
		var position = p.position();
		
		$('.thumbnails').css('left', -position.left);
		
//		$('.thumbnails').animate({
//			left: -position.left,
//		}, 1000, function() {});
		
	}
}
