$(document).ready(function(){
	$('.project').each(function(){
		$('.screenshot:gt(0)', this).wrapAll('<div class="thumbs" />');
		$('.screenshot:gt(0)', this).each(function(){
			$(this).addClass('thumbnail');
			nlctn.bigSrc = $(this).children('img').attr('src');
			nlctn.newSrc = nlctn.bigSrc.replace("Projects/", "Projects/thumbs/");
			$(this).children('img').attr('src', nlctn.newSrc);
		});
	});
	$('.screenshot').click(function(){
		nlctn.swapImage($(this));
		return false;
	});
});

var nlctn = nlctn || {
    settings:{}
};

nlctn.swapImage = function (el) {
	if($(el).hasClass('thumbnail')){
	//console.log($(el));
		nlctn.projectId = $(el).parent().parent().attr('id');
		$('#'+nlctn.projectId+' .screenshot:first').fadeOut(function() {
	    	$('#'+nlctn.projectId+' .screenshot:first').addClass('thumbnail');
			
			nlctn.bigSrc = $('#'+nlctn.projectId+' .screenshot:first img').attr('src');
			nlctn.newSrc = nlctn.bigSrc.replace("Projects/", "Projects/thumbs/");
			$('#'+nlctn.projectId+' .screenshot:first img').attr('src', nlctn.newSrc);
			
			$('#'+nlctn.projectId+' .screenshot:first').appendTo('#'+nlctn.projectId+' .thumbs').fadeIn();
	  	});
	
		$(el).fadeOut(function() {
			$(el).removeClass('thumbnail');
			
			nlctn.bigSrc = $(el).children('img').attr('src');
			nlctn.newSrc = nlctn.bigSrc.replace("Projects/thumbs/", "Projects/");
			$(el).children('img').attr('src', nlctn.newSrc);
			
			$(el).insertBefore('#'+nlctn.projectId+' .thumbs').fadeIn();
		});
	}else{
		//console.log($(el));
		nlctn.projectId = $(el).parent().attr('id');
		$('#'+nlctn.projectId+' .screenshot:first').fadeOut(function() {
	    	$('#'+nlctn.projectId+' .screenshot:first').removeClass('thumbnail');
			
			nlctn.bigSrc = $('#'+nlctn.projectId+' .screenshot:first img').attr('src');
			nlctn.newSrc = nlctn.bigSrc.replace("Projects/thumbs/", "Projects/");
			$('#'+nlctn.projectId+' .screenshot:first img').attr('src', nlctn.newSrc);
			
			$('#'+nlctn.projectId+' .screenshot:first').insertBefore('#'+nlctn.projectId+' .thumbs').fadeIn();
	  	});

		$(el).fadeOut(function() {
			$(el).addClass('thumbnail');

			nlctn.bigSrc = $(el).children('img').attr('src');
			nlctn.newSrc = nlctn.bigSrc.replace("Projects/", "Projects/thumbs/");
			$(el).children('img').attr('src', nlctn.newSrc);

			$(el).appendTo('#'+nlctn.projectId+' .thumbs').fadeIn();
		});
	}
};
