function pbtsImg(){ this.src = null; this.descr = ""; this.width = ""; this.height = ""; this.title = ""; this.extra1 = ""; this.extra2 = ""; this.extra3 = ""; this.extra4 = ""; this.date = ""; this.img = new Image(); this.isLoaded = false;}
var g_aryImgs = new Array(0); var g_defaults = new pbtsImg(); g_defaults.height = 1; g_defaults.width = 1; var g_isSshow = false, g_SshowIntId = null, g_SshowLoopIdx = 0; var g_thisImg, g_nextImg, g_prevImg, g_lastImg; var g_ThmsPerPg, g_firstImgThisPg; var g_isShowingAll= false, g_isAutoScroll= false; var g_aryAllowed = new Array("file","description","width","height","title","date","extra1","extra2","extra3","extra4"); var g_aryAddArg = new Array(0); g_aryAddArg = g_aryAddArg.concat(g_aryAllowed); var g_callbackFn = function(){ return true;}; var g_SshowDelay = 4000; var g_EID_Info = "", g_EID_Img = "theimage", g_EID_Descr = "imgdescr", g_EID_Title = "", g_EID_Extra1 = "", g_EID_Extra2 = "", g_EID_Extra3 = "", g_EID_Extra4 = "", g_EID_Date = "", g_EID_PgNav = "", g_EID_Thms = "", g_EID_Link = ""; var g_ThmDir = "images/photos/thumbs/", g_ImgDir = "images/photos/", g_HTMLThmPg = "", g_HTMLImgPg = "", g_Spacer = "images/shim.gif", g_loadingImg = g_Spacer; var g_ThmWidth = 175, g_ThmClass = "", g_ThmEmptyClass= "", g_ThmSpacing = 2, g_ThmCols = 3, g_ThmRows = 3, g_isThmTitles = false, g_isThmAll = false; var g_ThmPrefix = ""; var g_isWrap = true, g_isRotate90 = false; var g_isSetDescrWidth= false; function pbtsReadURLIdx() { var tempStr=new String(window.location.search).toLowerCase(); var id=0; if (tempStr.substr(1,3)=="img"){ tempStr= new String( tempStr.substr( 5, tempStr.length-5 )); if (tempStr.length < 1)
tempStr= "0"; else if (isNaN(tempStr))
alert("\""+tempStr+"\" is not a valid number."); else
id= parseInt( tempStr ); if (id >= g_aryImgs.length)
id = (g_aryImgs.length-1);} else if (tempStr.substr(1,4)=="file") { var found=false; tempStr= tempStr.substr( 6, tempStr.length-6 ); for (var i=0;i < g_aryImgs.length; i++) { if (g_aryImgs[i].src.toLowerCase() == tempStr) { id=i; found=true; break;}
}
if (!found)
alert( "Sorry, did not find file \""+ tempStr+"\".");}
return id;}
function pbtsArrayExists(p_find,p_array){ var found=false; for (var j=0;j <= p_array.length; j++) { if (p_find== p_array[j]) { found=true; break;}
}
return found;}
function pbtsTimeLoadImg(){ if (g_aryImgs[g_thisImg].img.complete) { document.getElementById(g_EID_Img).src= g_aryImgs[g_thisImg].img.src; g_aryImgs[g_thisImg].isLoaded= true; clearInterval(g_TimerId); g_callbackFn( g_thisImg );}
}
function pbtsInitImgPg() { g_nextImg= g_thisImg + 1 ; g_prevImg= g_thisImg - 1 ; g_lastImg= g_aryImgs.length-1; switchPic( g_thisImg, false );}
function pbtsInitThmbPg() { g_ThmsPerPg= (g_ThmCols * g_ThmRows); g_lastPage = Math.ceil( g_aryImgs.length/ g_ThmsPerPg); pbtsGetFirstIdx(); pbtsWritePgNav(); pbtsWriteThmGrid();}
function pbtsGetFirstIdx() { if ((g_thisImg % g_ThmsPerPg) == 0) { g_firstImgThisPg = g_thisImg;} else { g_firstImgThisPg = g_thisImg - (g_thisImg % g_ThmsPerPg);}
return g_firstImgThisPg;}
function pbtsWriteThmGrid() { var innerHTML= ""; var title=""; var start, stop; var isOnePg = (g_HTMLThmPg == g_HTMLImgPg); var spcHt= 0; var spcWd= 0; if (g_defaults.width > g_defaults.height){ spcWd = g_ThmWidth; spcHt = Math.round(g_ThmWidth*(g_defaults.height/g_defaults.width));} else { spcWd = Math.round(g_ThmWidth*(g_defaults.width/g_defaults.height)); spcHt = g_ThmWidth;}
g_isShowingAll= (arguments.length > 0)?arguments[0]:false; if (g_isShowingAll) { start= 0; stop= g_aryImgs.length;} else { start= g_firstImgThisPg; stop= g_firstImgThisPg+g_ThmsPerPg;}
for (var i=start; i < stop; i++ ) { if ((i % g_ThmCols) == 0)
innerHTML += "<tr>"; if (i < g_aryImgs.length) { if ((g_isThmTitles) && (g_aryImgs[i].title.length > 0))
title= "<br>"+g_aryImgs[i].title; else
title= ""; innerHTML += "<td valign=top \""+g_ThmClass+"\">"; if (g_aryImgs[i].width > g_aryImgs[i].height) { if (isOnePg)
innerHTML += "<a href='javascript:switchPic("+i+");' title=\"click for larger image\">"; else
innerHTML += "<a href='"+g_HTMLImgPg+"?img=" + i + "' title=\"click for larger image\">"; innerHTML +="<img src=\"" +g_ThmDir+ g_ThmPrefix+ g_aryImgs[i].src+ "\" border=0 width="+g_ThmWidth+"></a>"+title+"</td>";} else { if (isOnePg)
innerHTML += "<a href='javascript:switchPic("+i+");' title=\"click for larger image\">"; else
innerHTML += "<a href='"+g_HTMLImgPg+"?img=" + i + "' title=\"click for larger image\">"; innerHTML +="<img src=\"" +g_ThmDir+ g_ThmPrefix+ g_aryImgs[i].src+ "\" border=0 height="+g_ThmWidth+"></a>"+title+"</td>";}
} else { innerHTML += "<td valign=top "+g_ThmEmptyClass+" ><img src=\""+g_Spacer+"\" width="+spcWd+" height="+spcHt+"></td>";}
if ((i % g_ThmCols) == (g_ThmCols-1))
innerHTML += "</tr>";}
document.getElementById(g_EID_Thms).innerHTML= "<table cellspacing='"+g_ThmSpacing+"'>"+ innerHTML+ "</table>";}
function pbtsKeyEvent(p_e) { var action= 0; if (typeof(p_e) == "undefined")
p_e=event; if( typeof( p_e.which ) == "number")
action = p_e.which; else if( typeof( p_e.keyCode ) == "number")
action = p_e.keyCode; else if( typeof( p_e.charCode ) == "number")
action = p_e.charCode; else
action=""; switch (action) { case 72:
case 104:
showHelp(); break; case 83:
case 115:
if (!g_isSshow)
startSlideshow(); else
stopSlideshow(); break; case 80:
case 112:
gotoPrevPic(); break; case 78:
case 110:
gotoNextPic(); break; case 76:
case 108:
gotoLastPic(); break; case 70:
case 102:
gotoFirstPic(); break; case 85:
case 117:
if ((g_firstImgThisPg+g_ThmsPerPg) < g_aryImgs.length) { g_firstImgThisPg=g_firstImgThisPg+g_ThmsPerPg; pbtsWriteThmGrid();}
break; case 68:
case 100:
if (g_firstImgThisPg >= g_ThmsPerPg) { g_firstImgThisPg=g_firstImgThisPg-g_ThmsPerPg; pbtsWriteThmGrid();}
break; default:
if ((action >= 48) && (action<=57)){ var i = action-48; if (i > 0)
i--; else
i=9; if ((g_firstImgThisPg+i) < g_aryImgs.length) { switchPic(g_firstImgThisPg+i, false);}
}
}
return true;}
function pbtsWritePgNav() { var innerHTML= ""; if (arguments.length > 0)
g_EID_PgNav= arguments[0]; if (g_EID_PgNav == "")
return; for (var i=1; i <= g_lastPage; i++ ) { if ((g_firstImgThisPg >= ((i-1)*g_ThmsPerPg)) && (g_firstImgThisPg <= ((i*g_ThmsPerPg)-1)))
innerHTML += " <b>" + i + "</b> "; else
innerHTML +=" <a href='javascript:rePgIdx(" + ((i-1)*g_ThmsPerPg) + ");' title=\"page "+i+" thumbnails\">" + i + "</a> ";}
if (g_isThmAll && (g_lastPage > 1))
innerHTML +="&nbsp;<a href='javascript:showAll();' title=\"show all thumbnails\">all</a> "; document.getElementById(g_EID_PgNav).innerHTML= innerHTML;}
function pbtsGetLink(i){ var s=new String(document.location); 
var re=/^([^?]+)\?/
if (s.match(re)){ var m=s.match(re); s=m[1];}
return "<a href=\""+s+"?file="+g_aryImgs[i].src+"\">link</a>";}
function rePgIdx(p_imgIdx) { g_thisImg= p_imgIdx; pbtsGetFirstIdx(); pbtsWritePgNav(); pbtsWriteThmGrid(); if (g_HTMLThmPg == g_HTMLImgPg)
switchPic( p_imgIdx, false );}
function switchPic( p_idx ) { var pic= document.getElementById(g_EID_Img); var isScroll= g_isAutoScroll && g_isShowingAll; if (arguments.length > 1)
isScroll= isScroll && arguments[1]; if (isScroll)
window.scrollTo(0,pic.top); if (p_idx < 0) { if (g_isWrap)
switchPic(g_lastImg); else
alert( "this is the first picture" );} else if (p_idx > g_lastImg) { if (g_isWrap)
switchPic(0); else
alert( "this is the first picture" );} else { if (!g_aryImgs[p_idx].isLoaded)
pic.src = g_loadingImg; else
pic.src= g_ImgDir + g_aryImgs[p_idx].src; pic.width = g_aryImgs[p_idx].width; pic.height = g_aryImgs[p_idx].height; if (g_EID_Descr != "") { if (g_isSetDescrWidth)
document.getElementById(g_EID_Descr).innerHTML= "<p style=\"width:" +g_aryImgs[p_idx].width+ "px;\">"+g_aryImgs[p_idx].descr+"</p>"; else
document.getElementById(g_EID_Descr).innerHTML= g_aryImgs[p_idx].descr;}
if (g_EID_Info != "") document.getElementById(g_EID_Info).innerHTML= "file: "+ g_aryImgs[p_idx].src +" (" +g_aryImgs[p_idx].width+ "W x "+ g_aryImgs[p_idx].height+"H)"; if (g_EID_Title != "") document.getElementById(g_EID_Title).innerHTML = g_aryImgs[p_idx].title; if (g_EID_Extra1 != "") document.getElementById(g_EID_Extra1).innerHTML= g_aryImgs[p_idx].extra1; if (g_EID_Extra2 != "") document.getElementById(g_EID_Extra2).innerHTML= g_aryImgs[p_idx].extra2; if (g_EID_Extra3 != "") document.getElementById(g_EID_Extra3).innerHTML= g_aryImgs[p_idx].extra3; if (g_EID_Extra4 != "") document.getElementById(g_EID_Extra4).innerHTML= g_aryImgs[p_idx].extra4; if (g_EID_Link != "") document.getElementById(g_EID_Link).innerHTML= pbtsGetLink(p_idx); if (g_EID_Date != "") { if (g_aryImgs[p_idx].date!="")
document.getElementById(g_EID_Date).innerHTML = "taken :"+g_aryImgs[p_idx].date; else
document.getElementById(g_EID_Date).innerHTML = "";}
g_thisImg= p_idx; g_nextImg= p_idx + 1 ; g_prevImg= p_idx - 1 ; if (!g_aryImgs[p_idx].isLoaded) { g_aryImgs[p_idx].img.src = g_ImgDir + g_aryImgs[p_idx].src; g_TimerId = setInterval("pbtsTimeLoadImg()", 250 );} else { g_callbackFn( p_idx );}
}
}
function writeMaxWidthShim(p_id) { var maxWidth=0; for (var i=g_firstImgThisPg; i< (g_firstImgThisPg+g_ThmsPerPg); i++ ) { if (i < g_aryImgs.length) { if (g_aryImgs[i].width > maxWidth)
maxWidth= g_aryImgs[i].width;}
}
document.getElementById(p_id).innerHTML= "<img src=\""+g_Spacer+"\" width="+maxWidth+" height=\"1\">";}
function addImg(){ if (arguments.length > g_aryAddArg.length) { alert( "Photo Gallery function \"addImg\" received too many arguments. Call had "+arguments.length+" arguments."); return false;}
var tempImg= new pbtsImg; tempImg.src = ""; tempImg.descr = g_defaults.descr; tempImg.title = g_defaults.title; tempImg.date = g_defaults.date; tempImg.extra1 = g_defaults.extra1; tempImg.extra2 = g_defaults.extra2; tempImg.extra3 = g_defaults.extra3; tempImg.extra4 = g_defaults.extra4; tempImg.isLoaded= false; if (g_isRotate90) { tempImg.width = g_defaults.height; tempImg.height= g_defaults.width; g_isRotate90 = false;} else { tempImg.width = g_defaults.width; tempImg.height = g_defaults.height;}
for (var i=0; i < arguments.length; i++) { if (arguments[i]!=null) { switch (g_aryAddArg[i]){ case "file" : tempImg.src = arguments[i]; break; case "description": tempImg.descr = arguments[i]; break; case "width" : tempImg.width = arguments[i]; break; case "height" : tempImg.height= arguments[i]; break; case "title" : tempImg.title = arguments[i]; break; case "date" : tempImg.date = arguments[i]; break; case "extra1" : tempImg.extra1= arguments[i]; break; case "extra2" : tempImg.extra2= arguments[i]; break; case "extra3" : tempImg.extra2= arguments[i]; break; case "extra4" : tempImg.extra4= arguments[i]; break;}
}
}
g_aryImgs[g_aryImgs.length]=tempImg; return g_aryImgs.length;}
function addImg90(){ var i=0; var p_ary= new Array( g_aryAllowed.length ); for (i=0;i < g_aryAllowed.length; i++) p_ary[i]=null; for (i=0;i < arguments.length; i++) p_ary[i]=arguments[i]; g_isRotate90= true; return addImg( p_ary[0],p_ary[1],p_ary[2],p_ary[3],p_ary[4],p_ary[5],p_ary[6],p_ary[7],p_ary[8],p_ary[9] );}
function gotoPrevPic(){return switchPic( g_prevImg, false );}
function gotoNextPic(){return switchPic( g_nextImg, false );}
function gotoFirstPic(){return switchPic(0, false);}
function gotoLastPic(){return switchPic( g_lastImg, false );}
function gotoThumbs() { window.location = g_HTMLThmPg +"?img="+ g_thisImg ; return false;}
function showHelp() { alert( "Photo Gallery Help (v2.3.1)\nwww.pizzabytheslice.com\n\nF= First image\nL= Last\n\nN= Next Image\nP=Previous\n\n1-9,0 enlarge thumbnail 1-10\n\nS= Start/Stop Slideshow (delay is "+ (g_SshowDelay/1000)+ " seconds)\n\nU= page Up (next thumbnail page)\nD= page Down" );}
function showAll() { pbtsWriteThmGrid(true);}
function startSlideshow() { stopSlideshow(); g_SshowIntId= window.setInterval( "gotoNextPic()", g_SshowDelay ); g_isSshow= true; g_SshowLoopIdx= 0;}
function stopSlideshow() { if (g_isSshow) { g_isSshow= false; clearInterval(g_SshowIntId);}
}
function toggleSlideshow() { if (g_isSshow)
stopSlideshow(); else
startSlideshow(); return g_isSshow;}
function enableQuickKeys() { document.onkeypress= pbtsKeyEvent;}
function writeGallery() { var tempStr=new String(window.location.pathname).toLowerCase(); var thm= new String(g_HTMLThmPg).toLowerCase(); var img= new String(g_HTMLImgPg).toLowerCase(); if (g_aryImgs.length < 1) { alert( "Photo Gallery function \"writeGallery\" failed because the gallery contains no images." ); return false;}
g_thisImg= (arguments.length > 0)?arguments[0]:pbtsReadURLIdx(); if (thm.toString() == img.toString()) { pbtsInitThmbPg(); pbtsInitImgPg();} else if ((thm.length > 0) && (tempStr.indexOf(thm.toString()) >= 0)) { pbtsInitThmbPg();} else if ((img.length > 0) && (tempStr.indexOf(img.toString()) >= 0)) { pbtsInitImgPg();} else { alert( "Photo Gallery function \"writeGallery\" failed to recognize Thumbnail or Image page" );}
}
function reorderArgs() { var i=0, Str=new String, Ary=new Array(0); for (i=0;i<arguments.length;i++) { Str= arguments[i]; Ary[Ary.length]=Str.toLowerCase(); if (!pbtsArrayExists(Ary[i],g_aryAllowed)) { alert( "Photo Gallery function \"reorderArgs\" did not recognize attribute \""+Ary[i]+"\"" ); return false;}
}
for (i=0;i<g_aryAllowed.length;i++){ if (!pbtsArrayExists(g_aryAllowed[i],Ary))
Ary[Ary.length]=g_aryAllowed[i];}
for (i=0;i<Ary.length;i++)
g_aryAddArg[i]=Ary[i]; return true;}
function setElementId( p_attrb, p_id ) { switch (new String(p_attrb).toLowerCase()) { case "image" : g_EID_Img = p_id;break; case "description": g_EID_Descr = p_id;break; case "title" : g_EID_Title = p_id;break; case "extra1" : g_EID_Extra1 = p_id;break; case "extra2" : g_EID_Extra2 = p_id;break; case "extra3" : g_EID_Extra3 = p_id;break; case "extra4" : g_EID_Extra4 = p_id;break; case "date" : g_EID_Date = p_id;break; case "info" : g_EID_Info = p_id;break; case "pages" : g_EID_PgNav = p_id;break; case "thumbs" : g_EID_Thms = p_id;break; case "link" : g_EID_Link = p_id;break; default:
alert( "Photo Gallery function \"setElementId\" did not recognize attribute \""+p_attrb+"\"" ); break;}
}
function setDefault( p_attribute, p_defaultValue ){ if (!pbtsArrayExists(p_attribute,g_aryAllowed)) { alert( "Photo Gallery function \"setDefault\" did not recognize attribute \""+p_attribute+"\"" ); return false;}
switch (p_attribute){ case "description": g_defaults.descr= p_defaultValue; break; case "width" : g_defaults.width = p_defaultValue; break; case "height" : g_defaults.height = p_defaultValue; break; case "title" : g_defaults.title = p_defaultValue; break; case "date" : g_defaults.date = p_defaultValue; break; case "extra1" : g_defaults.extra1 = p_defaultValue; break; case "extra2" : g_defaults.extra2 = p_defaultValue; break; case "extra3" : g_defaults.extra3 = p_defaultValue; break; case "extra4" : g_defaults.extra4 = p_defaultValue; break; default:
alert( "Photo Gallery function \"setDefault\" \""+p_attribute+"\" does not accept defaults." ); break;}
}
function setThumbDir(p_path){ g_ThmDir=p_path;}
function setImgDir(p_path){ g_ImgDir=p_path;}
function setThumbPage(p_val){ g_HTMLThmPg=p_val;}
function setImgPage(p_val){ g_HTMLImgPg=p_val;}
function setSpacer(p_val){ g_Spacer=p_val;}
function setLoadingImg(p_Image){ g_loadingImg=p_Image;}
function setThumbPrefix(p_pre){ g_ThmPrefix=p_pre;}
function setRows( p_rows ){ g_ThmRows= p_rows;}
function setCols( p_cols ){ g_ThmCols= p_cols;}
function setThumbClass(p_class){ g_ThmClass=" class='"+p_class+"'";}
function setThumbEmptyClass(p_class){ g_ThmEmptyClass=" class='"+p_class+"'";}
function setThumbWidth(p_val){ g_ThmWidth=p_val;}
function setThumbSpacing(p_val){ g_ThmSpacing=p_val;}
function setThumbTitles(p_on){ g_isThmTitles=p_on;}
function setThumbAll(p_on){ g_isThmAll=p_on;}
function setAutoScroll(p_on){ g_isAutoScroll=p_on;}
function setDelay(p_miliseconds){ g_SshowDelay= p_miliseconds;}
function setWrap(p_on){ g_isWrap=p_on;}
function setDefDims( p_width, p_height ){ if (p_width < 1) p_width=1; g_defaults.width=p_width; if (p_height < 1) p_height=1; g_defaults.height=p_height;}
function setImageId( p_id ) { g_EID_Img = p_id;}
function setImageDescrId( p_id ){ g_EID_Descr = p_id;}
function setImageInfoId( p_id ) { g_EID_Info = p_id;}
function setImageTitleId( p_id ){ g_EID_Title = p_id;}
function setThumbIndexId( p_id ){ g_EID_PgNav = p_id;}
function setThumbGridId( p_id ) { g_EID_Thms = p_id;}
function setCallback(p_fn){ g_callbackFn=p_fn;}
function setSetDescrWidth(p_on){ g_isSetDescrWidth=p_on;}
function getCount() { return g_aryImgs.length;}
function getIsSlideshow() { return g_isSshow;}
function getValue( p_attribute ) { var i=(arguments.length > 1)?arguments[1]:g_thisImg; switch (new String(p_attribute).toLowerCase()) { case "image": return g_aryImgs[i]; case "file": return g_aryImgs[i].src; case "description": return g_aryImgs[i].descr; case "width": return g_aryImgs[i].width; case "height": return g_aryImgs[i].height; case "title": return g_aryImgs[i].title; case "extra1": return g_aryImgs[i].extra1; case "extra2": return g_aryImgs[i].extra2; case "extra3": return g_aryImgs[i].extra3; case "extra4": return g_aryImgs[i].extra4; case "date": return g_aryImgs[i].date; case "dir": return g_ImgDir; case "thumbdir": return g_ThmDir; case "pathname": return g_ImgDir+g_aryImgs[i].src; case "count": return g_aryImgs.length; case "current": return g_thisImg; case "maxwidth":
var m=-1; for (var i=0;i < g_aryImgs.length; i++)
m=Math.max(m, g_aryImgs[i].width); return m; break; case "maxheight":
var m=-1; for (var i=0;i < g_aryImgs.length; i++)
m=Math.max(m, g_aryImgs[i].height); return m; break; default:
alert( "Photo Gallery function \"getValue\" did not recognize attribute \""+p_attribute+"\"" ); break;}
}
