//this gallery by Trev at http://wavesculptor.com - please retain credit and link, thanks. 
//img data etc loaded from any pre-loaded .js data file containing an array "I"

//SHUFFLE
cn=new Array; for(i=0;i<=I.length;i++)cn[i]=0

function slide(m,i){M=eval(m);Im=eval(I[M]);ImL=Im.length;C=eval(cn[M])
if(i==1){C<ImL-1?N=C+1:N=0}
if(i==-1){if(C==-1){N=ImL-2}else if(C>0){N=C-1}else{N=ImL-1}}
cn[M]=N
sm=String("s"+M);IN=(Im[N][0]);imLoc=String(dir+IN);d.images[sm].src=imLoc;d.images[sm].style.width="auto";d.images[sm].style.height="auto"
ENbutton=String("b"+M+"en")
imgId=String("s"+M); pp="portrt"; LL="lscape"
G(imgId).attributes[2].nodeValue=imLoc

Gim=G(imgId)
imAt=Gim.attributes.length
for(i=0;i<imAt;i++){imCls=Gim.attributes[i]
	if(imCls.nodeName.toLowerCase()=="class"){
	Im[N][1]=="p"?imCls.nodeValue="portrt":imCls.nodeValue="lscape"
}}
N1=(N+1)+" ";M1=(M+1)+" "
G(ENbutton).childNodes[0].nodeValue=/*"item "+M1+":*/"image "+N1+"of "+(ImL)+" >"
}

ItemFile=dataFile()

//ITEM WINDOW OPENER
function itemOpen(){
	itemPage=dataFile()+"_item.htm"
	for(i=0;i<arguments.length;i++){
		i==0?qs1="?":qs1="&";qs=qs1+"a"+i+"="+arguments[i];itemPage+=qs;}
	window.location=itemPage
}
function LARGEimg(Cat){Ic=eval(I[Cat]); c=cn[Cat]; C=Ic[c]; itemOpen(0,Cat,c)}

//AUTOSCROLL REMOVED - just the scroll bar location and highlight left
function ST(){var sT=0
if(w&&typeof(w.pageYOffset)=='number'){sT=w.pageYOffset
}else if(d.all&&d.body.scrollTop){sT=d.body.scrollTop
}else if(d.documentElement&&d.documentElement.scrollTop){sT=d.documentElement.scrollTop
}//respectively NS/DOM/(IE6 in compliant-mode)
return sT
}
function HT(){
var ht=0
if(typeof(w.innerHeight)=='number'){ht=w.innerHeight
}else if(d.documentElement&&d.documentElement.clientHeight){ht=d.documentElement.clientHeight
}else if(d.body&&d.body.clientHeight){ht=d.body.clientHeight
}//respectively non-IE, IE6+ compliant mode, IE4 compatible
return ht
}

lastI=0
function OVR(inp){if(inp==1||inp==0)lastI=inp; if(lastI==1){op=true}else{op=false} return op}
//OVR()returns true = cursor over an image

function ImID(idx){OVR(1)
if(OVR()){if(G(idx)){G(idx).className='imMoused'}
}}
function xb(idx){OVR(0)
G(idx).className='im'}



//COMPILE ALL THE *INITIAL* REPEATED IMAGE TABLE ELEMENTS
function Twrite (tr,Id,filename,iclass){
tdHead="<h4>"+dR[1][Id]+"</h4>"
src=dir+filename
if(iclass=="p"){clss="portrt"}else{clss="lscape"}
HiLi="onmouseover=\"ImID(\'i"+Id+"\',"+tr+")\" onmouseout=\"xb(\'i"+Id+"\')\""
imN=eval(I[Id]).length
shfL=""; if(imN>2){moreIms=(imN-1)+" more images &gt;"
shfL="<a href=\"javascript:slide("+Id+",-1)\" "+HiLi+" title=\"shuffle images backwards\">&nbsp;&lt;<\/a>&nbsp;&nbsp;"}
hUI=Id+1
enTxt="en'>image 1 of " //item "+hUI+":
Shf="<p class=\"bB\">"+shfL+"<a "+HiLi+" href=\"javascript:slide("+Id+",1)\" id='b"+Id;   Shnd=imN+"&nbsp;&gt;<\/a><\/p>"
imN>1?(sDIVs="<DIV class=\"en\" lang=en>"+Shf+enTxt+Shnd+"<\/DIV>"):sDIVs="&nbsp;"

d.write("\n<td id=\"i"+Id+"\" class=\"im\">"+tdHead+
"<a "+HiLi+" href=\'javascript:LARGEimg("+Id+")\'>\n<img id=\"s"+Id+"\" src=\""+src+"\" alt=\""+src+"\" class="+
clss+"><\/a>"+sDIVs+"<\/td>")
}



//widthways number of images wN set to fit fixed "target-Object" frame width in this version
wN=4
function TR(i){i<I.length?trs="<\/tr><tr>":trs="<\/tr>";d.write("\n\n<td><\/td>"+trs)}
//extra td: IE5mac bug fix

//jumping lefthand nav bar
function NAV(j){ 
tx="</a></td></tr>"
tp="<tr><td>&nbsp;<br>&nbsp;</td></tr>"
tr="<tr><td class='nav'><a href='#"
tt="title='scroll "
ds=" style='border:0px;padding:0px;width:11px;height:11px'"
up="<img src='imF/up' alt='^'"+ds+tt
dn="<img src='imF/dn' alt='v'"+ds+tt
UP=up+"up one row of images'>"
DN=dn+"down one row of images'>"
TP=up+"to top of page'>"
BT=dn+"to bottom of page'>"
jup="n"+(j-2);if(j-2<1)jup="gtop"
if(j!=null){jdn="n"+j}else{jdn="gbot"}
d.write("\n<td class='nav'><table class='but' id='n"+j+"'>"+tp+tr+"gtop'>"+TP+TP+tx+tr+jup+"'>"+
UP+tx+tr+jdn+"'>"+DN+tx+tr+"gbot'>"+BT+BT+tx+tp+"</table></td><td class='spa'>&nbsp;</td>")
}

//nav bar visibility ie 'movement'
function posNav(){
sT=ST()
TT=110//adjust this to approx #px top of unscrolled top image row
TH=190//adjust this to approx image table row height
WB=(sT-TT)/TH; WBR=Math.round(WB); NN="n"+(WBR+2)
if(G(NN)){G(NN).style.visibility="visible";
for(i=1;i<I.length;i++){N2="n"+i; if(G(N2)&&(G(N2)!=G(NN))){G(N2).style.visibility="hidden"}}

//IE4 mode - does the page even run in IE4 anymore - does anyone ever try?
}else if(d.all&&d.all.NN){NN.style.visibility="visible"
for(i=1;i<I.length;i++){N2="n"+i; if(d.all.N2&&(d.all.N2!=d.all.NN)){N2.style.visibility="hidden"}}
}}
setInterval("posNav()",200)
LS=String(w.location)

if(LS.indexOf('#')==-1){posNav(0)}else{LSN=LS.substr((LS.length-1),1);if(Number(LSN)!=NaN)Nn=Number(LSN);WB=300+Nn*250; posNav(WB)}


//DHTML DIV DOCUMENT.WRITE
scrt="<a class='bB' href='javascript:scrolltoggle("
d.write("\n\n<!-- THIS IS WRITTEN FROM album.js -->"+
"\n<table summary='THE IMAGES TABLE' class='im' id='raw'><tr>"
)

//WRITE IMAGE GRID & NAV TABLE: i=img stack number; j=table row number; k=table column number
nR=Math.ceil(I.length/wN)
for(i=0,j=1,k=1;i<I.length;i++){
	Ii=eval(I[i])
	if(nR>2&&k==1)NAV(j)
	Twrite(j,i,Ii[0][0],Ii[0][1]);if(k<wN){k++}else{TR(i);k=1;j++}
}
//FOOTER on html page
d.write("\n</table><a name='gbot'>&nbsp;</a></div>\n"+
"\n<!-- THIS ENDS WRITING FROM album.js -->\n\n"

)
d.close()
w.focus()
w.name='obj'

/* edition history:
2.3, 2002.08.03
3.0, 2005.09.10
4.0, 2005.10.23
5.1, 2006.06.11 single .js page version for soulwave gallery, dual language version
6.0, 2007.04.22 adapted to run in a div of nancy's site; TR()error sorted
7.0, 2008.01.15 minimised as template with most variables removed to data file
*/
