$(document).ready(function() {
	
	var interval;
	var slideshowSpeed = 4500;
	var activeContainer = 1;	
	var currentImg = 0;
	var currentZindex = 999999;
	slideCopyDeck = ['.onetwo','.twotwo','.threetwo','.fourtwo','.fivetwo','.sixtwo','.seventwo'];

	function animateSlideCopyDeck(){
	if((currentImg != 1)||(currentImg != 15)){
		currentClass = slideCopyDeck[currentImg-1];
		lastClass = slideCopyDeck[currentImg-2]; 			  			
		$(currentClass).fadeIn(function(){
				$(currentClass).animate({opacity:1},2500,'linear')	
		});			
		$(lastClass).fadeOut();
		}
	}


	
	var slideshow = function(){
		
		currentImg++;
		
		if(currentImg > slides.length) {
			currentImg = 1;
		}
		
		var currentContainer = activeContainer;
		
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
 
		showImage(slides[currentImg - 1], currentContainer, activeContainer, currentImg);
		
	};
	
	var showImage = function(photoObject, currentContainer, activeContainer, currentImg){
		
		currentZindex--;
		
		$("#slidecontainer" + activeContainer).css({
			"background-color" : photoObject.hex,
			"background-image" : "url(" + photoObject.image + ")",
			"background-position" : "center top",
			"background-repeat" : "no-repeat",
			"z-index" : currentZindex,
			"display" : "none"
		});


		
		//set new url
		$('a.slide_clickthrough').attr('href', photoObject.url);
		


		//remove active states
		$("#nav1").removeClass('active');
		$("#nav2").removeClass('active');
		$("#nav3").removeClass('active');
		
		//alert(photoObject.image);
		
		{
		$("#slidecontainer" + currentContainer).fadeOut('slow', function() {
			//fade in new container
		    $("#slidecontainer" + activeContainer).fadeIn('slow');
		//show current slide		
		});
		}
		
	};
	
	// Set the first slide
	slideshow();
	
	// Start the slideshow
	interval = setInterval(function() {
		slideshow();
	}, slideshowSpeed);
	
});
