$(function(){

//Change these to customize slideshow
var currentpic = 1,
	fadespeed = 2000,
	delay = 8000,
	numberofpics = 11,
	fileType = '.jpg';

//DON'T EDIT BELOW THIS POINT
var topimage = $('#topimage'),
	bottomimage = $('#bottomimage'),
	image_title = $('#image_title');

//-----------------------------------Slideshow

//Set starting image
$(topimage).attr({'src':'images/slideshow_images/'+currentpic+fileType});
fade();

function fade(){
	//Calculate next image
	if(currentpic<numberofpics){
		currentpic++;
		}
	else{
		currentpic = 1;
		}
		
	//Call "changeText()" function
	changeText();
	
	//check if top img is visible
	if($(topimage).css('opacity')==1){
		//if top div is NOT visible, change top img to next image
		$(bottomimage).attr({'src':'images/slideshow_images/'+currentpic+fileType});

		$(topimage).delay(delay).animate({'opacity':'0'},fadespeed);
		$(bottomimage).delay(delay).animate({'opacity':'1'},fadespeed,function(){
			fade();
			});		
		
		}
	else{
		//if top img IS visible, change bottom img to next image
		$(topimage).attr({'src':'images/slideshow_images/'+currentpic+fileType});
		
		$(topimage).delay(delay).animate({'opacity':'1'},fadespeed);
		$(bottomimage).delay(delay).animate({'opacity':'0'},fadespeed,function(){
			fade();
			});	
		}
		

	}

//Change text along to match image
function changeText(){
	$(image_title).delay(delay).animate({opacity:0},fadespeed/2,function(){
			$(this).children().css({display:'none'});
			$('#'+currentpic).css({display:'block'});
			$(this).animate({opacity:1},fadespeed/2);
			});
	}
	
	
});
