var photoList = Array();
var delay = 2000;
var imageFade = 600;
var counter = 2; // we are hard coding first image on the page
var currentImage = 1; //we are hard coding first image on the page
var timer;
var loading = true;
var curLink = 1;
var firstImage = true;


function getSlide(imageID){
	if(!loading){
		clearTimeout(timer);
		currentImage = (imageID-1);
		loadImage();
	}
}

function nextPhoto(){
	if(!loading){
		clearTimeout(timer);
		currentImage++;
		currentImage = currentImage >= photoList.length ? 0 : currentImage;
		loadImage();
	}
}

function prevPhoto(){
	if(!loading){
		clearTimeout(timer);
		currentImage--;
		currentImage = currentImage < 0 ? photoList.length-1 : currentImage;
		loadImage();
	}
}

function loadImage(){
	loading = true;
	var imgSrc = photoList[currentImage];
	if(counter > 3){ counter = 2; $('#jsSlideShow img:first-child').css('z-index','1');  }
	var imgStyle = 'z-index:'+ counter +'; display:none;';
	
	$('<img />').attr('src', imgSrc).attr('style', imgStyle).load(function(){
		$('#homeLink_'+curLink).removeClass('jsSelected');
		$('#homeLink_'+(currentImage+1)).addClass('jsSelected');
		curLink = currentImage+1;
		
		$('#jsSlideShow').prepend($(this));
		
		if(currentImage == 0){
			$(this).click(function(){ 
				$.colorbox({ href:"http://www.youtube.com/embed/CnjFe2x-zTQ?rel=0", iframe:true, innerWidth:640, innerHeight:390});
			});
		}
		$('#jsSlideShow img:first').fadeIn(imageFade,function(){
			
			$('#jsSlideShow img:not(:first-child)').remove();
			counter++;
			loading = false;
			timer = setTimeout(nextPhoto, delay);
		});
	})
}
