﻿var gallery_timer = null;

$(function() {
	showImage(_imageIndex);
	gallery_timer = setTimeout(slideShowTick, 10000);
});

function slideShowTick() {
	showNextImage();
	gallery_timer = setTimeout(slideShowTick, 10000);
};

function showImage(index) {
	var preview = $("#gallery_preview");
	
	if (preview.length > 0)
		preview.css({ background: "url(/galleryimage.aspx?f=" + index + "&thumb=1) no-repeat center center" });
};

function showNextImage() {
	showImage(++_imageIndex);
};

function showPreviousImage() {
	showImage(--_imageIndex);
};

function showImageInLightbox(index) {

	if (typeof (index) == "number")
		_imageIndex = index;

	clearTimeout(gallery_timer);
	var lb = $(createLightbox(640, 450, 20, function() {
		gallery_timer = setTimeout(slideShowTick, 10000);
	}, function() {
		lb[0].showLoading();
		showNextImage();
		content.css("display", "none");
		content[0].src = "/galleryimage.aspx?f=" + _imageIndex + "&thumb=0";
	}, function() {
		lb[0].showLoading();
		showPreviousImage();
		content.css("display", "none");
		content[0].src = "/galleryimage.aspx?f=" + _imageIndex + "&thumb=0";
	}));
	
	var content = ($("<img></img>"));

	content.appendTo(lb).css({ width: "640px", height: "426px" })[0].src = "/galleryimage.aspx?f=" + _imageIndex + "&thumb=0";

	content[0].onload = function() {
		content.css("display", "block");
		lb[0].hideLoading();
	};
};
