//index.js defines much of the shorthand inc. functions here, so should load first
function count_images(){if(d.images){
//get open-ended array-handle on unscripted **album** images by className ... [? add sub for odd shape images]
	d.PA=[]
	for(i=0;i<d.images.length;i++){
		if(d.images[i].className){iCls=d.images[i].className;
			if(iCls=='iPw'||iCls=='iPt'||iCls=='iPq'||iCls=='enlargement'){
				d.PA[i]=[]
				d.PA[i][0]=d.images[i].src;d.PA[i][1]=iCls}
}}}	popFilename()	//extract filename from src data by searching portion of path after... domain/img/S/
}
function popFilename(){
searchstr="/S/"
	for(i=0;i<d.PA.length;i++){
		if(d.PA[i]&&d.PA[i][0]){srcStr=d.PA[i][0]
			path_index=srcStr.search(searchstr)
			if(path_index!=-1){fNameStart=path_index+3
				filename=srcStr.substr(fNameStart)
				d.PA[i][2]=filename
}}}}

//large image handler called from scripted links in Da()
function largeIm(imN){
// 	NOTE LAST ARG IN FX DEPENDS ON NUMBER OF THUMBS SCREENBITES - FIX THIS OR UPDATE TO MATCH
	if(Da(imN,6)){words=Da(imN,6)}else{words=noEnlargmtTextMssg}//message is at top of photos_data.js
	Lid='phi0';if(iGI(Lid)){G(Lid).src="img/L/"+d.PA[imN][2]	//change image source to L directory version of S directory small
		nL=G("p0").childNodes[0]								//change node pre to p, create text node, set text to Cra[imN][4], append it
		wNode=d.createTextNode(words)
		if(nL.nodeName.toLowerCase()=='pre'){
			G("p0").replaceChild(G("pre-replace"),nL)
		n2=G("p0").childNodes[0]
		if(n2.nodeName.toLowerCase()=='p'){n2.appendChild(wNode)}
		}else{
		n3=G("p0").childNodes[0]
		if(n3.nodeName.toLowerCase()=='p'){if(n3.childNodes[0].nodeName.toLowerCase="#text")n3.replaceChild(wNode,n3.childNodes[0])} //if already p	
		}}else{G(Lid).src="img/S/00_no_enl_loaded.jpg"}
	renderURLhash2("#dn5") //---!!!!!!!!!-----SET ON CHANGE NUMBER OF IMAGE PAGES dn4 is hidden empties at mo (no link on html page), till number of images set for a while....

//set enlargement tab message to img number
LaImNrTx=d.createTextNode("enlargement of image "+imN)
if(LaTabG.nodeName.toLowerCase()=='a'){if(LaTabG.childNodes[0].nodeName.toLowerCase="#text")LaTabG.replaceChild(LaImNrTx,LaTabG.childNodes[0])}

//set tab of calling screenbite to display "BACK" span: calculate tab number
tabNr=1
function calcTabNr(){if(imN<=imgPerPage){return tabNr}else{imN=imN-imgPerPage;tabNr++; return "more"}
}
function tabLogic(){for(z=0;z<7;z++){tabResultNr=calcTabNr();if(tabResultNr!="more"){return tabResultNr}} //----!!!!!----SET ON CHANGE NUMBER OF IMAGE PAGES
}
spanId="bTi"+tabLogic()
if(iGI(spanId))viz(spanId,inli)

}



//retrieve image words by image filename from Cra[] in photos_data.js
function Da(imN,y){if(typeof d.PA[imN]=='object'){file=d.PA[imN][2]}else{return "&nbsp;#"+imN}
	for(z=0;z<Cra.length;z++){cz=-1
		if(Cra[z][0]==file){Cra[z][y]?cz=Cra[z][y]:cz=""; return cz	//;-)
}}}
cn=0;row=0;col=0
//assemble individual img div - SMALL IMAGE RELATIVE DIRECTORY PATH WRITTEN INTO COMMON SRC STRING AT s[] BELOW
function writeDiv(imN){
	ob="object"
	function Ob(imN){if(typeof d.PA==ob&&typeof d.PA[imN]==ob)return true}
	s=["\n<div class='phd' id='p","' style='top:","px;left:","px'>","<a href='#top' title='' onmouseover='hiLi(1,",")' onmouseout='hiLi(0,",")' onclick='largeIm(",")' class='","'><img id='phi","' class='","' src='img/S/","' alt='","'>","</a>","</div>"]
//row and column calculator to go with positon:absolute to nail all divs in place, just for IEX :-)  (counts times through script...)
	col=cn;cn++;topd=row*218;lefd=col*252;if(cn==3){cn=0;row++;if(row==3)row=0}
//write components of div
		i=0;d.write(s[i]+imN)				//0=div id
		i=1;d.write(s[i]+topd)				//1=div top px
		i=2;d.write(s[i]+lefd)				//2=div left px
	r=1;i=3;d.write(s[i]+Da(imN,r));r++		//1/3=any a text above img from photos_data.js Cra[i][1]
	for(i=4;i<7;i++){d.write(s[i]+imN)}		//2/4=a mous ov, 3=mous out, 4=onclk
	p=1;i=7;if(Ob(imN)){
			d.write(s[i]+d.PA[imN][p])
			}else{d.write(s[i]+"PA2?")}		//5/7=a cls d.PA[][1]
		i=8;d.write(s[i]+imN)				//6/8=img id
	for(i=9;i<11;i++){if(Ob(imN)){
			d.write(s[i]+d.PA[imN][p]);p++	//7/9=img cls d.PA[][1], 8=img src d.PA[][2]
			}else{d.write(s[i]+"PA2?")}}	
		i=11;if(Ob(imN)){d.write(s[i]+d.PA[imN][2])}else{d.write(s[i]+"PA2?")} //9/11=alt - use img filename for now
	for(i=12;i<14;i++){d.write(s[i]+Da(imN,r));r++}//10/12=a text, 11/13=undefined space within div, in photos_data.js at Cra[i][2,3]
	d.write(s[14]) //the closing tags of each div
}
function footHead(K){k1=K+1
	foot="\n</div><!-- screen-bite-scripted" +K+ " -->\n"
	head="\n<div class='screen-bite' id=\'hi_" +k1+ "'>\n"
	d.write(foot+head);d.close()
}
//write screen-bite of images
function formatSub(screenBite,totalBites){
	if(d.images){
		dvN="nsp"+screenBite //nsp+number is unscripted-div id
		if(iGI(dvN))S(dvN).display=none
		imgPerPage=9								//SET number of images per page//
		start=1+(screenBite*imgPerPage)-imgPerPage	//first img div written is for enlargenment
		limit=start+imgPerPage	
		for(n=start;n<limit;n++){
			writeDiv(n)
}	if(screenBite<totalBites)footHead(screenBite)
}}
function photo_format(){					//called from photos.html
	count_images();	NN=4					//SET number of screenfulls of thumbs; also screenbite header + ids on htm page, and args in largeIm() above//
	for(j=1;j<NN+1;j++){formatSub(j,NN)}

//hide enlargement tab on load - needs to see NN so called from bottom of page - vars refered to in largeIm() 
LaTaNr=NN+1 //NN is nr of image pages in function photo_format() 
LaTaId="tab"+LaTaNr //+LaTaNr
if(GI(LaTaId))LaTabG=G(LaTaId) //used in LARGEim()
}

//writes a dummy enlargement image to be replaced by src=
function enlargement_space(){writeDiv(0);S("nspEnlargement").display=none;row=-1;col=-1}
//mouseover img div style 
function hiLi(onoff,imNr){
	for(n=0;n<d.PA.length;n++){divId='p'+n
		if(iGI(divId)){G(divId).className="phd"}}
		divId_Hi="p"+imNr
		if(iGI(divId_Hi))if(onoff==1){G(divId_Hi).className="phdHiLi"}else{G(divId_Hi).className="phd"}
}