var currentSlide = 1;
var prevSlide = 1;
var slideShowTimer;

$(function(){
	slideShowTimer = setInterval("SlideShowincrement()",6000);
	$('.counter a').bind('click', clickMoveSlideShow);
	
});

function clickMoveSlideShow(event){
	var thisObj = $(this);
	var thisObj_SSID = thisObj.attr('slideId');
	currentSlide = thisObj_SSID;
	
	clearInterval(slideShowTimer);
	slideShowTimer = setInterval("SlideShowincrement()", 6000);
	
	getSSContainers();

}
function SlideShowincrement(){
	
	var imgContainerSize = $('img.slideShowImage').length;
	
	
	if(currentSlide != imgContainerSize){
		currentSlide++;
	}else{
		currentSlide = 1;
	}
	getSSContainers();
}

function getSSContainers(){
	var imgContainer = $('img.slideShowImage');
	var textContainer = $('.galleryText');
	var indexter = $('.counter a');
	
	

	
	slideshowRotator(imgContainer = imgContainer, textContainer = textContainer, indexter = indexter);
}

function slideshowRotator(imgContainer, textContainer, indexter){
	
	indexter.each(function(index){
		if($(this).attr('slideId') == currentSlide ){
			$(this).addClass('on');
		}else{
			$(this).removeClass('on');
		}
	});
	
	imgContainer.each(function(index){
		if($(this).attr('slideId') == currentSlide ){
			$(this).fadeIn(1000)
			//$(this).css('z-index', 1).animate({opacity: 1.0}, 500);
			
			textContainer.each(function(index){
				if($(this).attr('slideId') == currentSlide ){
					//$(this).removeClass('hide');
					$(this).delay(1000/2).fadeIn(1000/2);
				}else if($(this).attr('slideId') == prevSlide ){
					//$(this).addClass('hide');
					$(this).fadeOut(1000/2);
				}
			});
			
		}else if($(this).attr('slideId') == prevSlide){
			$(this).fadeOut(1000)
			//$(this).css('z-index', 0).animate({opacity: 0}, 500);
		}
	});
	prevSlide = currentSlide;
}


