﻿function initSlideShow()
{	
	try 
	{
		$("SlidePause").onclick = function () { return PauseSlideShow(); };
		$("SlidePrev").onclick = function () { return PrevSlideShowImage(); };  
		$("SlideNext").onclick = function () { return NextSlideShowImage(); }; 	
		
		try { $("SlideImage1").onclick = function () { return ShowSlideImage(1); }; } catch (ex) { } 	
		try { $("SlideImage2").onclick = function () { return ShowSlideImage(2); }; } catch (ex) { } 	
		try { $("SlideImage3").onclick = function () { return ShowSlideImage(3); }; } catch (ex) { } 	
		try { $("SlideImage4").onclick = function () { return ShowSlideImage(4); }; } catch (ex) { } 	
		try { $("SlideImage5").onclick = function () { return ShowSlideImage(5); }; } catch (ex) { } 	
		try { $("SlideImage6").onclick = function () { return ShowSlideImage(6); }; } catch (ex) { } 	
		try { $("SlideImage7").onclick = function () { return ShowSlideImage(7); }; } catch (ex) { } 
		
		AnimateAutoTimer = setTimeout('AnimateAutoSlideShow()', AutoscrollSpeed);
	} 
	catch (ex) { } 
	
};

var ScrollOrigin = 0; 
var ScrollDestination = 0; 
var ScrollPosition = 0; 
var ScrollSpeed = 0.4; 
var ScrollMaxSpeed = 50; 

var SlideShowPaused = false; 
var CurrentSlideShowImage = 0; 
var MaxSlideShowImages = 1; 
var AutoscrollSpeed = 5000; 
var AnimateAutoTimer = null; 

var SlideShowImageWidth = 300; 

function AnimateSlideShow()
{
	var continueScroll = false;
	
	if ((ScrollPosition < ScrollDestination - 2) || 
		(ScrollPosition > ScrollDestination + 2))
	{
		var diff = (ScrollDestination - ScrollPosition) * ScrollSpeed; 
		
		if (diff > ScrollMaxSpeed)
		{
			diff = ScrollMaxSpeed; 
		}
		else if (diff < -ScrollMaxSpeed)
		{
			diff = -ScrollMaxSpeed; 
		}		
		
		ScrollPosition += diff; 
		continueScroll = true; 
	}
	else 
	{
		ScrollPosition = ScrollDestination; 
	}
	
	try { $("SlideShowPanel").style.marginLeft = ScrollPosition + "px";	} catch (ex) { }  
	
	if (continueScroll == true && SlideShowPaused == false) 
	{
		setTimeout('AnimateSlideShow()', 30);
	}
	else if (SlideShowPaused == false) 
	{
		AnimateAutoTimer = setTimeout('AnimateAutoSlideShow()', AutoscrollSpeed);
	}
	else 
	{
		clearTimeout(AnimateAutoTimer);
	}
}; 

function PauseSlideShow() 
{
	SlideShowPaused = true; 
	
	if (window.event != null)
	{
		window.event.cancelBubble = true;
	}	
	
	clearTimeout(AnimateAutoTimer);
	
	return false; 
};

function AnimateAutoSlideShow() 
{
	NextSlideShowImage(); 		
	
	return false; 
};

function PrevSlideShowImage() 
{	
	clearTimeout(AnimateAutoTimer);
	SlideShowPaused = false; 
	
	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "normal"; } catch (ex) { } 
	
	if (CurrentSlideShowImage > 0) 
	{	
		CurrentSlideShowImage = CurrentSlideShowImage - 1; 
		ScrollDestination = CurrentSlideShowImage * -SlideShowImageWidth; 	
		ScrollOrigin = ScrollDestination; 		
	}
	else 
	{
		CurrentSlideShowImage = MaxSlideShowImages - 1; 
		ScrollDestination = CurrentSlideShowImage * -SlideShowImageWidth; 
		ScrollOrigin = ScrollDestination; 
	}
	
	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "bold"; } catch (ex) { } 
	
	setTimeout('AnimateSlideShow()', 30);
	
	if (window.event != null)
	{
		window.event.cancelBubble = true;
	}	
	
	return false; 
};

function NextSlideShowImage()
{
	clearTimeout(AnimateAutoTimer);
	SlideShowPaused = false; 
	
	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "normal"; } catch (ex) { } 
	
	if (CurrentSlideShowImage < MaxSlideShowImages - 1) 
	{
		CurrentSlideShowImage = CurrentSlideShowImage + 1; 
		ScrollDestination = CurrentSlideShowImage * -SlideShowImageWidth; 	
		ScrollOrigin = ScrollDestination; 		
	}
	else 
	{
		CurrentSlideShowImage = 0; 
		ScrollDestination = 0; 
		ScrollOrigin = ScrollDestination; 
	}
		
	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "bold"; } catch (ex) { } 
	
	setTimeout('AnimateSlideShow()', 30);
	
	if (window.event != null)
	{
		window.event.cancelBubble = true;
	}	
	
	return false; 
};

function ShowSlideImage(image)
{	
	clearTimeout(AnimateAutoTimer);
	SlideShowPaused = false; 
	
	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "normal"; } catch (ex) { } 
	
	CurrentSlideShowImage = image - 1; 	
	ScrollDestination = CurrentSlideShowImage * -SlideShowImageWidth; 	
	ScrollOrigin = ScrollDestination; 		

	try { $("SlideImage" + (CurrentSlideShowImage + 1)).style.fontWeight = "bold"; } catch (ex) { } 
		
	setTimeout('AnimateSlideShow()', 30);
	
	if (window.event != null)
	{
		window.event.cancelBubble = true;
	}	
	
	return false; 
};

addLoadEvent2(initSlideShow); // run initLightbox onLoad

