/*
 * s4bPhotoBook.js: PhotoBook Contol File for S4B Web Site
 */
 


// Number of images per row in Photo Album
var __imageColumns = 3;

// Number of images per page
var __imagesPerPage = 9; 

var __currentImage = 0; // Current Referred Image


//-----------------------------------------------------------------------------------------------

function createThumbnail() {
	if (__images.length == 0) return; // There is no images
	imageRows = Math.ceil(__imagesPerPage / __imageColumns);
	
	imCount = 0; // Counter of images
//	document.write("<div id=\"s4bPhotoBookScreen\">");
	document.write("<h1>"+__AlbumTitle+"</h1>");
	document.write("<table class=\"s4bInnerBoxWidth\" id=\"s4bThumbnail\">");
	for (i = 0; i < imageRows; i++) {
		document.write("<tr>");
		for (j = 0; j < __imageColumns; j++) {
			document.write("<td class=\"s4bThumbnailPhotoCell\" width=\""+ Math.floor(100/__imageColumns)+"%\" id=\"imageCell" + imCount + "\"></td>");
			imCount++;
		}
		document.write("</tr>");
	}

	// Navigation
	document.write("<tr><td class=\"s4bThumbnailNavCell\" colspan=\"" + __imageColumns + "\" id=\"arCell\"></td></tr>");

	document.write("</table>");
//	document.write("</div>");
	
	redrawImages(0);
}

function redrawImages(startImage) {
	if (startImage < 0 || startImage > __images.length) return; // invalid case

	imCount = startImage; // initialize image counter

	for (i = 0; i < __imagesPerPage; i++) {
		imageCell = document.getElementById("imageCell" + i);
		if (imageCell) {
			if (imCount < __images.length) {
				imageCell.innerHTML = "<a href=\"photoalbum/" + __images[imCount] + "\" rel=\"lightbox\" title=\""+__imageTitles[imCount]+"\"><img src=\"photoalbum/s" + __images[imCount] + "\" alt=\""+__imageTitles[imCount]+"\"></a>";
				imCount++;
			} else {
				imageCell.innerHTML = "<img src=\"media/comSoon.png\" alt=\"Coming Soon\">";
//				imageCell.innerHTML = "&nbsp;";
			}		
		}		
	}

	arrowCell = document.getElementById("arCell");
	cellHTML="&nbsp;"; // HTML to be written in the arrowCell

//	alert("arrowCell" + arrowCell);
	
	if (arrowCell) {
		if (imCount <= __imagesPerPage) { // means first page
			cellHTML="<span id=\"s4bThumbnailNavDisabled\" class=\"s4bThumbnailNavigation\">"+__leftArrows+"</span>";
		} else {
			cellHTML="<span id=\"s4bThumbnailNavEnabled\" class=\"s4bThumbnailNavigation\"><a href=\"javascript:redrawImages("+ (startImage - __imagesPerPage)+")\">"+__leftArrows+"</a></span>";
		}		

		cellHTML=cellHTML+Math.ceil(imCount/__imagesPerPage)+" / "+Math.ceil(__images.length/__imagesPerPage);

		if (imCount >= __images.length) { // means last page
			cellHTML=cellHTML+("<span id=\"s4bThumbnailNavDisabled\" class=\"s4bThumbnailNavigation\">"+__rightArrows+"</span>");
		} else {
			cellHTML=cellHTML+("<span id=\"s4bThumbnailNavEnabled\" class=\"s4bThumbnailNavigation\"><a href=\"javascript:redrawImages("+imCount+")\">"+__rightArrows+"</a></span>");
		}
		arrowCell.innerHTML=cellHTML;
	}
	initLightbox();
}

