
/////////////////////////////////////////////////
// CYCLE IMAGES
/////////////////////////////////////////////////

var slide;

function cycleImages(){
	
	var numSlideImages = 0;
	
	$(".project-list-image").hide(0);
	$(".content-box-image-cycle-wrapper img:first").show();
	
	//Get number of slides in slideshow
	var slideImages = $(".content-box-image-cycle-wrapper img");
		numSlideImages = slideImages.length;
		
	if(numSlideImages > 1){ 
		var zIndex = numSlideImages;
		var i = 1;
		var a = 1;
				
		//SET Z-INDEX AND ASSIGN ID'S
		slideImages.each(function(){
			$(this).attr({ 'id' : 'slide-image-' + i });
			zIndex--;
			i++;
		});
			
	   //SLIDE
		slide = setInterval(function()
		{	
			if(a >= numSlideImages){
				a = 1;
			}
			else{
				a++;
			}
			fadeImages(slideImages, a, numSlideImages);
		},2500);
	}
	else{
		slideImages.css({'display':'block'});
	}
}

function fadeImages(slideImages, a, numSlideImages)
{
	slideImages.fadeOut(300);
	$("#slide-image-" + a).fadeIn(1200);
}


$(document).ready(function(){

	

/////////////////////////////////////////////////
// CYCLE IMAGES
/////////////////////////////////////////////////

	$(window).load(function(){
		
		//Recall function on window focus as it is unset (clear interval) on blur to prevent weird tab swithing thingy
		$(window).focus(function(){
			clearInterval(slide);
			cycleImages();
		});
		$(window).blur(function(){
			clearInterval(slide);
		});
	
		$("#project-list-image-group-1").show();

		if($('body').attr('id') == "services" || $('body').attr('id') == "projects" || $('body').attr('id') == "project_list"){
			cycleImages();
		}
		
	
	});
});
			

