﻿/* Fader Controls */
var FRAME_SPEED = 50;
var TRANSITION_STEP = 5;
var FULLSIZE_WIDTH = 550;
var FULLSIZE_HEIGHT = 412;

var currentOpacity = 0;
var faderTimer;

var hires = document.getElementById("fullsizeImage");
var overlay = document.getElementById("fullsizeOverlay");


function EnlargePhoto(newThumb) {
	var currentThumb = document.getElementById("currentThumbnail");
	currentThumb.id = "";

	overlay.style.opacity = 0;
	overlay.style.filter = "alpha(opacity=0)";
	overlay.style.visibility = "visible";
	overlay.firstChild.src = newThumb.src.replace("S.jpg", "L.jpg");

	newThumb.id = "currentThumbnail";
	newThumb.scrollIntoView();
	}


function CenterImage(whichImage) {
	whichImage.style.width = "";
	whichImage.style.height = "";

	var width  = whichImage.offsetWidth;
	var height = whichImage.offsetHeight;
	
	if(width > height) {
		whichImage.style.width = FULLSIZE_WIDTH + "px";
		}
	else {
		whichImage.style.height = FULLSIZE_HEIGHT + "px";
		}
	whichImage.style.marginLeft = "-" + Math.ceil(whichImage.offsetWidth / 2) + "px";
	}


function StartFader() {
	CenterImage(overlay.firstChild);
	faderTimer = window.setInterval("FadePhoto()", FRAME_SPEED);
	}

function FadePhoto() {
	if (currentOpacity < 100) {
		currentOpacity += TRANSITION_STEP;
		}
	else {
		hires.src = overlay.firstChild.src;
		hires.style.width = overlay.firstChild.style.width;
		hires.style.height = overlay.firstChild.style.height;
		hires.style.marginLeft = overlay.firstChild.style.marginLeft;
		overlay.style.visibility = "hidden";
		currentOpacity = 0;
		window.clearInterval(faderTimer);
		}
	overlay.style.opacity = Math.min(currentOpacity,99) / 100;
	overlay.style.filter = "alpha(opacity=" + currentOpacity + ")";
	}




/* Slide Show Controls */	
var TRANSITION_PAUSE = 45 * 60;
var slideshowTimer = null;
	
function SlideshowToggle() {
	if(slideshowTimer) {
		document.getElementById("slideshowControls").src = "slideshow_paused.png";
		window.clearInterval(slideshowTimer);
		slideshowTimer = null;
		}
	else {
		SlideshowAdvance();
		document.getElementById("slideshowControls").src = "slideshow_playing.png";
		slideshowTimer = window.setInterval("SlideshowAdvance()", TRANSITION_PAUSE);
		}
	}

function SlideshowAdvance() {
	var nextCell;
	if(nextCell = document.getElementById("currentThumbnail").parentNode.nextSibling) {
		EnlargePhoto(nextCell.firstChild);
		}
	else if(slideshowTimer) {
		SlideshowToggle();
		}
	}
	
function SlideshowRewind() {
	var prevCell;
	if(prevCell = document.getElementById("currentThumbnail").parentNode.previousSibling) {
		EnlargePhoto(prevCell.firstChild);
		}
	}
	
function SlideshowBeginning() {
	var thumbnailCells = document.getElementById("thumbnailViewport").firstChild.firstChild.firstChild;
	EnlargePhoto(thumbnailCells.firstChild.firstChild);
	if(slideshowTimer) {
		SlideshowToggle();
		}
	}

function SlideshowEnd() {
	var thumbnailCells = document.getElementById("thumbnailViewport").firstChild.firstChild.firstChild;
	EnlargePhoto(thumbnailCells.lastChild.firstChild);
	if(slideshowTimer) {
		SlideshowToggle();
		}
	}

function SlideshowShowControls() {
	document.getElementById("slideshowControls").style.display = "block";
	}
	
function SlideshowHideControls() {
	document.getElementById("slideshowControls").style.display = "none";
	}




