// JavaScript Document

var entry_count=0;
var active_entry=0;

var $slideshow_photos, $slideshow_placeholders;

// For slideshow
var t = null;

$(document).ready(function(){
	
	// SLIDESHOW
	
	// Collects all the photos in the main slideshow
	$slideshow_photos = $("#banner img.slideshow_img");
	$slideshow_placeholders = $("#banner img.placeholder");
	// The number of images in the slideshow
	entry_count = $slideshow_photos.length;
	
	$slideshow_photos.hide();
	
	// Automatically advances the main slideshow after an arbitrary period of time
	function advance_slideshow(){
		
		clearTimeout(t);
		next_entry=active_entry<(entry_count-1)?active_entry+1:0;
		
		$slideshow_placeholders.eq(0).fadeOut(500,function(){
			
			$slideshow_placeholders.eq(0).attr('src',$slideshow_photos.eq(next_entry).attr('src'));
			$slideshow_placeholders.eq(0).attr('alt',$slideshow_photos.eq(next_entry).attr('alt'));
			$slideshow_placeholders.eq(0).attr('title',$slideshow_photos.eq(next_entry).attr('title'));
			third_entry=next_entry<(entry_count-1)?next_entry+1:0;
			$slideshow_placeholders.eq(0).show();
			$slideshow_placeholders.eq(1).attr('src',$slideshow_photos.eq(third_entry).attr('src'));
			$slideshow_placeholders.eq(1).attr('alt',$slideshow_photos.eq(third_entry).attr('alt'));
			$slideshow_placeholders.eq(1).attr('title',$slideshow_photos.eq(third_entry).attr('title'));
			active_entry = next_entry;
			t = setTimeout(advance_slideshow, 4000);
			
		});
				
		//return false;
		
	}
	
	t = setTimeout(advance_slideshow, 4000);
	
});
