// positionNumber = [X, Y]
var pos1 = [335, 180];
var pos2 = [435, 120];
var pos3 = [535, 60];
var pos4 = [635, 0];	
var positions = [pos1, pos2, pos3, pos4];	
var totalPos = positions.length;

// default positions
var default1 = ['slide0',pos1];
var default2 = ['slide1',pos2];
var default3 = ['slide2',pos3];
var default4 = ['slide3',pos4];
var defaults = [default1,default2,default3,default4];


var infoNum = "";

var URLS = ["<a href=\"tuckpointing-masonry/historic-evanston-tuckpointing.php\">View Project</a>","<a href=\"restoration-projects/painted-ladies/painted-lady-house-oak-park.php\">View Project</a>","<a href=\"tuckpointing-masonry/historic-evanston-tuckpointing.php\">View Project</a>","<a href=\"restoration-projects/oldest-italian-restaurant-chicago.php\">View Project</a>",];

//set furthest-back z-index
var backZ = 5;

var i=0;

function setStartPos()
{
	for(i = 0; i < defaults.length; i++ )
	{
		var curPos = (defaults[i][1]);
		var X = curPos[0];
		var Y = curPos[1];
		var id = document.getElementById('slide'+i);
		id.style.left = X + 'px';
		id.style.top = Y + 'px';
	}
}

//does it on click $("a.nexter").click(function(event){	
function swapper(){	
	$(".toProject").fadeOut('slow');		
	$("#slideHolder .slide").each(								  
	function(slideNum){
		
		var slideID = 'slide'+slideNum;
		var thisSlide = document.getElementById(slideID);
		var thisZ = ($(this).css('z-index')) * 1; //makes the z-index an integer
		var curX = thisSlide.offsetLeft;
		var curY = thisSlide.offsetTop;		
		if (curX == pos4[0])
		{
			
			$(this).animate({left: "-=500",top:"+=100"}, 600, function() {
				$(this).css('z-index', backZ);	
			});
			$(this).animate({left: "335",top:"180"}, 600);	
			
			if(slideNum == 0){
				infoNum = 3;
				}
			else {
				infoNum = slideNum - 1;
				}
			var nextSlide = document.getElementById('slide'+infoNum);
			var child = $(nextSlide).children('img');
			var desc = child.attr('title');		
			
			$("a.nexter").animate({ 'top' : '210' }, 'slow');
			$(".toProject").fadeIn('slow', function() {
				$(".toProject").html(URLS[infoNum]);
			});
			
			$("#slideInfo").animate({ 'top' : '250' }, 'slow');
			$("#slideInfo .infoSpace").fadeOut('slow', function(){
			$("#slideInfo .infoSpace").html(desc);
																});
			
		}
		else
		{
			//make sure to wait swapping the z-index when image is above/under the gallery
			$(this).animate({left: "+=100",top:"-=60"}, 'slow', function() { 
				//increase the z-index by one; because it's in a function, will wait until moved to complete
				$(this).css('z-index', (thisZ + 1)); 					  
			});

		}
		
	});
	$("#slideInfo .infoSpace").fadeIn('fast');
	$("#slideInfo").animate({ 'top' : '170' }, 'slow');
	//$("a.nexter").animate({ 'top' : '170' }, 'slow');			
}

//hides everything until everything is loaded
$(window).load(function(){
		setStartPos();
		$("a.nexter").fadeIn('slow');
		$("#slide0").fadeIn('slow');
		$("#slide1").fadeIn('slow');
		$("#slide2").fadeIn('slow');
		$("#slide3").fadeIn('slow');
		$(".toProject").fadeIn('slow');
		$("#slideInfo").animate({ 'top' : '170' }, 'slow');		
		setInterval('swapper()', 5000);
	
});