// file-bin/js/colony.js

$(document).ready(function() {
	// Array - holds all original positions
	var projectListPositionState = [];
	
	// Give some spacing to the main image
	$('#cnt-greeting img:first').css('margin', '0 0 15px 30px');
	
	// Project thumb cleanup - restrict h/w and remove prefix_1
	$('.prjct_thumb:first').removeClass('prefix_1');
	$('.prjct_thumb img').css({'height': '75px', 'width': '75px'});
	
	$('#img-team img:last').css('margin-left:', '10px');
	
	// Reordering thumbnails
	$('#toggleThumbPosition').click(function(event) {
		event.preventDefault();
		
		var projectList = $('#cnt-projects .projectThumb');
		var listKeys = [0, 1, 2, 3, 4];
		
		// Initialize the states on load
		if (projectListPositionState.length < 1) {
			projectList.each(function(key, item) {
				var tempPos = $(this).position();
				projectListPositionState.push(tempPos.left);
			});
		}
		
		// randomize keys
		listKeys.sort(function() { return 0.5 - Math.random(); })
		//console.log(projectListPositionState);
		//console.log(listKeys);
		
		projectList.each(function(key, item) {
			var movement = projectListPositionState[listKeys[key]] - projectListPositionState[key];
			$(this).stop().animate({"left": movement}, 2000);
		});
	});
	
	// Projects image hover	
	$.each($('.projectThumb .underlay'), function() {
		var splitSource = $(this).attr('src').split('_bw.jpg');
		$(this).before('<img src="' + splitSource[0] + '.jpg" class="overlay" />');
	});
	
	$('.projectThumb a').hover(
		function() {
			$(this).find('.overlay').stop().fadeTo('def', 1.0);
		},
		function() {
			$(this).find('.overlay').stop().fadeTo('def', 0.0);
		}
	);
 });
