var rows = 3;
var cols = 3;
var pageCount = 0;
var currPageIdx = 1;
var sDisplay = "";
var prevClick = "javascript:fnGoToPage(-1)";
var nextClick = "javascript:fnGoToPage(1)";						 
var links = new Array();

function drawPages(photos,titles){
	for (iIdx = 0;iIdx < photos.length;iIdx++){
		links[iIdx] = "<a id='lnk" + (Number(iIdx)+1) + "' " + ((iIdx == 0) ? "class='currLink' " : "") + "href='javascript:fnGoToIdx(" + Number(Number(pageCount) + 1) + ")'>" + titles[iIdx] + "</a>";
		for (i=1;i<photos[iIdx].length;i++){
			if ((i % (cols*rows)) == 1){
				pageCount += 1;
				sDisplay = (pageCount == currPageIdx) ? "inline" : "none";
				document.write("<div photoName='" + titles[iIdx] + "' style='display:" + sDisplay + "' id='div" + pageCount + "'><table cellpadding='0' cellspacing='0'>");
			}
			
			if ((i % cols) == 1){
				document.write("<tr>");
			}
	
			var photoProperties = photos[iIdx][i].split("|");
			var thumb = photoProperties[0];
			var photo = photoProperties[1];
			var photoLink = photo;
			
			var width = "";
			var defaultHeight = "";			
			var photoTitle = "";			
			if (photoProperties.length > 2) photoTitle = photoProperties[2];
			if (photoProperties.length > 3) defaultHeight = photoProperties[3];
			if (photoProperties.length > 4) width = photoProperties[4];
			if (photoProperties.length > 5) photoLink = photoProperties[5];
			
			document.write("<td onclick='window.open(\"" + sDir + photoLink + "\",\"_pictures\")' style='vertical-align:top; text-align:center;width:100px; height:100px; background-image:url(images/bg_thumb.png); background-repeat:no-repeat;padding-top:10px;'><a photoLink='" + sDir + photoLink + "' href='" + sDir + photo + "' rel='enlargeimage::mouseover' title='" + photoTitle + "' rev='loadarea' defaultHeight='" + defaultHeight + "' showWidth='" + width + "'><img style='width:75px; height:75px;border:solid 1px #999; ' border='0' src='" + sDir + 'thumb/' + thumb + "'></a></td>")
			
			if ((i % cols) == cols){
				document.write("</tr>");
			}
			
			if ((i % (cols*rows)) == 0 || (i==photos[iIdx].length-1)){
				document.write("</table></div>");
			}
		}
	}

	sHTML = ""
	for (i=0;i<links.length;i++){
		if (i != 0) sHTML += "&nbsp;&nbsp;|&nbsp;&nbsp;";
		sHTML += links[i];
	}
	if ($id('divLinks'))	$id('divLinks').innerHTML = sHTML;
}

function fnGoToIdx(idx){
	currPageIdx = idx-1;
	fnGoToPage(1);
}
function fnGoToPage(idx){
								
	currPageIdx = idx;
	for (i=1;i<=pageCount;i++){
		$id('lnk' + i).className = (i == currPageIdx) ? "currentPageHighlight" : "lnkPage";
		$id('div' + i).style.display = (i == currPageIdx) ? "inline" : "none";
	}
}

function drawFooter(){
	document.write("Page(s):&nbsp;&nbsp;");
	for (i=1;i<=pageCount;i++){
		if (i == currPageIdx){
			document.write('<a id="lnk' + i + '" class="currentPageHighlight" href="javascript:fnGoToPage(' + i + ')">' + i + '</a>');
		}
		else{
			document.write('<a id="lnk' + i + '" class="lnkPage" href="javascript:fnGoToPage(' + i + ')">' + i + '</a>');
		}
		document.write("&nbsp;&nbsp;");
		//<span class="currentPageHighlight">1</span>&nbsp;&nbsp;<a href="1.aspx?page=2">2</a>
	}
}