//	Updated 9/02/2009
//
// Javascript copyright 2003-2009 by Jay Krause.  All rights reserved.
//
// clib_slideshow.js - common slide show functions
//
//		clibsl_init();
//			in onload="init()" routine
//
//		clibsl_pic(url,w,h,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,altText);
//			to define pictures in <HEAD> section
//
//		clibsl_slideShowHtml();
//			in <BODY> section
//

if (eval('typeof clib_fDumpData') == 'undefined') var clib_fDumpData = false;

if (typeof clibp_newPassCode != 'undefined') {
	clibp_newPassCode(' ', 'cp_getKeystroke(32)');	// SPACE
	clibp_newActionCode(13,'cp_getKeystroke(13)');	// RETURN
	clibp_newActionCode(37,'cp_getKeystroke(37)');	// left-arrow
	clibp_newActionCode(38,'cp_getKeystroke(38)');	// up-arrow
	clibp_newActionCode(39,'cp_getKeystroke(39)');	// right-arrow
	clibp_newActionCode(40,'cp_getKeystroke(40)');	// down-arrow
	}

else if (typeof newPassCode != 'undefined') {
	clib_debugFunction(clib_fLocal);
	newPassCode(' ', 'cp_getKeystroke(32)');	// SPACE
	newActionCode(13,'cp_getKeystroke(13)');	// RETURN
	newActionCode(37,'cp_getKeystroke(37)');	// left-arrow
	newActionCode(38,'cp_getKeystroke(38)');	// up-arrow
	newActionCode(39,'cp_getKeystroke(39)');	// right-arrow
	newActionCode(40,'cp_getKeystroke(40)');	// down-arrow
	}

function cp_getKeystroke(code) {
	if (code == 32) cp_toggle();
	else if ((code == 13) || (code == 39) || (code == 40)) cp_incrementPic(true,code);
	else if ((code == 37) || (code == 38)) cp_incrementPic(false,code);
	}

if (clib_fDumpData) clibdb_register('cp_rgPic','cp_s');
var cp_rgPic = new Array();
var cp_nrgPic = 0;
var cp_copyright = null;
var cp_msInterval = 4000;
var cp_secFade = 1;
var cp_s = new controlStateType();
var cp_wThumbDefault = 72;
var cp_hThumbDefault = 72;
var cp_zoomLabel = "zoom";

function cp_picType(url,w,h,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,altText,copyright,mOutClass,mOverClass,tid,fPng) {
	this.members = 'url,w,h,wImg,hImg,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,copyright,altText,mOutClass,mOverClass,tid,fPng';
	this.url = url;
	this.w = w;
	this.h = h;
	this.wImg = w;
	this.hImg = h;
	this.urlThumb = urlThumb;
	this.wThumb = wThumb;
	this.hThumb = hThumb;
	this.urlZoom = urlZoom;
	this.wZoom = wZoom;
	this.hZoom = hZoom;
	this.title = title;
	this.altText = altText;
	this.copyright = copyright;
	this.subtitle = subtitle;
	this.mOutClass = mOutClass;
	this.mOverClass = mOverClass;
	this.tid = tid;
	this.fPng = fPng;
	}

function controlStateType() {
	this.members = 'fInit,idMainImage,irgImage,msInterval,secFade,fTitles,fZooms,fPaused,fReverse,fNoFade,fDisableFade,';
	this.members += 'fPanelOn,fThumbsOff,fThumbsVertical,wMax,hMax,wThumbMax,hThumbMax,wThumbBottomTotal,hThumbSideTotal,wZoomMax,hZoomMax,';
	this.members += 'fKeepPanelOn,fCloseOnStop,hSlideShow,iLastThumbHL,imageLoc,timerPanel,';
	this.members += 'fPng,clImgM,clImgM_p,clImgT,clImgT_hl,fTitleCaption,statusCallback,slideShowData';
	this.fInit = false;
	this.idMainImage = null;
	this.irgImage = 0;
	this.msInterval = cp_msInterval;
	this.secFade = cp_secFade;
	this.fTitles = false;
	this.fZooms = false;
	this.fPaused = false;
	this.fReverse = false;
	this.fNoFade = false;
	this.fDisableFade = false;
	this.fPanelOn = true;
	this.fThumbsOff = false;
	this.fThumbsVertical = null;
	this.fWrapThumbs = false;
	this.wMax = 0;
	this.hMax = 0;
	this.wThumbMax = 0;
	this.hThumbMax = 0;
	this.wThumbBottomTotal = 0;
	this.hThumbSideTotal = 0;
	this.wZoomMax = 0;
	this.hZoomMax = 0;
	this.fKeepPanelOn = true;
	this.fCloseOnStop = false;
	this.hSlideShow = null;
	this.iLastThumbHL = null;
	this.imageLoc = null;
	this.timerPanel = null;
	this.fPng = false;
	this.clImgM = 'clibsl_clImgM';
	this.clImgM_p = 'clibsl_clImgM_p';
	this.clImgT = 'clibsl_clImgT';
	this.clImgT_hl = 'clibsl_clImgT_hl';
	this.fTitleCaption = false;
	this.fShowSlideStatus = false;
	this.statusCallback = null;
	}

function isPngImage(url) {
	if ((url == null) || (url.length < 4)) return false;
	return (url.substr(url.length - 4,4).toLowerCase() == '.png');
	}

function clibsl_slideShowHtml(divId,tmode,fThumbFilm,lThumbBox,imageLoc,irg,fTitleCaption,cText) {
	var checkNull =			 'divId,tmode,fThumbFilm,lThumbBox,imageLoc,irg,fTitleCaption,cText';
	var rgCN = checkNull.split(',');
	for (var i = 0; i < rgCN.length; i++) eval('if (typeof ' + rgCN[i] + ' == "undefined") ' + rgCN[i] + ' = null;');
	if (cp_rgPic.length == 0) { clib_debugFunction(true,"no pictures"); return; }
	if (isPngImage(cp_rgPic[0].url)) cp_s.fPng = true;
	if (cp_s.fPng) {
		cp_s.fNoFade = true;
		cp_s.fDisableFade = true;
		cp_s.clImgM = 'clibsl_clImgM_png';
		cp_s.clImgM_p = 'clibsl_clImgM_png_p';
		cp_s.clImgT = 'clibsl_clImgT_png';
		cp_s.clImgT_hl = 'clibsl_clImgT_png_hl';
		}
	cp_s.idMainImage = clib_newElementId('imgId');
	if (imageLoc == null) imageLoc = clib_normalizeUrl('/clibimages/');
	cp_s.imageLoc = imageLoc;
	if (typeof irg == 'string') irg = parseInt(irg,10);
	if (typeof irg != 'number') irg = 0;
	if (typeof fTitleCaption != 'boolean') fTitleCaption = true;
	cp_s.fTitleCaption = fTitleCaption;
	if (cText != null) cp_copyright = cText;
	cp_s.fTitles = true;
	if (fThumbFilm) clib_preLoadImages(imageLoc + 'film_left.gif',imageLoc + 'film_right.gif',imageLoc + 'film_top.gif',imageLoc + 'film_bottom.gif');
	var img = cp_rgPic[irg];
	cp_s.irgImage = irg;
	if (tmode == null) tmode = "r";
	else tmode = tmode.charAt(0).toLowerCase();
	if ((tmode != 'l') && (tmode != 'r') && (tmode != 'b') && (tmode != '*')) tmode = '*';
	if (tmode == "*") tmode = (cp_s.hMax > 510) || ((cp_s.hMax/cp_s.hThumbSideTotal) > (cp_s.wMax/cp_s.wThumbBottomTotal)) ? "r" : "b";
	for (var i = 0; i < cp_nrgPic; i++) {
		var p = cp_rgPic[i];
		if (p.wThumb == null) {
			if (tmode == "b") {
				p.wThumb = Math.floor(p.w * (cp_hThumbDefault/p.h));
				p.hThumb = cp_hThumbDefault;
				}
			else {
				p.wThumb = cp_wThumbDefault;
				p.hThumb = Math.floor(p.h * (cp_wThumbDefault/p.w));
				}
			}
		cp_s.wThumbMax = Math.max(cp_s.wThumbMax,p.wThumb);
		cp_s.hThumbMax = Math.max(cp_s.hThumbMax,p.hThumb);
		clib_preLoadImages(cp_rgPic[i].urlThumb);
		}

	function htmlPausePlayZoom() {
		var h = '<div id=clibsl_div_pauseplay_button class=clibsl_class_button onclick="cp_toggle()" onmouseover="cp_pausePlayHL(true)" onmouseout="cp_pausePlayHL(false)">pause</div>';
		h += '<div id=clibsl_div_zoom><p class=clibsl_class_slideTitle style="color:#d82c38;"> </p></div>';
		h += '<div id=clibsl_div_pauseplay_status class=clibsl_class_slideTitle>&nbsp;</div>';
		h += '<div id=clibsl_div_image_status class=clibsl_class_slideTitle>&nbsp;</div>';
		return h;
		}

	function htmlMainImage() {
		var h = '<table align=center border=0 cellpadding=0 cellspacing=0 width=' + wImgBox + ' height=' + hImgBox + '><tr><td valign=middle align=center>';
		// h += '<img src="' + imageLoc + 'blank.gif" width=1 height=' + hImgBox + ' border=0 style="margin:0px;">'; // here for some old IE or netscape bug I don't remember datails.
		// clib_imageHtml(idImg,url,w,h,border,alt,imgClass,imgStyle,imgExtras)
		if (typeof clib_imageHtml != 'undefined') h += clib_imageHtml(cp_s.idMainImage,img.url,img.w,img.h,0,null,cp_s.clImgM, null,'ondblclick="cp_mainPicDblClick()" onclick="cp_mainPicClick();"');
		else h += '<img id="' + cp_s.idMainImage + '" src="' + img.url + '" class=' + cp_s.clImgM + ' width=' + img.w + ' height=' + img.h + ' ondblclick="cp_mainPicDblClick()" onclick="cp_mainPicClick();">';
		h += '</td></tr></table>';
		return h;
		}

	function htmlMainImageCaption() {
		if (fTitleCaption) {
			var h = '<table align=center border=0 cellpadding=0 cellspacing=0 width=' + wImgBox + '><tr>';
			h += '<td width="5%"><p class=clibsl_class_slideTitle>&nbsp;<br>&nbsp;</p></td>';
			h += '<td width="90%" valign=top><div id=clibsl_div_slideTitle><p class=clibsl_class_slideTitle style="color:#d82c38;text-align:justify;">loading...</p></div></td>';
			h += '<td width="5%"><p class=clibsl_class_slideTitle>&nbsp;<br>&nbsp;</p></td>';
			h += '</tr></table>';
			return h;
			}
		else return '&nbsp;';
		}

	function htmlThumbBox() {
		var h = '';
		h += '<div id=id_thumbDiv style="width:' + wThumbBox + 'px;height:' + hThumbBox + 'px;">';
		h += '<table border=0 cellpadding=0 cellspacing=0>';
		if (cp_s.fThumbsVertical) {
			h += '<tr>';
			if (fThumbFilm) {
				h += '<td style="background-image:url(' + "'" + imageLoc + 'film_left.gif' + "'" + ');background-repeat:repeat-y;background-color:#202020;">';
				h += '<img src="' + imageLoc + 'blank.gif" width=10 height=10 border=0 style="margin:0px;"></td>';
				}
			h += '<td align=center' + (fThumbFilm ? ' bgcolor=#202020' : '') + '>';
			for (var i = 0; i < cp_nrgPic; i++) {
				var p = cp_rgPic[i];
				h += '<img id=' + p.tid + ' class=' + cp_s.clImgT + ' alt="' + p.altText + '" ';
				h += 'onmouseover="clibsl_moThm(true,' + i + ')" onmouseout="clibsl_moThm(false,' + i + ')" ';
				h += 'width=' + p.wThumb + ' height=' + p.hThumb + ' border=0 ondblclick="cp_thumbDblClick(' + i + ')" onclick="cp_thumbClick(' + i + ')" src="' + cp_rgPic[i].urlThumb + '"><br>';
				}
			h += '</td>';
			if (fThumbFilm) {
				h += '<td style="background-image:url(' + "'" + imageLoc + 'film_right.gif' + "'" + ');background-repeat:repeat-y;background-color:#202020;">';
				h += '<img src="' + imageLoc + 'blank.gif" width=10 height=10 border=0 style="margin:0px;"></td>';
				}
			h += '</tr>';
			}
		else {
			if (fThumbFilm) {
				h += '<tr><td style="background-image:url(' + "'" + imageLoc + 'film_top.gif' + "'" + ');background-repeat:repeat-x;background-color:#202020;">';
				h += '<img src="' + imageLoc + 'blank.gif" width=10 height=10 border=0 style="margin:0px;"></td></tr>';
				}
			h += '<tr><td align=center' + (fThumbFilm ? ' bgcolor=#202020' : '') + '>';
			for (var i = 0; i < cp_nrgPic; i++) {
				var p = cp_rgPic[i];
				h += '<img id=' + p.tid + ' class=' + cp_s.clImgT + ' alt="' + p.altText + '" ';
				h += 'onmouseover="clibsl_moThm(true,' + i + ')" onmouseout="clibsl_moThm(false,' + i + ')" ';
				h += 'width=' + p.wThumb + ' height=' + p.hThumb + ' border=0 ondblclick="cp_thumbDblClick(' + i + ')" onclick="cp_thumbClick(' + i + ')" src="' + cp_rgPic[i].urlThumb + '">';
				}
			h += '</td></tr>';
			if (fThumbFilm) {
				h += '<tr><td style="background-image:url(' + "'" + imageLoc + 'film_bottom.gif' + "'" + ');background-repeat:repeat-x;background-color:#202020;">';
				h += '<img src="' + imageLoc + 'blank.gif" width=10 height=10 border=0 style="margin:0px;"></td></tr>';
				}
			}
		h += '</table></div>';
		return h;
		}

	function htmlStatusBox() {
		var h = '';
		h += '<table border=0 cellpadding=1 cellspacing=1 width=' + wThumbBox + ' align=center>';
		if (!fTitleCaption) h += '<tr><td align=center><div id=clibsl_div_slideTitle><p class=clibsl_class_slideTitle style="color:#d82c38;">loading...</p></div></td></tr>';
		h += '<tr><td align=center>' + htmlPausePlayZoom() + '</td></tr>';
		h += '</table>';
		return h;
		}

//
// Main Code Section
//
	var html = '';
	if (tmode == "n") {												// no thumbs
		var wImgBox = cp_s.wMax;
		html += '<table align=center border=0 cellpadding=0 cellspacing=0 width=' + (cp_s.wMax) + '><tr>'
		html += '<td align=center>' + htmlMainImage() + '</td>';
		if (fTitleCaption) html += '</tr><tr><td align=center>' + htmlMainImageCaption + '</td>';
		html += '</tr></table>';
		}

	else if (tmode == "r") {										// "right"
		var wThumbBox = cp_s.wThumbMax + 45 + (fThumbFilm ? 20 : 0);
		var hThumbBox = (lThumbBox == null ? cp_s.hMax + 8 : lThumbBox);
		var wImgBox = cp_s.wMax + 20;
		cp_s.fThumbsVertical = true;
		html += '<table align=center border=0 cellpadding=0 cellspacing=0><tr>';
		html += '<td valign=middle align=center width=' + wImgBox + '>' + htmlMainImage() + '</td>';
		html += '<td align=center valign=bottom width=' + wThumbBox + '>' + htmlThumbBox() + '</td>';
		html += '</tr><tr>';
		html += '<td align=center valign=top width=' + wImgBox + '>' + htmlMainImageCaption() + '</td>';
		html += '<td align=center valign=top>' + htmlStatusBox() + '</td>';
		html += '</tr></table>';
		}

	else if (tmode == "l") {										// "right"
		var wThumbBox = cp_s.wThumbMax + 60 + (fThumbFilm ? 20 : 0);
		var hThumbBox = (lThumbBox == null ? cp_s.hMax + 8 : lThumbBox);
		var wImgBox = cp_s.wMax + 20;
		cp_s.fThumbsVertical = true;
		html += '<table align=center border=0 cellpadding=0 cellspacing=0><tr>';
		html += '<td align=center valign=bottom width=' + (cp_s.wThumbMax + 100) + '>' + htmlThumbBox() + '</td>';
		html += '<td valign=middle align=center width=' + wImgBox + '>' + htmlMainImage() + '</td>';
		html += '</tr><tr>';
		html += '<td align=center valign=top>' + htmlStatusBox() + '</td>';
		html += '<td align=center valign=top width=' + wImgBox + '>' + htmlMainImageCaption() + '</td>';
		html += '</tr></table>';
		}

	else if (tmode == "b") {	// thumbs below
		var wThumbBox = Math.max(500,(lThumbBox == null ? cp_s.wMax : lThumbBox));
		var hThumbBox = cp_s.hThumbMax + 60 + (fThumbFilm ? 20 : 0);
		var wImgBox = Math.max(wThumbBox,cp_s.wMax + 20);
		var hImgBox = Math.max(cp_s.hMax + 20);
		cp_s.fThumbsVertical = false;
		html += '<table align=center border=0 cellpadding=0 cellspacing=0 width=' + wImgBox + '>';
		html += '<tr><td align=center width=' + wImgBox + '>' + htmlMainImage() + '</td></tr></table>';
		html += '<table align=center border=0 cellpadding=0 cellspacing=0 width=' + wThumbBox + '>';
		html += '<tr><td align=center>' + htmlMainImageCaption() + '</td></tr>';
		html += '<tr><td align=center><br>' + htmlThumbBox() + '</td></tr>';
		html += '<tr><td align=center>' + htmlStatusBox() + '</td></tr>';
		html += '</table>';
		}

	clib_writeln(html,divId);
	cp_startTestMonitor();
	}

function clibsl_moThm(fOver,iPic) {
	var p = cp_rgPic[iPic];
	clib_changeClass(p.tid,(fOver ? p.mOverClass : p.mOutClass));
	}

function clibsl_pic(url,w,h,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,altText,copyright) {
	var checkNull = 'url,w,h,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,altText,copyright';
	var rgCN = checkNull.split(',');
	for (var i = 0; i < rgCN.length; i++) eval('if (typeof ' + rgCN[i] + ' == "undefined") ' + rgCN[i] + ' = null;');
	if (urlThumb == null) urlThumb = url;
	if (title == null) title = cp_getPicName(url);
	if (altText == null) {
		altText = title;
		if (subtitle != null) altText += ' - ' + subtitle;
		altText = clib_altFromHtml(altText);
		}
	var fPng = 	isPngImage(url);
	var mOutClass =  fPng ? 'clibsl_clImgT_png' : 'clibsl_clImgT';
	var mOverClass = fPng ? 'clibsl_clImgT_png_hl' : 'clibsl_clImgT_hl';
	if (wZoom == "*") wZoom = null;
	if (hZoom == "*") hZoom = null;
	cp_rgPic[cp_nrgPic++] = new cp_picType(url,w,h,urlThumb,wThumb,hThumb,urlZoom,wZoom,hZoom,title,subtitle,altText,copyright,mOutClass,mOverClass,clib_newElementId('thumb'),fPng);
	cp_s.wMax = Math.max(cp_s.wMax,w);
	cp_s.hMax = Math.max(cp_s.hMax,h);
	if (wThumb == null) {
		cp_s.wThumbBottomTotal += Math.floor(w*(cp_hThumbDefault/h)) + 6;
		cp_s.hThumbSideTotal += Math.floor(h*(cp_wThumbDefault/w)) + 6;
		}
	else {
		cp_s.wThumbBottomTotal += wThumb + 6;
		cp_s.hThumbSideTotal += hThumb + 6;
		}
	if (urlZoom != null) cp_s.fZooms = true;
	if (wZoom != null) cp_s.wZoomMax = Math.max(cp_s.wZoomMax,wZoom);
	if (hZoom != null) cp_s.hZoomMax = Math.max(cp_s.hZoomMax,hZoom);
	if (title != null) cp_s.fTitles = true;
	}

function clibsl_init(fPaused,imgBlank) {
	if (cp_rgPic.length == 0) return;
	var checkNull = 'fPaused,imgBlank';
	var rgCN = checkNull.split(',');
	for (var i = 0; i < rgCN.length; i++) eval('if (typeof ' + rgCN[i] + ' == "undefined") ' + rgCN[i] + ' = null;');
	imgBlank = clib_normalizeUrl(imgBlank);
	if (fPaused == null) fPaused = false;
	var fCloseOnStop = false;
	var fPause = false;
	if (fCloseOnStop != null) cp_s.fCloseOnStop = fCloseOnStop;
	cp_s.hSlideShow = 
		clib_slideShow(
			 cp_s.idMainImage
			,cp_rgPic
			,cp_nrgPic
			,cp_s.msInterval
			,(cp_s.fDisableFade ? 0 : cp_s.secFade)
			,false
			,false
			,'cp_showStatus()'
			,cp_rgPic[0].w
			,cp_rgPic[0].h
			,(imgBlank == null ? cp_s.imageLoc + 'white.jpg' : imgBlank)
			);
	if (cp_s.irgImage >= cp_nrgPic) cp_s.irgImage = 0;
	clib_rgSlideShow[cp_s.hSlideShow].irg = cp_s.irgImage;					// tell clib_slideshow routine which pic is showing and its size
	clib_rgSlideShow[cp_s.hSlideShow].wLast = cp_rgPic[cp_s.irgImage].w;
	clib_rgSlideShow[cp_s.hSlideShow].hLast = cp_rgPic[cp_s.irgImage].h;

	cp_s.slideShowData = clib_rgSlideShow[cp_s.hSlideShow];
	if (fPaused) cp_pause();
	cp_showStatus();
	}

function cp_mainPicClick() {
	if (cp_s.slideShowData == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var img = cp_rgPic[cp_s.irgImage];
	if (!cp_s.fPaused) cp_pause();
	else cp_play();
	cp_showStatus();
	}

function cp_mainPicDblClick() {
	if (cp_s.slideShowData == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var img = cp_rgPic[cp_s.irgImage];
	if (!cp_s.fPaused) cp_pause();
	if (img.urlZoom != null) cp_doZoom(cp_s.irgImage);
	cp_showStatus();
	return false;
	}

function cp_toggle() {
	if (cp_s.slideShowData == null) return;
	if ( cp_s.fPaused ) cp_play();
	else cp_pause();
	cp_showStatus();
	}

function cp_incrementPic(f,n) {
	if (cp_s.slideShowData == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var iPic = cp_s.slideShowData.irg + (f ? 1 : -1);
	if (!cp_s.fWrapThumbs && ((iPic >= cp_nrgPic) || (iPic < 0))) return;
	if (iPic >= cp_nrgPic) iPic = 0;
	if (iPic < 0) iPic = cp_nrgPic - 1;
	cp_thumbClick(iPic);
	}

function cp_forceVisibleThumb() {
	if (cp_s.fThumbsVertical == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var iPic = cp_s.irgImage;
	var tid = cp_rgPic[iPic].tid;
	var id_thumb = clib_getElementId(tid);
	var id_div = clib_getElementId('id_thumbDiv');
	if (cp_s.fThumbsVertical) {
		var tH = id_thumb.height;
		var dH = id_div.clientHeight;
		var tOffsetTop = id_thumb.offsetTop;
		var tTargetTop = Math.max(0,Math.floor((dH - tH)/2));
		var scrollTop = Math.max(0, tOffsetTop - tTargetTop);
		id_div.scrollTop = scrollTop;
		}
	else {
		var tW = id_thumb.width;
		var dW = id_div.clientWidth;
		var tOffsetLeft = id_thumb.offsetLeft;
		var tTargetLeft = Math.max(0, Math.floor((dW - tW)/2));
		var scrollLeft = Math.max(0, tOffsetLeft - tTargetLeft);
		id_div.scrollLeft = scrollLeft;
		}
	}

function cp_startTestMonitor() {
	return;
	var id = clib_getElementId('testMsg');
	if (id == null) return;
	setTimeout('cp_showThumbsBoxInfo()',2000);
	}

function cp_showThumbsBoxInfo() {
	if (cp_s.fThumbsVertical == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var id_thumb = clib_getElementId(cp_rgPic[cp_s.irgImage].tid);
	var id_div = clib_getElementId('id_thumbDiv');
	var rgShow = new Array();
	var nrgShow = 0;
	rgShow[nrgShow++] = 'cp_nrgPic';
	rgShow[nrgShow++] = 'cp_rgPic[cp_s.irgImage].tid';
	rgShow[nrgShow++] = 'cp_s.irgImage';
	rgShow[nrgShow++] = 'id_thumb.width';
	rgShow[nrgShow++] = 'id_thumb.height';
	rgShow[nrgShow++] = 'id_thumb.offsetLeft';
	rgShow[nrgShow++] = 'id_thumb.offsetTop';
	rgShow[nrgShow++] = 'id_div.clientWidth';
	rgShow[nrgShow++] = 'id_div.clientHeight';
	rgShow[nrgShow++] = 'id_div.scrollWidth';
	rgShow[nrgShow++] = 'id_div.scrollHeight';
	rgShow[nrgShow++] = 'id_div.scrollTop';

	var rgDim = new Array('clientWidth','','','','scrollLeft','');
	var rgVar = new Array('iPic','tid','tW','tH','tL','tT','','p','range');

	var html = '<table border=1>';
	for (var i = 0; i < nrgShow; i++) html += '<tr><th align=left>' + rgShow[i] + '</th><td>' + eval(rgShow[i]) + '</td></tr>';
	html += '</table>';

	clib_writeln(html,'testMsg');
	setTimeout('cp_showThumbsBoxInfo()',25);
	}

function cp_thumbClick(iPic) {
	if (cp_s.slideShowData == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var img = cp_rgPic[cp_s.irgImage];
	if (!cp_s.fPaused) {
		cp_showPic(iPic);
		cp_pause();
		}
	else if (iPic == cp_s.irgImage) cp_play();
	else cp_showPic(iPic);
	cp_showStatus();
	}

function cp_thumbDblClick(iPic) {
	if (cp_s.slideShowData == null) return;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var img = cp_rgPic[cp_s.irgImage];
	if (!cp_s.fPaused) cp_pause();
	if (iPic != cp_s.irgImage) cp_showPic(iPic);
	if (img.urlZoom != null) cp_doZoom(iPic);
	}

function cp_pause() {
	cp_s.fPaused = true;
	clib_slideShowControl(cp_s.hSlideShow,true,0,0,false,false);
	if (cp_s.slideShowData.fShowingBlank) clib_doSlideShow(cp_s.hSlideShow,cp_s.irgImage);
	clib_changeClass(cp_s.idMainImage,cp_s.clMainImage_pause);	// get around filter bug
	cp_showStatus();
	}

function cp_play() {
	cp_s.fPaused = false;
	clib_changeClass(cp_s.idMainImage,cp_s.clImgM);	// get around filter bug
	clib_slideShowControl(cp_s.hSlideShow,false,cp_s.msInterval,(cp_s.fDisableFade ? 0 : cp_s.secFade),false,false);
	cp_showStatus();
	}

function cp_showPic(iPic) {
	clib_slideShowControl(cp_s.hSlideShow,true,0,0,false,false);
	clib_doSlideShow(cp_s.hSlideShow,iPic);
	cp_showStatus();
	}

var cpx_timerid = null;

function cp_pausePlayHL(fHL) { 	clib_changeClass('clibsl_div_pauseplay_button', 'clibsl_class_button' + (fHL ? 'HL' : '')); }
function cp_zoomHL(fHL) { 	clib_changeClass('clibsl_p_zoom_button', 'clibsl_class_button' + (fHL ? 'HL' : '')); }

function cp_zoomButton(f) {
	var html = '';
	if (f) html += '<p id=clibsl_p_zoom_button class=clibsl_class_button onclick="cp_pause();cp_doZoom(' + cp_s.irgImage + ');" onmouseover="cp_zoomHL(true)" onmouseout="cp_zoomHL(false)">' + cp_zoomLabel + '</p>';
	clib_writeln(html,'clibsl_div_zoom');
	}


function cp_showStatus() {
	if (cp_s.slideShowData == null) {
		if (cpx_timerid == null) cpx_timerid = setTimeout('cp_showStatus()',500);
		return;
		}
	if (cpx_timerid != null) clearTimeout(cpx_timerid);
	cpx_timerid = null;
	cp_s.irgImage = cp_s.slideShowData.irg;
	var p = cp_rgPic[cp_s.irgImage];
	if ((cp_s.iLastThumbHL != null) && (cp_s.iLastThumbHL != cp_s.irgImage)) {
		var pLast = cp_rgPic[cp_s.iLastThumbHL];
		pLast.mOutClass = cp_s.clImgT;
		clib_changeClass(pLast.tid,pLast.mOutClass);
		}
	p.mOutClass = p.mOverClass;
	clib_changeClass(p.tid,p.mOverClass);
	cp_s.iLastThumbHL = cp_s.irgImage;
	clib_writeln((cp_s.fPaused ? 'play' : 'pause'),'clibsl_div_pauseplay_button');
	clib_writeln('<p class=clibsl_class_slideTitle style="color:#d82c38;text-align:center;">' + (cp_s.fPaused ? '(paused)' : '&nbsp;'),'clibsl_div_pauseplay_status');
	clib_writeln(cp_titleHtml(),'clibsl_div_slideTitle');

	cp_zoomButton(p.urlZoom);
//	if (p.urlZoom != null) clib_writeln('<p class=clibsl_class_slideTitle><a href="javascript:cp_pause();cp_doZoom(' + cp_s.irgImage + ');">' + cp_zoomLabel + '</a></p>','clibsl_div_zoom');

	clib_writeln(cp_imageStatusHtml(),'clibsl_div_image_status');
	fMainPicClick = false;
	cp_forceVisibleThumb();
	if (!cp_fLoaded) cpx_timerid = setTimeout('cp_showStatus()',500);
	if (cp_s.statusCallback != null) eval(cp_s.statusCallback);
	}

function cp_doZoom(irgImage) {
	var p = cp_rgPic[irgImage];
	clib_newWindow(p.urlZoom,'_blank');
//	if ((p.wZoom == null) || (p.hZoom == null) || (p.wZoom > cp_s.wMax) || (p.hZoom > cp_s.hMax)) clib_newWindow(p.urlZoom,'_blank');
//	else clib_showPic(p.urlZoom,p.title + (p.subtitle == null ? '' : '<br><font size=-1>' + p.subtitle + '</font>'),p.wZoom,p.hZoom);
	}

function cp_getPicName(url) {
	var rg = url.split("/");			// strip leading folder names
	rg = rg[rg.length-1].split(".");	// strip trailing file extension
	return rg[0];
	}

var cp_fLoaded = false;
function cp_imageStatusHtml() {
	var html = '';
	if (!cp_fLoaded) {
		if (cp_s.slideShowData == null) return '';
		var nLeft = cp_s.slideShowData.rgImg.length;
		for (var i = 0; i < cp_s.slideShowData.rgImg.length; i++) if (cp_s.slideShowData.rgImg[i].image.complete == true) {
			nLeft--;
			cp_rgPic[i].wImg = cp_s.slideShowData.rgImg[i].image.width;
			cp_rgPic[i].hImg = cp_s.slideShowData.rgImg[i].image.height;
			}
		if (nLeft > 0) html += nLeft + ' images to load';
		else cp_fLoaded = true;
		}
	var p = cp_rgPic[cp_s.irgImage];
	if (clib_fLocal && ((p.wImg != p.w) || (p.hImg != p.h))) {
		html += (html == '' ? '' : '<br>');
		html += '(' + p.wImg + ',' + p.hImg + ') actual'
		html += '<br>(' + p.w + ',' + p.h + ') show'
		}
	return html;
	}

function cp_titleHtml() {
	if (!cp_s.fTitles) return '';
	var p = cp_rgPic[cp_s.irgImage];
	var html = '';
	if (clib_isString(p.title)) html += '<p class=clibsl_class_slideTitle>' + p.title + '</p>';
	if (clib_isString(p.subtitle)) html += '<p class=clibsl_class_slideSubtitle>' + p.subtitle + '</p>';
	var copy = (clib_isString(p.copyright) ? p.copyright : cp_copyright);
	if (clib_isString(copy)) html += '<p class=clibsl_class_slideSubtitle>' + copy + '</p>';
	return html;
	}


