
var imageUrl = DATA_MEDURL;

var dimMenu = '#E0E0E0';
var smallMenuSz = "12px";
var largeMenuSz = "16px";

var tables = new Array('lighttable', 'browse', 'linear', 'scatter', 'slide');
// hide all of the views
function makeAllInvisible() {
	for (i=0; i < tables.length ; i++)
	{
		document.getElementById(tables[i]).style.display="none";
		document.getElementById(tables[i]).style.visibility="hidden";
		var menu = document.getElementById(tables[i]+"-menu");
		menu.style.color=dimMenu;
		menu.style.fontSize=smallMenuSz;
	}
}

// make the give view visible
function makeOneVisible(d) {
	document.getElementById(d).style.display="";
	document.getElementById(d).style.visibility="visible";
	var menu = document.getElementById(d+"-menu");
	menu.style.color="white";
	menu.style.fontSize=largeMenuSz;
}

var curview;
var br_last = 0;    // current photo film strip
var lt_last = 0;    // current photo light table
var sl_last= 0;    // current photo slide show
var lt_tableShown = false; // true if the table is being displayed

/**
 * Change to the given view
 * d: name of the view
 * save: true to save the view change to the session asynchronously
 */
function view(d, save) {
	curview = d;
	makeAllInvisible();
	makeOneVisible(d);
	// change the color of the menubar background
	var menubar = document.getElementById('menubar');
	if (d == "lighttable") {
			menubar.style.backgroundColor = "rgb(0, 139, 206)"; // rgb(168, 226, 255)
			if (lt_tableShown)
					setPhotoLinks(-1);
			else
					setPhotoLinks(lt_last);
	}
	else if (d == "browse") {
			menubar.style.backgroundColor="rgb(58,67,55)"; // rgb(157,170,166)
			setPhotoLinks(br_last);
	}
	else if (d == "linear" ) {
			menubar.style.backgroundColor="#EE9C01";
			ln_fetchImages(isBrowserIE6());
			setPhotoLinks(-1);//turn them off
	}
	else if (d == "scatter") {
			menubar.style.backgroundColor="rgb(172,36,2)";
			sc_fetchImages(isBrowserIE6());
			setPhotoLinks(-1); // turn them off
	}
	else if (d == "slide") {
		 menubar.style.backgroundColor="rgb(204,138,0)";  // rgb(255,232,183)
		 setPhotoLinks(sl_last);
	}
	if (save) {
			saveToServer("__viewoverride__", d);
	}
	scrollToMenubar();
	updateLink(curview);
	return false;
}

// switch to the next view
function view_next() {
    if (curview == "lighttable")
        view("browse", true);
    else if (curview == "browse")
        view("linear", true);
    else if (curview == "linear")
        view("scatter", true);
    else if (curview == "scatter")
        view("slide", true);
    else
        view("lighttable", true);
}

// switch to the previous view
function view_prev() {
    if (curview == "lighttable")
        view("slide", true);
    else if (curview == "browse")
        view("lighttable", true);
    else if (curview == "linear")
        view("browse", true);
    else if (curview == "scatter")
        view("linear", true);
    else
        view("scatter", true);

}


// open the full size window
function full(ctrl, index, sharedpeopleid) {
	if (allowShowFullSize) {
		window.open("fullimage.php?id="+obfuscateID(''+images[index][DATA_REQUESTID])+"&i="+sharedpeopleid);
		showFullSizeCount += 1;
		//saveToServer('photo_show_full_sz_count', showFullSizeCount);
		setAllowFull();
	} else {
		var pos = findPos(ctrl);
		var teaser = document.getElementById('teaserMenu2');
		teaser.style.visibility = "visible";
		teaser.style.display="block";
		teaser.style.top = ""+(pos[0])+"px";
		teaser.style.left = ""+(pos[1] - 200)+"px";
	}
	return false;
}

function downloadOrCopyPhoto(control, val, albumId, albumOwnerId, requestId, fname) {
	if (val == 'downloadphoto') {
		downloadPhoto(requestId, fname);
	} else if (val == 'copyphoto') {
		copyPhoto(requestId, fname);
	} else if (val == 'copyalbum') {
		copyAlbum(albumId, albumOwnerId);
	}
	control.value = "";
	return false;
}

function downloadOrCopyVideo(control, val, albumId, albumOwnerId, requestId, fname) {
	if (val == 'copyvideo') {
		copyPhoto(requestId, '');
	} else if (val == 'copyalbum') {
		copyAlbum(albumId, albumOwnerId);
	}
	control.value = "";
	return false;
}

function showDownloadMenu(ctrl, which, isOwnerViewing, requestId, fname, albumId, albumOwnerId) {
	var pos = findPos(ctrl);
	var menu = document.getElementById('downloadMenu');
	var teaser = document.getElementById('teaserMenu');

	if (allowDownload) {
		var downloadphoto = document.getElementById('downloadMenu_downloadphoto');
		var copyphoto = document.getElementById('downloadMenu_copyphoto');
		var copyvideo = document.getElementById('downloadMenu_copyvideo');
		var copyalbum = document.getElementById('downloadMenu_copyalbum');
		if (which == 'photo') {
			downloadphoto.style.visibility="visible";
			downloadphoto.style.display="";
			copyphoto.style.visibility=(isOwnerViewing ? "hidden" : "visible");
			copyphoto.style.display=(isOwnerViewing ? "none": "");
			copyvideo.style.visibility = "hidden";
			copyvideo.style.display="none";
		} else if (which == 'video') {
			downloadphoto.style.visibility="hidden";
			downloadphoto.style.display="none";
			copyphoto.style.visibility="hidden";
			copyphoto.style.display="none";
			copyvideo.style.visibility = (isOwnerViewing ? "hidden" : "visible");
			copyvideo.style.display= (isOwnerViewing ? "none" : "");
		} else {
			downloadphoto.style.visibility="hidden";
			downloadphoto.style.display="none";
			copyphoto.style.visibility="hidden";
			copyphoto.style.display="none";
			copyvideo.style.visibility =  "hidden" ;
			copyvideo.style.display= "none" ;
		}
		copyalbum.style.visibility=(isOwnerViewing ? "hidden" : "visible");
		copyalbum.style.display=(isOwnerViewing ? "none" : "");

		menu.style.visibility = "visible";
		menu.style.display="block";
		menu.style.top = ""+(pos[0])+"px";
		menu.style.left = ""+(pos[1] - 200)+"px";
		teaser.style.visibility = "hidden";
		teaser.style.display="none";

		downloadMenu_photo_fname = fname;
		downloadMenu_photo_requestid = requestId;
		downloadMenu_album_albumId = albumId;
		downloadMenu_album_ownerId = albumOwnerId;
		document.getElementById('downloadMenu_dphoto').href='download.php?id='+requestId+'&f='+fname+"&a="+albumId;
	} else {
		menu.style.visibility = "hidden";
		menu.style.display="none";

		teaser.style.visibility = "visible";
		teaser.style.display="block";
		teaser.style.top = ""+(pos[0])+"px";
		teaser.style.left = ""+(pos[1] - 320)+"px";
	}
}

function hideDownloadMenu() {
	var menu = document.getElementById('downloadMenu');
	var teaser = document.getElementById('teaserMenu');
	var teaser2 = document.getElementById('teaserMenu2');

	menu.style.visibility = "hidden";
	menu.style.display="none";
	teaser.style.visibility = "hidden";
	teaser.style.display="none";
	teaser2.style.visibility = "hidden";
	teaser2.style.display="none";
	return true;
}

// menu bar at the bottom of each image view
function presentationMenuBar(index, showEdit) {
	return "<table width=\"100%\"cellpadding=\"0\" cellspacing=\"0\"><tr>"
							+"<td width=\"8%\">&nbsp;</td>"
							+(imageCount > 0 ? "<td align=\"center\">"
							+(showFullSize ? "<a href=\"#\" onclick=\"return full(this, '"+index+"','"+albumOwnerId+"')\" title=\"Show the photo at it's full size\" ><span class=\"st_text2\"><nobr>Show Full Size</nobr></span></a>&nbsp;&nbsp;&nbsp;" : "")
						  +(showFullSize && showDownload ? "|&nbsp;&nbsp;&nbsp;" : "")
							+(showDownload ? "<a href=\"javascript:void(0);\" onClick=\"showDownloadMenu(this, 'photo', isOwnerViewing, '"+images[index][DATA_REQUESTID]+"', '"+images[index][DATA_FNAME]+"', '"+albumId+"', '"+albumOwnerId+"')\">Download"+(!isOwnerViewing ? " or Copy" : "")+"</a>" : "")
							+ "</td>" : "")
							+(showEdit && (isOwnerViewing || visitorHasEditingRights) ? "<td width=\"8%\" align=\"right\"><a href=\"edit.php?id="+albumId+"&i="+albumOwnerId+"&view_index="+index+"\" class=\"st_text2\"><nobr>Edit Album</nobr></a>&nbsp;&nbsp;</td>" : "<td width=\"8%\">&nbsp;</td>")
							+"</tr></table>";
}

// menu bar at the bottom of each image view
function videoPresentationMenuBar(index, showEdit) {
	return "<table width=\"100%\"cellpadding=\"0\" cellspacing=\"0\"><tr>"
							+"<td width=\"8%\">&nbsp;</td><td align=\"center\">"
							+(showDownload ? "<a href=\"javascript:void(0);\" onClick=\"showDownloadMenu(this, 'video', isOwnerViewing, '"+images[index][DATA_REQUESTID]+"', '"+images[index][DATA_FNAME]+"', '"+albumId+"', '"+albumOwnerId+"')\">Download"+(!isOwnerViewing ? " or Copy" : "")+"</a>" : "")
							+"</td>"
							+(showEdit && (isOwnerViewing || visitorHasEditingRights) ? "<td width=\"8%\" align=\"right\"><a href=\"edit.php?id="+albumId+"&i="+albumOwnerId+"&view_index="+index+"\" class=\"st_text2\"><nobr>Edit Album</nobr></a>&nbsp;&nbsp;</td>" : "<td width=\"8%\">&nbsp;")
							+"</td></tr></table>";
}

// menu bar at the bottom of the  light table view
function lightTableMenuBar(showEdit) {
	return "<table width=\"100%\"><tr>"
                +"<td width=\"8%\">&nbsp;</td><td align=\"center\">"
								+(showDownload ? "<a href=\"javascript:void(0);\" onClick=\"showDownloadMenu(this, 'album', isOwnerViewing, '', '', '"+albumId+"', '"+albumOwnerId+"')\">Download"+(!isOwnerViewing ? " or Copy" : "")+"</a>" : "")
							  +"</td>"
								+(showEdit ? "<td width=\"8%\" align=\"right\"><a href=\"edit.php?id="+albumId+"&i="+albumOwnerId+"\" class=\"st_text2\"><nobr>Edit Album</nobr></a></td></tr>" : "<td width=\"8%\"></td>")
							  +"</table>";
}

// size of the photo display
var imgSizeIndex=1;

// set the size of the displayed photos
function setBigPhotoSize(sz) {
	var small_menu = document.getElementById('small-menu');
	small_menu.style.color=dimMenu;
	small_menu.style.fontSize=smallMenuSz;
	var medium_menu = document.getElementById('medium-menu');
	medium_menu.style.color=dimMenu;
	medium_menu.style.fontSize = smallMenuSz;
	var large_menu = document.getElementById('large-menu');
	large_menu.style.color=dimMenu;
	large_menu.style.fontSize = smallMenuSz;
	if (sz=="large") {
		imageUrl = DATA_LARGEURL;
		large_menu.style.color="white";
		large_menu.style.fontSize = largeMenuSz;
		imgSizeIndex = 2;
	} else if (sz=="medium") {
		imageUrl = DATA_MEDURL;
		medium_menu.style.color="white";
		medium_menu.style.fontSize = largeMenuSz;
		imgSizeIndex = 1;
	} else {
		imageUrl = DATA_SMALLURL;
		small_menu.style.color="white";
		small_menu.style.fontSize = largeMenuSz;
		imgSizeIndex = 0;
	}
	br_show(-1);
	lt_show(-1);
	ln_fetchImages(isBrowserIE6());
	sc_fetchImages(isBrowserIE6());
	sl_show(-1, false); // redisplay
	linearLayout();
	scatterLayout();
	saveToServer('__browsing_size__', sz);
	browse_size = sz;
	return view(curview, false); // refresh
}

function sizeit_next() {
	if (browse_size == "small")
		setBigPhotoSize("medium");
	else if (browse_size == "medium")
		setBigPhotoSize("large");
	else
		setBigPhotoSize("small");
}

function sizeit_prev() {
	if (browse_size == "large")
		setBigPhotoSize("medium");
	else if (browse_size=="medium")
		setBigPhotoSize("small");
	else
		setBigPhotoSize("large");
}

// linear

function linearLayout() {
	var html="";
	var maxWidth = imgsizes[imgSizeIndex][0];
	html += "<table width=\"100%\" cellpadding=\"6\" cellspacing=\"0\" border=\"0\" class=\"presentation\">";
	for (i = 0; i < images.length; i++ )
	{
		var itemhtml = "";
		itemhtml += "<tr><td><table width=\"100%\" cellpadding=\"0\"; cellspacing=\"0\" border=\"0\">";
		itemhtml += "<tr><td align=center>";
		itemhtml += "<DIV class=\"st_text photoTitleBody\" style=\"text-align:center;width:"+maxWidth+"px\">"+images[i][DATA_TITLE]+"</DIV>";
		itemhtml += "</td></tr>";
		itemhtml += "<tr><td align=center>";
		if (images[i][DATA_EMBED]=='')
		{
			itemhtml += "<DIV align=center style=\"height:"+images[i][imageUrl+2]+"\"><IMG id=\"ltd"+i+"\"  border=0></DIV>";
		}
		else {
			itemhtml += "<div align=center>"+images[i][DATA_EMBED]+"</div>";
		}
		itemhtml += "</td></tr>";
		itemhtml += "<tr><td align=center>";
		itemhtml += "<DIV class=\"st_text photoDescrBody\"  style=\"text-align:left;width:"+maxWidth+"px\">"+images[i][DATA_DESCR]+"</DIV>";
		if (images[i][DATA_EMBED] == '') {
			itemhtml += presentationMenuBar(i, true);
		} else {
			itemhtml += videoPresentationMenuBar(i, true);
		}
		itemhtml += "</td></tr>";
		itemhtml += "</table></td></tr>";
		itemhtml += "<tr><td>&nbsp;</td></tr>";
		html += itemhtml;
	}
	html +="</table>";
	document.getElementById('linear').innerHTML = html;
}

// scatter
function scatterLayout() {
	var html = "";
	var maxWidth = imgsizes[imgSizeIndex][0];
	html += "<table width=\"100%\" cellpadding=\"6\" cellspacing=\"0\" border=\"0\"  class=\"presentation\">";
	for (var i = 0; i < images.length; i++ )
	{
		var lastHeight = 0;
		if (i < images.length) {
			var itemhtml="";
			var w = maxWidth;
			itemhtml += "<TR><TD colspan=2 align=\"center\" valign=\"top\">";
			itemhtml += "<DIV class=\"st_text photoTitleBody\" style=\"text-align:center;width:"+w+"px\">"+images[i][DATA_TITLE]+"</DIV>";
			if (images[i][DATA_EMBED] == '') {
				lastHeight = images[i][imageUrl+2];
				itemhtml += "<DIV align=center style=\"height:"+lastHeight+"px\"><IMG id=\"td"+i+"\" border=0 ></DIV>";
			}
			else {
				lastHeight = 300; // est
				itemhtml += "<DIV align=center>"+images[i][DATA_EMBED]+"</DIV>";
			}
			itemhtml += "<DIV class=\"st_text photoDescrBody\" style=\"text-align:left;width:"+w+"px\">"+images[i][DATA_DESCR]+"</DIV>";
			if (images[i][DATA_EMBED]=='') {
				itemhtml += presentationMenuBar(i, true);
			} else {
				itemhtml += videoPresentationMenuBar(i, true);
			}
			itemhtml += "</TD></TR>";
			html += itemhtml;
		}
		i++;
		var added = false;
		if (i < images.length )
		{
			var itemhtml1 = "";
			added=true;
			var t1 = images[i][DATA_TITLE];
			var w1 = maxWidth / (images[i][imageUrl+1] > images[i][imageUrl+2] ? 1.4 : 2);
			//if (images[i][DATA_EMBED] != '')
			//    w1 = maxWidth; // embedded doesn't shrink
			itemhtml1 += "<TR>";

			itemhtml1 += "<TD align=\"center\" valign=\"middle\" width=\"50%\" >";
			itemhtml1 += "<DIV class=\"st_text photoTitleBody\" style=\"text-align:center;width:"+w1+"px\">"+t1+"</DIV>";
			if (images[i][DATA_EMBED] == '')
			{
				if (images[i][imageUrl+1] > images[i][imageUrl+2]) {
						// landscape
						itemhtml1 += "<DIV align=center><IMG id=\"td"+i+"\"  border=0  height=\""+lastHeight/2+"px\"></DIV>";
				} else {
						itemhtml1 += "<DIV align=center><IMG id=\"td"+i+"\"  border=0  height=\""+lastHeight/2+"px\"></DIV>";
				}
			}
			else {
				itemhtml1 += "<DIV align=center>"+images[i][DATA_EMBED]+"</DIV>";
			}
			itemhtml1 += "<DIV class=\"st_text photoDescrBody\" style=\"text-align:left;width:"+w1+"px\">"+images[i][DATA_DESCR]+"</DIV>";
			if (images[i][DATA_EMBED]=='') {
				itemhtml1 += presentationMenuBar(i, false);
			} else {
				itemhtml1 += videoPresentationMenuBar(i, false);
			}
			itemhtml1 += "</TD>";
			html += itemhtml1;
		}
		i++;
		if (i < images.length )
		{
			var itemhtml2="";
			var t2 = images[i][DATA_TITLE];
			var w2 = maxWidth / (images[i][imageUrl+1] > images[i][imageUrl+2] ? 1.4 : 2);
			//if (images[i][DATA_EMBED] != '')
			//    w2 = maxWidth;
			itemhtml2 += "<TD align=\"center\" valign=\"middle\" width=\"50%\" >";
			itemhtml2 += "<DIV  class=\"st_text photoTitleBody\" style=\"text-align:center;width:"+w2+"px\">"+t2+"</DIV>";
			if (images[i][DATA_EMBED]=='')
			{
				if (images[i][imageUrl+1] > images[i][imageUrl+2]) {
						// landscape
						itemhtml2 += "<DIV align=center><IMG id=\"td"+i+"\"  border=0  height=\""+lastHeight/2+"px\"></DIV>";
				} else {
						itemhtml2 += "<DIV align=center><IMG id=\"td"+i+"\"  border=0  height=\""+lastHeight/2+"px\"></DIV>";
				}
			}
			else {
				itemhtml2 += "<DIV align=center>"+images[i][DATA_EMBED]+"</DIV>";
			}
			itemhtml2 += "<DIV class=\"st_text photoDescrBody\" style=\"text-align:left;width:"+w2+"px\">"+images[i][DATA_DESCR]+"</DIV>";
			if (images[i][DATA_EMBED]=='') {
				itemhtml2 += presentationMenuBar(i, false);
			} else {
				itemhtml2 += videoPresentationMenuBar(i, false);
			}
			itemhtml2 += "</TD>";
			html+=itemhtml2;
		}
		else if (added) {
			html += "<TD class=\"st_bg\">&nbsp;</TD>";
		}
		if (added)
		{
			html += "</TR>";
		}
	}
    html += "</table>";
    document.getElementById('scatter').innerHTML=html;
}

var headerPercent = 0; // percentage of the window used by the header
var sz = 15000; // height of fixed display * 100
var br_width=0;
function br_resize() {
	br_width= document.body.clientWidth-adPadding;
	document.getElementById('br_scroller').style.width=""+br_width+"px";
}

function br_show(index) {
	if (index == -1)
		index = br_last;
	br_last=index;
	if (index >= images.length)
		return false;
	var path = images[index][imageUrl];
	var title = images[index][DATA_TITLE];
	if (title =="")
		title = "&nbsp;";
	var description = images[index][DATA_DESCR];
	var embed = images[index][DATA_EMBED];
	var width = images[index][imageUrl+1];
	var height = images[index][imageUrl+2];
	var maxWidth = imgsizes[imgSizeIndex][0];
	var maxHeight = imgsizes[imgSizeIndex][1];
	if (embed=='') {
		document.getElementById('br_imagehere').innerHTML="<img id=\"br_image\" src=\""+path+"\" width=\""+width+"px\" height=\""+height+"px\"/>";
		document.getElementById('br_fullhere').innerHTML=presentationMenuBar(index, true);
		document.getElementById('br_imagehere').style.width=""+maxWidth+"px";
		document.getElementById('br_imagehere').style.height=""+maxHeight+"px";
	} else {
		document.getElementById('br_imagehere').innerHTML="<div>"+embed+"</div>";
		document.getElementById('br_fullhere').innerHTML=videoPresentationMenuBar(index, true);
	}
	document.getElementById('br_titlehere').innerHTML=(title.length != 0 ? title : "&nbsp");
	document.getElementById('br_titlehere').style.width=""+maxWidth+"px";
	document.getElementById('br_descrhere').innerHTML="<div style=\"text-align:left;width:"+maxWidth+"px\">"+(description.length != 0 ? description : "&nbsp;")+"</div>";
    //document.getElementById('br_descrhere').style.width=maxWidth;
	if ((index+1) < images.length) {
			var nextImage = index+1;
			embed = images[nextImage][DATA_EMBED];
			path = images[nextImage][imageUrl];
			if (embed=='') {
					document.getElementById('br_prefetchhere').innerHTML="<img src=\""+path+"\" />";
			} else {
					document.getElementById('br_prefetchhere').innerHTML="<div>"+embed+"</div>";
			}
	}
	br_resize();
	br_highlight(index);
	setPhotoLinks(index);
	return false;
}

function br_next() {
	if (br_last+1 < images.length) {
		br_show(br_last+1);
	}
	return false;
}

function br_prev() {
	if ((br_last-1) >= 0) {
		br_show(br_last-1);
	}
	return false;
}

var thumb_width=128;
function br_highlight(index) {
	for (i = 0; i < images.length; i++) {
		document.getElementById('br_'+i).style.border=(i==index ? "2px solid white" : "2px solid black");
	}
	var imgstart = index * thumb_width; // where the highlighted image starts
	var scroller = document.getElementById('br_scroller');
	if (imgstart < scroller.scrollLeft) {
		var n = imgstart-thumb_width;
		if (n < 0)
			n=0;
		scroller.scrollLeft = n;
	}
	else if ((imgstart+thumb_width) > (scroller.scrollLeft+br_width)) {
		scroller.scrollLeft = (imgstart+thumb_width+16) -(br_width)  +thumb_width;
	}
}

//<!-- lighttable -->

var recallScrollTop = 0; // remember where we were in the light table

function showTable(scrollBack) {
	var table = document.getElementById('lt_table');
	table.style.visibility = "visible";
	table.style.display="";
	var menu = document.getElementById('lt_menu');
	menu.style.visibility = "visible";
	menu.style.display="";

	var imagediv = document.getElementById('lt_imagediv');
	imagediv.style.visibility = "hidden";
	imagediv.style.display="none";
	setPhotoLinks(-1);
	lt_tableShown = true;
	if (scrollBack)
		scroll(0, recallScrollTop);
	return false;
}

function getScrollTop() {
  var scrOfY=0;
  //var scrOfX=0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    //scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    //scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    //scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

function lt_show(index) {
	if (index == -1) {
		index = lt_last;
	}
	lt_last = index;
	if (index >= images.length) {
		return false;
	}

	var url = images[index][imageUrl];
	var title = images[index][DATA_TITLE];
	var description = images[index][DATA_DESCR];
	var embed = images[index][DATA_EMBED];
	var width = images[index][imageUrl+1];
	var height = images[index][imageUrl+2];
	var maxWidth = imgsizes[imgSizeIndex][0];
	var maxHeight = imgsizes[imgSizeIndex][1];
	if (title == "")
		title = "&nbsp";
	if (description == "")
		description = "&nbsp;";

	recallScrollTop = getScrollTop();
	var table = document.getElementById('lt_table');
	table.style.visibility = "hidden";
	table.style.display="none";
	var menu = document.getElementById('lt_menu');
	menu.style.visibility = "hidden";
	menu.style.display="none";

	var imagediv = document.getElementById('lt_imagediv');
	imagediv.style.visibility = "visible";
	imagediv.style.display="";
	if (embed == '') {
		imagediv.innerHTML="<table width='100%'><tr><td align=center colspan=4><div  onclick=\"return showTable(true);\" class=\"st_text photoTitleBody\" style=\"cursor:pointer;width:"+maxWidth+"px\">"
            +title+"</div></td></tr><tr><td align=\"right\" onclick=\"return showTable(true);\">"
            +"</td><td align=center width=\"1%\"><div class=\"pictureWindow\" style=\"width:"
            +maxWidth+"px;height:"+maxHeight+"px\"><img id=\"lt_image\"src=\""
            +url+"\" title=\"Click here to view the table\" onclick=\"return showTable(true);\" style=\"{cursor:pointer}\" width=\""
            +width+"px\" height=\""+height+"px\"></div></td>"
            +"<td align=left valign=middle onclick=\"return showTable(true);\">"
            +"</td></tr>"
            +"<tr><td align=\"center\" colspan=\"3\"> <div   class=\"st_text photoDescrBody\" style=\"text-align:left;width:"+maxWidth+"px\">"+description+"</div></td></tr>"
            +"<tr><td align=\"center\" colspan=\"3\">"
            + presentationMenuBar(index, true)
            +"</td></tr></table>";
	} else {
		imagediv.innerHTML="<table width='100%'><tr><td align=center colspan=4><span onclick=\"return showTable(true);\"  class=\"st_text photoTitleBody\" style=\"cursor:pointer\";width:"+maxWidth+"px\">"
            +title+"</span></td></tr><tr>"
            +"<td align=center width=\"100%\" onclick=\"return showTable(true);\"><div class=\"pictureWindow\" >"+embed+"</div></td>"
            +"</tr>"
            +"<tr><td align=center colspan=4> <div   class=\"st_text photoDescrBody\" style=\"text-align:left;width:"+maxWidth+"px\">"+description+"</div></td></tr>"
            +"<tr><td align=\"center\" colspan=\"3\">"
            + videoPresentationMenuBar(index, true)
            +"</td></tr></table>";
	}

	if ((index+1) < images.length) {
		var nextImage = index+1;
		embed = images[nextImage][DATA_EMBED];
		path = images[nextImage][imageUrl];
		if (embed=='') {
			document.getElementById('lt_prefetchdiv').innerHTML="<img src=\""+path+"\" />";
		} else {
			document.getElementById('lt_prefetchdiv').innerHTML="<div>"+embed+"</div>";
		}
	}

	if (curview=='lighttable') {
		lt_highlight(index);
		scrollToMenubar();
	}
	setPhotoLinks(index);
	lt_tableShown = false;
	return false;
}

function lt_next() {
    if ((lt_last+1) < images.length) {
        lt_show(lt_last+1);
    }
    return false;
}

function lt_prev() {
    if ((lt_last-1) >= 0) {
        lt_show(lt_last-1);
    }
    return false;
}

// from morrison.ben@gmail.com , http://lists.evolt.org/archive/Week-of-Mon-20070115/187466.html
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ opacity + ");"; //IE
	obj.style.MozOpacity = opacity/100; // Older Mozilla and Firefox
	obj.style.opacity = opacity/100; // standard CSS
}

function fadeOut(id, level){
	setOpacity(document.getElementById(id), level);
	if (level > 0) {
		level = level - transitionPercent;
		setTimeout( "fadeOut('"+id+"', "+level+");", transitionIntervalStep );
	}
}
function fadeIn(id, level){
	setOpacity(document.getElementById(id), level);
	if (level < 100) {
		level = level + transitionPercent;
		setTimeout( "fadeIn('"+id+"', "+level+");", transitionIntervalStep );
	}
}

function findPos(obj) {
	var cleft = 0;
	var ctop = 0;
	if (obj.offsetParent) {
		do {
			cleft += obj.offsetLeft;
			ctop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [ctop,cleft];
}

function transition(fromId, toId) {
	setOpacity(document.getElementById(toId), 0);
	var div1 = document.getElementById(fromId);
	var div2 = document.getElementById(toId);
	var p = findPos(div1);
	div2.style.top = p[0];
	div2.style.left = p[1];
	div2.style.visibility="visible";
	div2.style.display="";
	fadeOut(fromId, 100);
	fadeIn(toId, 0);
}


function lt_highlight(index) {
	setOpacity(document.getElementById('lt_'+index), 50);
}

function showTitle(title) {
	if (document.getElementById('lt_titletext') != null) {
		document.getElementById('lt_titletext').innerHTML=title;
	}
}

var imageSz = 160;

// light table thumb sizes
function setImageSize(which) { 
	var sz = 125;
	var ltmenu_small = document.getElementById("ltmenu-small");
	ltmenu_small.style.color=dimMenu;
	ltmenu_small.style.fontSize = smallMenuSz;
	var ltmenu_medium = document.getElementById("ltmenu-medium");
	ltmenu_medium.style.color=dimMenu;
	ltmenu_medium.style.fontSize = smallMenuSz;
	var ltmenu_large = document.getElementById("ltmenu-large");
	ltmenu_large.style.color=dimMenu;
	ltmenu_large.style.fontSize = smallMenuSz;

	if (which=='small') {
		sz = 110;
		ltmenu_small.style.color="white";
		ltmenu_small.style.fontSize = largeMenuSz;
	} else if (which=='medium') {
		sz = 160;
		ltmenu_medium.style.color="white";
		ltmenu_medium.style.fontSize = largeMenuSz;
	} else if (which=='large') {
		sz = 256;
		ltmenu_large.style.color="white";
		ltmenu_large.style.fontSize = largeMenuSz;
	}
	imageSz = sz;
	lt_resize();
	saveToServer('__lighttable_size__', which);
	lighttable_size = which;
	scrollToMenubar();
	return false;
}

function setImageSizeNext() {
	if (which == "small")
		setImageSize("medium");
	else if (which == "medium")
		setImageSize("large");
}

function setImageSizePref() {
	if (which == "large")
		setImageSize("medium");
	else if (which == "medium")
		setImageSize("small");
}


function lt_resize() {
	var cellWidth = imageSz;
	var proportionalMaxHeight = imgsizethumb[1] * (imageSz / imgsizethumb[0]); // proportional max height for the given width
	var cellHeight = proportionalMaxHeight;
	var content = ""; //<table cellpadding=\"2\" cellspacing=\"2\" border=0 ><tr>";
	//var col = 0;
	var maxLen = 0;
	if (showDecoration) {
			cellWidth += 30;
			if (imageSz == 110) {
					maxLen=14;
					cellHeight += 34;
			} else if (imageSz == 160) {
					maxLen=20;
					cellHeight += 34;
			} else {
					maxLen =30;
					cellHeight += 34;
			}
	}
	for ( i = 0; i < images.length ; i++ )
	{
		var rowcontent = "";
		if (showDecoration) {
				var fulltitle = images[i][DATA_TITLE];
				fulltitle = fulltitle.replace(/\"/g, '&quot;').stripTags(); // no markup in the light table
				fulltitle = fulltitle.replace(/&nbsp;/g, ' ');
				var title = fulltitle;
				if (title.length > maxLen) {
						title = title.substring(0, maxLen)+"...";
				}
				var fulldescr = images[i][DATA_DESCR];
				fulldescr = fulldescr.replace(/\"/g, '&quot;').stripTags(); // no markup in the light table
				fulldescr = fulldescr.replace(/&nbsp;/g, ' ');
				var descr = fulldescr;
				if (descr.length > maxLen) {
						descr = descr.substring(0, maxLen)+"...";
				}

				/*
				if (title.length > 0) {
						fulldescr = fulltitle;
						descr = title;
				}
				title = "<b>"+(i+1)+"</b>";
				fulltitle = "";
				*/
		}
		rowcontent += "<DIV style=\"text-align:center;width:"+cellWidth+"px;height:"+cellHeight+"px;float:left;border: 1px solid silver;margin:1px;background-color:white\">";
		if (showDecoration) {
				rowcontent = rowcontent + "<div align=center   class=\"lighttable_text"+imageSz+"\" title=\""+fulltitle+"\">"+title+"&nbsp;</div>";
		}
		rowcontent = rowcontent + "<div>"; // spacer to generate a fixed width

		if (images[i][DATA_EMBED] == '') {
			var imgWidth = images[i][DATA_THUMBWIDTH];
			if (imgWidth == 0)
					imgWidth = imageSz;
			var imgHeight = images[i][DATA_THUMBHEIGHT];
			if (imgHeight == 0)
					imgHeight = imageSz;
			if (imgWidth > imgHeight) {
					imgHeight = imgHeight * (imageSz / imgWidth);
					imgWidth = imageSz;
					if (imgHeight > imageSz) {
							imgWidth = imgWidth * (imageSz / imgHeight);
							imgHeight = imageSz;
					}
			} else {
					imgWidth = imgWidth * (imageSz / imgHeight);
					imgHeight = imageSz;
					if (imgWidth > imageSz) {
							imgHeight = imgHeight * (imageSz / imgWidth);
							imgWidth = imageSz;
					}
			}
			// if the imageheight is less that the tallest image, add a spacer'
			var spacerHeight = (proportionalMaxHeight - (images[i][DATA_THUMBHEIGHT] * (imageSz / imgsizethumb[0])))/2;
			rowcontent += "<div style=\"height:"+spacerHeight+"px\"></div>";
			rowcontent = rowcontent + "<img id=\"lt_"+i+"\" src=\""+images[i][DATA_THUMBURL]+"\" width=\""+imgWidth+"px\" height=\""+imgHeight+"px\" style='cursor:pointer;border:1px solid sliver'";
		}
		else {
			rowcontent = rowcontent + "<img id=\"lt_"+i+"\" src=\""+images[i][DATA_EMBEDURL]+"\" width=\"110px\" style=\"border:2px solid silver\"";
		}
		rowcontent = rowcontent + " onclick=\"lt_show("+i+")\" ";
		rowcontent = rowcontent + " title=\"Click to view image "+(i+1)+"\" >";
		rowcontent += "</div>";
		if (images[i][DATA_EMBED] != '') {
			rowcontent += "<div><img src=\"/graphics/backgrounds/videobar.jpg\" border=0 /></div>";
		}
		if (showDecoration) {
			rowcontent = rowcontent + "<div align=center  class=\"lighttable_text"+imageSz+"\" title=\""+fulldescr+"\">"+descr+"&nbsp;</div>";
		}
		rowcontent = rowcontent + "</DIV>\n";
		content += rowcontent;
	}
	var menu = lightTableMenuBar(isOwnerViewing || visitorHasEditingRights);

	document.getElementById('lt_imagetable').innerHTML = content;
	document.getElementById('lt_imagetable_menu').innerHTML=menu;
}

//<!-- linear -->

function ln_resize() {
	if (!isBrowserIE6())
		ln_fetchImages(false);
}

function ln_fetchImages(all) {
    if (curview=="linear") {

        var limit = document.body.scrollTop + (document.body.clientHeight*2);
        var progress = 0;
        for (i =0; i < images.length ;i++ )
        {
            var sz = 0;
            if (images[i][DATA_EMBED].length > 0) {
                sz = 250; // guess at the height of a video
            } else {
                sz = parseInt(images[i][(imageUrl+2)])+20; // height of the selected size
            }
            if (all || (progress < limit))
            {
                var img = document.getElementById("ltd"+i);
                if (img != null)
                {
                    img.src = images[i][imageUrl];
                }
            }
            else
                break;
            progress += sz;
        }
    }
}


//<!-- scatter -->

function sc_fetchImages(all) {
    if (curview=="scatter") {
        var limit = document.body.scrollTop + (document.body.clientHeight*2);
        var bottom = 0;
        for (i =0; i < images.length ;i++ )
        {
            var sz = 0;
            if (images[i][DATA_EMBED].length > 0)
                sz = 256;
            else
                sz = parseInt(images[i][imageUrl+2])+20;
            if (all || (bottom < limit))
            {
                var img = document.getElementById("td"+i);
                if (img != null)
                {
                    img.src = images[i][imageUrl];
                }
            }
            bottom += sz;
            i++;
            var sz1=0;
            var sz2=0;
            if (i < images.length)
            {
                sz1 = 0;
                if (images[i][DATA_EMBED].length > 0)
                    sz1 = 256;
                else
                    sz1 = parseInt(images[i][imageUrl+2])+20;
                if (all || (bottom < limit))
                {
                    img = document.getElementById("td"+i);
                    if (img != null)
                    {
                        img.src = images[i][imageUrl];
                    }
                }
            }
            i++;
            if (i < images.length)
            {
                sz2 = 0;
                if (images[i][DATA_EMBED].length > 0)
                    sz2 = 256;
                else
                    sz2 = parseInt(images[i][imageUrl+2])+20;
                if (all || (bottom < limit))
                {
                    img = document.getElementById("td"+i);
                    if (img != null)
                    {
                        img.src = images[i][imageUrl];
                    }
                }
            }
            if (sz1 > sz2)
                sz = sz1;
            else
                sz = sz2;
            bottom += sz/2;
        }
    }
}


//<!-- slide -->
function sl_show(index, trans) {
	if (index == -1)
		index = sl_last;
	var path = images[sl_last][imageUrl];
	var title = images[sl_last][DATA_TITLE];
	var description = images[sl_last][DATA_DESCR];
	var embed = images[sl_last][DATA_EMBED];
	var width = images[sl_last][imageUrl+1];
	var height = images[sl_last][imageUrl+2];
	var maxWidth = imgsizes[imgSizeIndex][0];
	var maxHeight = imgsizes[imgSizeIndex][1];

	if (embed=='')
	{
		if (!trans || document.getElementById('sl_image') == null) {
				var imghere1 = document.getElementById('sl_imagehere');
				imghere1.innerHTML="<img id=\"sl_image\" src=\""+path+"\" width=\""+width+"px\" height=\""+height+"px\" >";
				imghere1.style.width=""+maxWidth+"px";
				imghere1.style.height=""+maxHeight+"px";
		} else {
				var oldpath = document.getElementById('sl_image').src;
				var imghere = document.getElementById('sl_imagehere');
				var imghere2 = document.getElementById('sl_imagehere2');
				var pos = findPos(imghere);
				imghere2.style.visibility="hidden";
				imghere2.innerHTML="<img id=\"sl_image2\"src=\""+oldpath+"\"  >";
				imghere2.style.width=""+maxWidth+"px";
				imghere2.style.height=""+maxHeight+"px";
				imghere2.style.top = pos[0];
				imghere2.style.left = pos[1];
				imghere2.style.visibility="visible";
				imghere2.style.display="";

				imghere.style.visibility="hidden";
				imghere.innerHTML="<img id=\"sl_image\"src=\""+path+"\" width=\""+width+"px\" height=\""+height+"px\" >";
				imghere.style.width=""+maxWidth+"px";
				imghere.style.height=""+maxHeight+"px";
				transition('sl_imagehere2', 'sl_imagehere');
		}
		document.getElementById('sl_fullhere').innerHTML=(sl_timer == null ? presentationMenuBar(sl_last, true): "");
	}
	else {
		document.getElementById('sl_imagehere').innerHTML="<div>"+embed+"</div>";
		document.getElementById('sl_fullhere').innerHTML=(sl_timer == null ? videoPresentationMenuBar(sl_last, true) : "");
	}
	document.getElementById('sl_titlehere').innerHTML= (title.length == 0 ? "&nbsp;" : title);
	document.getElementById('sl_titlehere').style.width=""+maxWidth+"px";
	document.getElementById('sl_descrhere').innerHTML="<div style=\"text-align:left;width:"+maxWidth+"px\">"+(description.length == 0 ? "&nbsp;" : description)+"</div>";
	//document.getElementById('sl_descrhere').style.width=maxWidth;
	if ((index+1) < images.length) {
			var nextImage = index+1;
			embed = images[nextImage][DATA_EMBED];
			path = images[nextImage][imageUrl];
			if (embed=='') {
					document.getElementById('sl_prefetchhere').innerHTML="<img src=\""+path+"\" >";
			} else {
					document.getElementById('sl_prefetchhere').innerHTML="<div>"+embed+"</div>";
			}
	}
	if (curview == "slide") {
			setPhotoLinks(index); // conditional so that slide show in the background doesn't update the photo number
	}
}

function sl_start(index) {
	sl_last = index-1;
	sl_next();
}

function sl_buttons(index) {
    var prevButton = document.getElementById('ltprevbutton');
    var nextButton = document.getElementById('ltnextbutton');
    if (index == 0) {
        prevButton.src = "/graphics/buttons/photo/arrow.left.gold.screen.gif";
    } else {
        prevButton.src = "/graphics/buttons/photo/arrow.left.gold.gif";
    }

    if (index >= (images.length-1)) {
        nextButton.src = "/graphics/buttons/photo/arrow.rt.gold.screen.gif";
    } else {
        nextButton.src  = "/graphics/buttons/photo/arrow.rt.gold.gif";
    }
}

function sl_next() {
	sl_last += 1;
	if (sl_last >= images.length) {
		sl_last=images.length-1;
		return false;
	}
	sl_show(sl_last, true);
	return false;
}

function sl_cycle() {
	sl_last = sl_last+1;
	if (sl_last >= images.length) {
		sl_last=0;
	}
	sl_show(sl_last, true);
	return false;
}

function sl_prev() {
	sl_last = sl_last-1;
	if (sl_last < 0) {
		sl_last=0;
		return false;
	}
	sl_show(sl_last, true);
	return false;
}

var sl_timer=null;
function sl_play(speed, quickcycle) {
	var slstop = document.getElementById('stopslide');
	slstop.style.visibility="visible";
	slstop.style.display="";
	var slstart = document.getElementById('startslide');
	slstart.style.visibility="hidden";
	slstart.style.display="none";
	if (sl_timer != null) {
			clearInterval(sl_timer);
			sl_timer = null;
	}
	sl_timer=setInterval("sl_cycle()", speed);
	if (speed ==slowSlideInterval) {
		transitionPercent = 5;
	} else if (speed == medSlideInterval) {
		transitionPercent = 10;
	} else if (speed == fastSlideInterval) {
		transitionPercent = 15;
	}
	if (quickcycle) {
		sl_cycle();
	}
	document.getElementById('slide_slowmenu').style.fontSize=(speed == slowSlideInterval ? "13px" : "10px");
	document.getElementById('slide_medmenu').style.fontSize=(speed == medSlideInterval ? "13px" : "10px");
	document.getElementById('slide_fastmenu').style.fontSize=(speed == fastSlideInterval ? "13px" : "10px");
	document.getElementById('slideFiller').style.height="1200px";
	scrollToMenubar();
	return false;
}

function sl_stop() {
	clearInterval(sl_timer);
	sl_timer = null;
	sl_show(sl_last, false);
	document.getElementById('slide_slowmenu').style.fontSize= "10px";
	document.getElementById('slide_medmenu').style.fontSize= "10px";
	document.getElementById('slide_fastmenu').style.fontSize=  "10px";
	document.getElementById('slideFiller').style.height="0px";
	var slstop = document.getElementById('stopslide');
	slstop.style.visibility="hidden";
	slstop.style.display="none";
	var slstart = document.getElementById('startslide');
	slstart.style.visibility="visible";
	slstart.style.display="";
	transitionPercent = 15;
	return false;
}

function resize() {
	ln_resize();
	br_resize();
}

function fetch() {
    ln_fetchImages(false);
    sc_fetchImages(false);
}

function fetchAll() {
    ln_fetchImages(true);
    sc_fetchImages(true);
}

function isBrowserIE6() {
    return navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
}

function switchView(next) {
    if (next)
        view_next();
    else
        view_prev();
}

function switchSize(next) {
    if (next)
        sizeit_next();
    else
        sizeit_prev();
}

function updatePhotoControl(index) {
    var photocontrolleft = document.getElementById('photocontrolleft');
    var photocontrolright = document.getElementById('photocontrolright');
    var photonumber = document.getElementById('photonumber');

    if (index == 0) {
        photocontrolleft.src = "/graphics/buttons/photo/arrow.left.black.screen.gif";
    } else {
        photocontrolleft.src = "/graphics/buttons/photo/arrow.left.black.gif";
    }
    if (index >= (images.length-1)) {
        photocontrolright.src = "/graphics/buttons/photo/arrow.rt.black.screen.gif";
    } else {
        photocontrolright.src = "/graphics/buttons/photo/arrow.rt.black.gif";
    }
    photonumber.innerHTML=""+(index+1) + " of "+images.length;
}

function switchPhoto(next) {
    if (curview == "lighttable") {
        if (next)
            lt_next();
        else
            lt_prev();
        updatePhotoControl(lt_last);
    }
    else if (curview== "browse") {
        if (next)
            br_next();
        else
            br_prev();
        updatePhotoControl(br_last);
    }
    else if (curview== "linear" ) {
        //;
    }
    else if (curview == "scatter") {
        //;
    }
    else if (curview == "slide") {
       if (next)
           sl_next();
       else
           sl_prev();
       updatePhotoControl(sl_last);
    }
}


function processArrowKeys(ev) {
    ev = (ev ? ev : ((window.event ? event: null)));
    if (ev != null) {
        if (ev.keyCode == 37) {
            // left arrow
            if (ev.ctrlKey == 1) {
                switchView(false);
                return false;
            }
            else {
                switchPhoto(false);
                return false;
            }
        } else if (ev.keyCode == 39) {
            // right arrow
            if (ev.ctrlKey == 1) {
                switchView(true);
                return false;
            }
            else {
                switchPhoto(true);
                return false;
            }
        } else if (ev.keyCode == 38 && ev.ctrlKey==1) {
            switchSize(true);
            return false;
        } else if (ev.keyCode == 40 && ev.ctrlKey==1) {
            switchSize(false);
            return false;
        }
    }
    return true;
}

function scrollToTop() {
    setTimeout("scroll(0,0);", 100);
}

var skipScrollToTop = true; // first time flag
function scrollToMenubar() {
	if (skipScrollToTop && location.href.endsWith("#comments")) {
		return;
	}
	setTimeout("scroll(0, findPos(document.getElementById('ptop'))[0]);", 150);
}


