// JavaScript Document
// Duration slide is shown
var duration = 3500;
var bannerduration = 7000;
var timeout = 3500;
var bannertimeout = 7000;

// Width of slide images
var slideWidth = 553;
var slideHeight = 300;

// Internal variables
var currentSlide = 0;
var nextSlide = 0;
var previousSlide = 0;
var working = false;

// Internal variables
var bannercurrentSlide = 0;
var bannernextSlide = 0;
var bannerpreviousSlide = 0;
var bannerworking = false;

// Tranition to the next slide
function goForward() {
	// Make sure previous transition is complete before proceeding
	if (!working) {
		working = true;
		
		var slides = $$('div.slideContainer');
	
		// Slideshow has just started
		if (currentSlide < 1) currentSlide = 1;
	
		// Set next slide, start over if we are at the end
		if (currentSlide < slides.length) nextSlide = currentSlide+1;
		else nextSlide = 1;

		// Transition to next slide
		if ($('slide'+currentSlide).hasClassName('fade')) {
			// Fade transition		
			$('slide'+currentSlide).setStyle({left:'0px',
										 top:'0px',
										 display:'inline',
										 zIndex:'2'});
		
			$('slide'+nextSlide).setStyle({left:'0px',
										  top:'0px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Appear('slide'+nextSlide);
		
			new Effect.Fade('slide'+currentSlide, {
							afterFinish: function(){
								working = false;} });
		} else if ($('slide'+currentSlide).hasClassName('slide')) {
			// Slide transtion
			$('slide'+currentSlide).setStyle({left:'0px',
											 top:'0px',
											 display:'inline',
											 zIndex:'2'});
		
			$('slide'+nextSlide).setStyle({left:slideWidth+'px',
										  top:'0px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Morph('slide'+currentSlide, {
							 style: {left:'-'+slideWidth+'px'} });
		
			new Effect.Morph('slide'+nextSlide, {
							 style: {left:'0px'},
							 afterFinish: function(){
								 working = false;} });
		} else if ($('slide'+currentSlide).hasClassName('blind')) {
			// Blind transtion
			$('slide'+currentSlide).setStyle({left:'0px',
											 top:'0px',
											 display:'inline',
											 zIndex:'2'});
		
			$('slide'+nextSlide).setStyle({left:'0px',
										  top:slideHeight+'px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Morph('slide'+currentSlide, {
							 style: {top:'-'+slideHeight+'px'} });
		
			new Effect.Morph('slide'+nextSlide, {
							 style: {top:'0px'},
							 afterFinish: function(){
								 working = false;} });
		}

		currentSlide = nextSlide;
		clearTimeout(duration);
		duration = setTimeout('goForward()',timeout);
	}
}

// Transition to the previous slide
function goBack() {
	// Make sure previous transition is complete before proceeding
	if (!working) {
		working = true;	
		
		var slides = $$('div.slideContainer');
	
		// Slideshow has just started
		if (currentSlide < 1) currentSlide = 1;
	
		if (currentSlide == 1) {
			previousSlide = slides.length;
		} else previousSlide = currentSlide-1;

		if ($('slide'+previousSlide).hasClassName('fade')) {
			// Fade transition		
			$('slide'+currentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			$('slide'+previousSlide).setStyle({left:'0px',
											  top:'0px',
											  zIndex:'1'});
		
			new Effect.Fade('slide'+currentSlide);
			
			new Effect.Appear('slide'+previousSlide, {
							  afterFinish: function(){
								  working = false;} });
		
		} else if ($('slide'+previousSlide).hasClassName('slide')) {
			// Slide transtion
			$('slide'+previousSlide).setStyle({left:'-'+slideWidth+'px',
											  top:'0px',
											  display:'inline',
											  zIndex:'1'});
		
			$('slide'+currentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			new Effect.Morph('slide'+previousSlide, {
							 style: {left:'0px'} });
		
			new Effect.Morph('slide'+currentSlide, {
							 style: {left:slideWidth+'px'},
							 afterFinish: function(){
								 working = false;} });
		
		} else if ($('slide'+previousSlide).hasClassName('blind')) {
			// Blind transtion
			$('slide'+previousSlide).setStyle({left:'0px',
											  top:'-'+slideHeight+'px',
											  display:'inline',
											  zIndex:'1'});
		
			$('slide'+currentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			new Effect.Morph('slide'+previousSlide, {
							 style: {top:'0px'} });
		
			new Effect.Morph('slide'+currentSlide, {
							 style: {top:slideHeight+'px'},
							 afterFinish: function(){
								 working = false;} });
		}
	
		currentSlide = previousSlide;
		clearTimeout(duration);
		duration = setTimeout('goForward()',timeout);
	}
}

// Pause slideshow
function pause() {
	clearTimeout(duration);
//	$('pauseButton').hide();
//	$('playButton').show();
}

// Start/Resume slideshow
function play() {
	if (!$('slide1').visible()) Effect.Appear('slide1');
	duration = setTimeout('goForward()',timeout);
//	$('playButton').hide();
//	$('pauseButton').show();
}


/// Banner code

// Tranition to the next slide
function bannergoForward() {
	// Make sure previous transition is complete before proceeding
	if (!bannerworking) {
		bannerworking = true;
		
		var bannerslides = $$('div.bannerslideContainer');
	
		// Slideshow has just started
		if (bannercurrentSlide < 1) bannercurrentSlide = 1;
	
		// Set next slide, start over if we are at the end
		if (bannercurrentSlide < bannerslides.length) bannernextSlide = bannercurrentSlide+1;
		else bannernextSlide = 1;

		// Transition to next slide
		if ($('bannerslide'+bannercurrentSlide).hasClassName('fade')) {
			// Fade transition		
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
										 top:'0px',
										 display:'inline',
										 zIndex:'2'});
		
			$('bannerslide'+bannernextSlide).setStyle({left:'0px',
										  top:'0px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Appear('bannerslide'+bannernextSlide);
		
			new Effect.Fade('bannerslide'+bannercurrentSlide, {
							afterFinish: function(){
								bannerworking = false;} });
		} else if ($('bannerslide'+bannercurrentSlide).hasClassName('bannerslide')) {
			// Slide transtion
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
											 top:'0px',
											 display:'inline',
											 zIndex:'2'});
		
			$('bannerslide'+bannernextSlide).setStyle({left:slideWidth+'px',
										  top:'0px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Morph('bannerslide'+bannercurrentSlide, {
							 style: {left:'-'+slideWidth+'px'} });
		
			new Effect.Morph('bannerslide'+bannernextSlide, {
							 style: {left:'0px'},
							 afterFinish: function(){
								 bannerworking = false;} });
		} else if ($('bannerslide'+bannercurrentSlide).hasClassName('blind')) {
			// Blind transtion
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
											 top:'0px',
											 display:'inline',
											 zIndex:'2'});
		
			$('bannerslide'+bannernextSlide).setStyle({left:'0px',
										  top:slideHeight+'px',
										  display:'inline',
										  zIndex:'1'});
		
			new Effect.Morph('bannerslide'+bannercurrentSlide, {
							 style: {top:'-'+slideHeight+'px'} });
		
			new Effect.Morph('bannerslide'+bannernextSlide, {
							 style: {top:'0px'},
							 afterFinish: function(){
								 bannerworking = false;} });
		}

		bannercurrentSlide = bannernextSlide;
		clearTimeout(bannerduration);
		bannerduration = setTimeout('bannergoForward()',bannertimeout);
	}
}

// Transition to the previous slide
function bannergoBack() {
	// Make sure previous transition is complete before proceeding
	if (!bannerworking) {
		bannerworking = true;	
		
		var bannerslides = $$('div.bannerslideContainer');
	
		// Slideshow has just started
		if (bannercurrentSlide < 1) bannercurrentSlide = 1;
	
		if (currentSlide == 1) {
			bannerpreviousSlide = bannerslides.length;
		} else bannerpreviousSlide = bannercurrentSlide-1;

		if ($('bannerslide'+bannerpreviousSlide).hasClassName('fade')) {
			// Fade transition		
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			$('bannerslide'+pbannerreviousSlide).setStyle({left:'0px',
											  top:'0px',
											  zIndex:'1'});
		
			new Effect.Fade('bannerslide'+bannercurrentSlide);
			
			new Effect.Appear('bannerslide'+bannerpreviousSlide, {
							  afterFinish: function(){
								  bannerworking = false;} });
		
		} else if ($('bannerslide'+bannerpreviousSlide).hasClassName('slide')) {
			// Slide transtion
			$('bannerslide'+bannerpreviousSlide).setStyle({left:'-'+slideWidth+'px',
											  top:'0px',
											  display:'inline',
											  zIndex:'1'});
		
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			new Effect.Morph('bannerslide'+bannerpreviousSlide, {
							 style: {left:'0px'} });
		
			new Effect.Morph('bannerslide'+bannercurrentSlide, {
							 style: {left:slideWidth+'px'},
							 afterFinish: function(){
								 bannerworking = false;} });
		
		} else if ($('bannerslide'+bannerpreviousSlide).hasClassName('blind')) {
			// Blind transtion
			$('bannerslide'+bannerpreviousSlide).setStyle({left:'0px',
											  top:'-'+slideHeight+'px',
											  display:'inline',
											  zIndex:'1'});
		
			$('bannerslide'+bannercurrentSlide).setStyle({left:'0px',
											 top:'0px',
											 zIndex:'2'});
		
			new Effect.Morph('bannerslide'+bannerpreviousSlide, {
							 style: {top:'0px'} });
		
			new Effect.Morph('bannerslide'+bannercurrentSlide, {
							 style: {top:slideHeight+'px'},
							 afterFinish: function(){
								 bannerworking = false;} });
		}
	
		bannercurrentSlide = bannerpreviousSlide;
		clearTimeout(bannerduration);
		bannerduration = setTimeout('bannergoForward()',bannertimeout);
	}
}

// Pause slideshow
function bannerpause() {
	clearTimeout(bannerduration);
//	$('bannerpauseButton').hide();
//	$('bannerplayButton').show();
}

// Start/Resume slideshow
function bannerplay() {
	if (!$('bannerslide1').visible()) Effect.Appear('bannerslide1');
	bannerduration = setTimeout('bannergoForward()',bannertimeout);
//	$('bannerplayButton').hide();
//	$('bannerpauseButton').show();
}
