jQuery(document).ready(function(){
	Shadowbox.init();
	
	
	jQuery('.modernLargeProjectOverview #projectList_large li.gallery').each(
		function() {
		
		
		// setup values
		var imagesDiv = jQuery(this).find('.images');
		var position = 1;
		var whichImgContainer = 1;
		var totalImages = jQuery(this).find('.images li').length;
		// add extra imgContainer and index the first one
		var imgContainer1 = jQuery(this).find('.imgContainer1');
		var imgContainer2 = '<div class ="imgContainer2" style="left: -9999px"><img src="" /></div>';
		jQuery(imgContainer2).insertAfter(imgContainer1);
		// add navigation
		var backButton = '<p class="back"><a href="#">back</a></p>';
		var forwardButton = '<p class="forward"><a href="#">forward</a></p>';
		jQuery(forwardButton).insertAfter(imagesDiv);
		jQuery(backButton).insertAfter(imagesDiv);
		// wire buttons
		jQuery(this).find('p.forward a').click(function () {
			if(position < totalImages) {
				var newPosition = position + 1;
				var bigImgSrc = jQuery(this).parent().parent().find('li:nth-child(' + newPosition + ') a').attr('href');
				if(whichImgContainer == 1)
				{
					var slide2 = jQuery(this).parent().parent().find('.imgContainer2');
					jQuery(slide2).css({ 'opacity' : '0', 'left' : 150 });
					jQuery(this).parent().parent().find('.imgContainer2 img').attr({ 'src' : bigImgSrc });
					jQuery(slide2).animate({
					    opacity: 1,
						left: 0
					  }, 'slow', function() {
						jQuery(this).parent().parent().find('.imgContainer1').css({ 'z-index' : '3', 'opacity' : 0 });
						jQuery(slide2).css({ 'z-index' : 1 });
					  });
					whichImgContainer = 2;
				} else {
					var slide1 = jQuery(this).parent().parent().find('.imgContainer1');
					jQuery(slide1).css({ 'opacity' : '0', 'left' : 150 });
					jQuery(this).parent().parent().find('.imgContainer1 img').attr({ 'src' : bigImgSrc });
					jQuery(slide1).animate({
					    opacity: 1,
						left: 0
					  }, 'slow', function() {
						jQuery(this).parent().parent().find('.imgContainer2').css({ 'z-index' : '3', 'opacity' : 0 });
						jQuery(slide1).css({ 'z-index' : 1 });
					  });
					whichImgContainer = 1;
				}
				position = newPosition;
				if(position == totalImages)
				{
					jQuery(this).parent().css({ 'opacity' : 0 });
					jQuery(this).css({ 'cursor' : 'default' });
				}
				if(position - 1 > 0)
				{
					jQuery(this).parent().parent().find('.back').css({ 'opacity' : 1 });
					jQuery(this).parent().parent().find('.back a').addClass('active');
				}
			}
			return false;
		});
		
		jQuery(this).find('p.back a').click(function () {
			if(position > 1) {
				var newPosition = position - 1;
				var bigImgSrc = jQuery(this).parent().parent().find('li:nth-child(' + newPosition + ') a').attr('href');
				if(whichImgContainer == 1)
				{
					var slide2 = jQuery(this).parent().parent().find('.imgContainer2');
					jQuery(slide2).css({ 'opacity' : '0', 'left' : -150 });
					jQuery(this).parent().parent().find('.imgContainer2 img').attr({ 'src' : bigImgSrc });
					jQuery(slide2).animate({
					    opacity: 1,
						left: 0
					  }, 'slow', function() {
						jQuery(this).parent().parent().find('.imgContainer1').css({ 'z-index' : '3', 'opacity' : 0 });
						jQuery(slide2).css({ 'z-index' : 1 });
					  });
					whichImgContainer = 2;
				} else {
					var slide1 = jQuery(this).parent().parent().find('.imgContainer1');
					jQuery(slide1).css({ 'opacity' : '0', 'left' : - 150 });
					jQuery(this).parent().parent().find('.imgContainer1 img').attr({ 'src' : bigImgSrc });
					jQuery(slide1).animate({
					    opacity: 1,
						left: 0
					  }, 'slow', function() {
						jQuery(this).parent().parent().find('.imgContainer2').css({ 'z-index' : '3', 'opacity' : 0 });
						jQuery(slide1).css({ 'z-index' : 1 });
					  });
					whichImgContainer = 1;
				}
				position = newPosition;
				if(position == 1)
				{
					//jQuery(this).parent().css({ 'opacity' : 0 });
					jQuery(this).removeClass('active');
				}
				if(position + 1 <= totalImages)
				{
					jQuery(this).parent().parent().find('.forward').css({ 'opacity' : 1 });
					jQuery(this).parent().parent().find('.forward a').css({ 'cursor' : 'pointer' });
				}
			}
			return false;
		});

	});
});
	

function wireButtons() {
	
}
