$(document).ready(function(){
	fn_slideShowInitialize();
	fn_BlockCopyAndPaste();
});

function fn_slideShowInitialize(){
	
	$('#slideShow div.img').hide();
	
	slideShowIsBusy = false;
	slideShowCurIndex = 0;
	slideShowCount = $('#slideShow div.img').length;
	slideShowDuration = 1000;
	slideShowInterval = 8000;
	
	fn_slideShowSwap(slideShowCurIndex,true,null);
	
	slideShowTimer = setInterval(
		function(){
			fn_slideShowAutoRun();
		},
		slideShowInterval
	);
	
}

function fn_slideShowAutoRun(){
	if(slideShowCurIndex+1 < slideShowCount){
		slideShowCurIndex++;
	}else{
		slideShowCurIndex = 0;
	}	
	fn_slideShowSwap(slideShowCurIndex,true,null);
}

function fn_slideShowGoTo(index,animate,sender){
	slideShowCurIndex = index-1;
	fn_slideShowSwap(slideShowCurIndex,animate,sender);
	
	clearInterval(slideShowTimer);
	slideShowTimer = setInterval(
		function(){
			fn_slideShowAutoRun();
		},
		slideShowInterval
	);
}

function fn_slideShowSwap(index,animate,sender){

	var curSlide = $('#slideShow div.imgCtn .show');
	var displaySlide = $('#slideShow div.imgCtn .img').eq(index);
	var selectToggle = $('#slideShow div.toggle a').eq(index);

	if(slideShowIsBusy == false){

		slideShowIsBusy = true;

		if(animate==true){
			if(!$(displaySlide).hasClass('show')){
				$(curSlide).fadeOut(slideShowDuration);
				$(displaySlide).fadeIn(
					slideShowDuration,
					function(){
						$(curSlide).removeClass('show');
						$(displaySlide).addClass('show');
						fn_slideShowCallback(index);
					}
				);
			}else{
				fn_slideShowCallback(index);
			}
		}else{
			$(displaySlide).css('display','block').addClass('show');
			fn_slideShowCallback(index);
		};
	}
	$(sender).blur();
	
}

function fn_slideShowCallback(index){
	slideShowIsBusy = false;
	slideShowCurIndex = index;
	var link = $('#slideShow div.imgCtn div').eq(index).find('a').attr('href');
	var selectToggle = $('#slideShow div.toggle a').eq(index);

	$('#slideShow div.toggle a').each(function(){
		$(this).removeClass('selected');
	});
	$(selectToggle).addClass('selected');
	$('#slideShow div.trigger a').attr('href',link);
}
