// daniel.js for fully-commented version
function G(x){return document.getElementById(x)}var r={w:1,h:1,pO:G('pO'),pI:G('pI'),pL:G('pL'),iO:G('iO'),iI:G('iI'),tO:G('tO'),t0:G('t0'),t1:G('t1'),t2:G('t2'),t3:G('t3'),bO:G('bO'),bI:G('bI'),n:null,c:null,x:'* Filter Selection *',s:'',S:function(a,l){a.push('<select style="font-size:0.75em" onchange="r.'+l+'(this.value)">')
for(c in p.c){a.push('<option value="',c)
if(c==f.c)
a.push('" selected="selected')
a.push('">',c,'</option>')}a.push('</select>')},H:function(c){if(c)
f.L(c)
r.c=r.n=null
h=['<span style="font-size:0.80em;line-height:100%;background-color:#fff">We\'ve classified each photograph into one or more categories.&nbsp; The selected category is displayed in the film canister to the bottom-left.&nbsp; The filmstrip above the canister shows the photographs in the selected category.<br />&nbsp;<br />Click a film frame to display an enlarged copy of the image.&nbsp; You can adjust the film speed by clicking on the up and down arrows on either side of the film canister.&nbsp; The filmstrip speed will also slow (or stop) when under the mouse pointer.<br />&nbsp;<br />When displaying a photograph, the prev and next buttons at the bottom will advance to the previous or next photograph in the selected category.&nbsp; You can change the selected category using the drop-down select box ']
r.S(h,'H')
h.push('.<br />&nbsp;<br />Too complicated?&nbsp; Click <a href="http://sites.google.com/a/danieljarboe.com/photos/">here</a> for the simple photo-dump page.<p>&nbsp;</p><p style="font-size:small">FYI, I\'m using <a href="http://www.000webhost.com/164687.html">$0.00 webhost</a> for free hosting with 100GB/month data transfer.<br />The full-size images are on <a href="http://www.google.com/sites">Google Sites</a> with unlimited storage/bandwidth (but restricted page layouts).<br />Hoo-ray for freebies!</p></span>')
r.T(h.join(''))
return false},F:function(c){if(c)
f.L(c)
r.c=r.n=null
var h=["Welcome to Daniel's Picture Viewer.<br />Found ",p.l,' photographs and ',p.k,' categories.<br />Click a film frame to the left, or narrow your selection with a category filter below.<br />&nbsp;<br />']
r.S(h,'F')
h.push('<br />&nbsp;<br /><span class="l" style="color:#0f20b4;text-decoration:underline" onclick="return r.H()">Help</span>')
r.T(h.join(''))},P:function(n){if(!n||!n.f)
n=r.n
if(!n||!n.f.height)
return
r.c=n
r.n=null
r.pO.style.display=r.iO.style.display='none'
r.pI.src=r.pL.href=n.s
var h=r.h-r.bO.offsetHeight
if(h<0)
h=0
var i=n.f.height/n.f.width
var a=h/r.w
if(i>a){r.pI.height=h
r.pI.width=Math.floor(h/n.f.height*n.f.width)
r.t=0}else{r.pI.width=r.w
t=Math.floor(r.w/n.f.width*n.f.height)
r.pI.height=t
r.t=Math.max(0,Math.floor((h-t)/2))}r.pO.style.top=r.tO.style.top=r.t+'px'
r.t0.innerHTML=r.t2.innerHTML=r.t3.innerHTML=n.i
r.pO.style.display='inline'},T:function(d){r.pO.style.display='none'
if(d.s){var h=['Found in <select style="font-size:0.75em" onchange="f.L(this.value)">']
for(var c in d.c){h.push('<option value="',c)
if(c==f.c)
h.push('" selected="selected')
h.push('">',c,'</option>')}h.push('<option value="">',r.s,'</option><option value="',r.x,'">',r.x,'</option></select>')
r.tO.style.top='0px'
r.t0.innerHTML=r.t2.innerHTML=r.t3.innerHTML=''
r.t1.innerHTML=r.pI.alt=r.pL.title=d.i
r.bI.innerHTML=h.join('')
r.iI.innerHTML='Loading <a href="'+d.s+'">'+d.s+'</a> <span style="text-decoration:blink">...</span>'
r.bO.style.display=r.tO.style.display=r.iO.style.display='inline'
r.iO.style.top=Math.max(0,Math.floor((r.h-r.bO.offsetHeight-r.iO.offsetHeight-r.t1.offsetHeight)/2))+r.t1.offsetHeight-4+'px'}else{r.tO.style.display=r.bO.style.display='none'
r.iI.innerHTML=d
r.iO.style.top='0px'
r.iO.style.display='inline'
r.iO.style.top=Math.max(0,Math.floor((r.h-r.iO.offsetHeight)/2))+'px'}}}
var f={h:0,t:0,fO:G('fO'),fI:G('fI'),sL:G('sL'),sR:G('sR'),s:0,f:34,b:3,hv:0,i:0,x:0,c:'All Photos',cI:G('cI'),A:function(d){f.s+=d
if(f.s&&!f.x)
f.x=window.setInterval(f.M,50)
else
if(!f.s&&f.x){window.clearInterval(f.x)
f.x=0}},F:function(e){if(!e)
e=window.event
var t=e.srcElement||e.target
if(t.id=='u') f.A(-1)
else if(t.id=='d') f.A(1)
else if(t.id=='cI') r.F()},C:function(e){if(!e)
e=window.event
var t=e.srcElement||e.target
var i=parseInt(t.id)
if(i==t.id&&t.tagName.toUpperCase()=='IMG'){e.returnValue=false
if(e.preventDefault)
e.preventDefault()
C(D(i))
return false}},M:function(){var reOrder=0
var s=f.s
if(f.hv)
s=Math.round(s/2)
if(!s)
return
f.t+=s
while(f.t>33){f.t-=34
f.f+=34}while(f.t<0){f.t+=34
f.f-=34}var c=p.c[f.c]
if(s<0)
while((f.f-34+f.t+f.b)<=-D(0).h){f.f+=D(0).h+f.b
f.i=(f.i+1)%c.length
reOrder=1}else
while((f.f-34+f.t+f.b)>0){f.i=(f.i-1+c.length)%c.length
f.f-=D(0).h+f.b
reOrder=1}f.W(reOrder)},W:function(reOrder){if(reOrder){var c=p.c[f.c]
var t=f.f
var h=[]
for(var i=0;i<f.l;i++){var d=p.d[c[(f.i+i)%c.length]]
h.push('<a href="',d.s,'"><img id="',i,'" src="',d.t.src,'" width="128" height="',d.h,'" style="margin-top:',f.b,'px" alt="Click for full photo" /></a>')
t+=d.h+f.b}f.fI.innerHTML=h.join('')}f.fI.style.top=f.f+'px'
f.fO.style.top=f.t+'px'},L:function(c){if(c==r.x)
return r.F()
if(!c)
return C(r.c||r.n)
f.c=c
f.cI.innerHTML=c
f.cI.style.paddingBottom='0px'
f.cI.style.paddingBottom=Math.max(0,Math.floor((32-f.cI.offsetHeight)/2))+'px'
c=p.c[c]
var l=0
var t=f.b
while(t<f.h)
t+=p.d[c[l++%c.length]].h+f.b
for(var i=0,z=c.length-1;i<z;i++){t+=p.d[c[(i+l)%c.length]].h-p.d[c[i]].h
while(t<f.h)
t+=p.d[c[(i+(++l))%c.length]].h+f.b}f.l=l+1
f.W(1)}}
var p={l:0,d:[],c:{},k:-1,f:0,R:function(){var i=p.d.length
while(i--){p.d[i].h=Math.floor(p.d[i].t.height*(128/Math.max(1,p.d[i].t.width)))
if(p.d[i].h!=p.d[i].t.height||128!=p.d[i].t.width)
alert('WARN: resized thumbnail '+p.d[i].t.src)}var c={}
c[f.c]=p.c[f.c]
var a=[]
for(var i in p.c){if(i!=f.c)
a.push(i)}a.sort()
for(var i=0,z=a.length;i<z;i++)
c[a[i]]=p.c[a[i]]
p.c=c
var t=G('t')
a.push(f.c,r.x)
t.innerHTML='<select><option>'+a.join('</option><option>')+'</option></select>'
var m=t.offsetWidth
t.innerHTML='<select><option>'+(r.s='.')+'</option></select>'
while(t.offsetWidth<m)
t.innerHTML='<select><option>'+(r.s+=' .')+'</option></select>'
t.parentNode.removeChild(t)
t=null
f.fI.innerHTML=''
f.fI.style.lineHeight='0px'
R()
if(f.fO.addEventListener){f.fO.addEventListener('click',f.C,false)
f.fO.addEventListener('mouseover',function(){f.hv=1},false)
f.fO.addEventListener('mouseout',function(){f.hv=0},false)
f.cI.parentNode.addEventListener('click',f.F,false)}else if(f.fO.attachEvent){f.fO.attachEvent('onclick',f.C)
f.fO.attachEvent('onmouseover',function(){f.hv=1})
f.fO.attachEvent('onmouseout',function(){f.hv=0})
f.cI.parentNode.attachEvent('onclick',f.F)}else{f.fO.onclick=f.C
f.fO.onmouseover=function(){f.hv=1}
f.fO.onmouseout=function(){f.hv=0}
f.cI.parentNode.onclick=f.F}window.onresize=R
f.c="Daniel's Favorites"
p.f|=2
r.F(f.c)
f.A(-1)},N:function(i,c,s){this.t=new Image()
this.h=0
this.f=new Image()
this.i=i
this.c={}
for(var j=0,z=c.length;j<z;j++)
this.c[c[j]]=p.c[c[j]].length-1
if (s.slice(-4).toLowerCase()=='.gif')
this.s='images/'+s
else this.s='http://sites.google.com/a/danieljarboe.com/photos/Home/'+s
this.t.onload=function(){f.fI.innerHTML='Loading Film...<br />'+(++p.l)+'/'+p.d.length+' ('+Math.floor(100*p.l/p.d.length)+'%)'
if(p.f&1&&p.l==p.d.length)
p.R()}}}
function D(i){return p.d[p.c[f.c][(f.i+i)%p.c[f.c].length]]}function B(d){var n=r.c||r.n
var c=p.c[f.c]
C(p.d[c[(c.length+n.c[f.c]+d)%c.length]])}function C(d){r.T(d)
if(d.f.src&&d.f.complete&&d.f.height){r.n=null
r.P(d)}else{r.n=d
r.c=null
d.f.onload=r.P
if(!d.f.src||d.f.complete)
d.f.src=d.s}}function R(){var w=r.w
var h=r.h
if(document.documentElement&&document.documentElement.clientWidth)
r.w=document.documentElement.clientWidth
else
r.w=document.body.clientWidth
if(document.documentElement&&document.documentElement.clientHeight)
r.h=document.documentElement.clientHeight
else
r.h=document.body.clientHeight
r.w-=166
if(r.w<52)
r.w=52
if(w==r.w&&h==r.h)
return
if(h!=r.h){f.h=r.h-34
if(f.h<0)
f.h=0
if(p.f&2)
f.L(f.c)}if(r.c)
r.P(r.c)
else
r.iO.style.top=Math.max(0,Math.floor((r.h-r.bO.offsetHeight-r.iO.offsetHeight-r.t1.offsetHeight)/2))+r.t1.offsetHeight-4+'px'}function X(){var x
if(window.XMLHttpRequest)
x=new XMLHttpRequest()
else
x=new ActiveXObject('Microsoft.XMLHTTP')
if(!x)
return
if(!f.fI.firstChild)
f.fI.innerHTML='Loading Film...'
x.onreadystatechange=function(){if(x.readyState==4){if(x.status==200){var n=0
var a=x.responseText.split('<a href="')
for(var i=0,l=a.length;i<l;i++){var h=a[i].slice(0,a[i].indexOf('"'))
if(h.indexOf('(category)')==13){var y=h.indexOf('(caption)')
var z=h.indexOf('(filename)',y)
if(y>0&&z>0){var s=h.slice(z+10)
var t=unescape(unescape(h.slice(y+9,z))).replace('"','&quot;')
var c=unescape(unescape(h.slice(23,y))).replace('"','&quot;').split('_')
c.sort()
c.splice(0,0,f.c)
var j=0
while(j<c.length){if(!c[j]||((j+1)<c.length&&c[j]==c[j+1]||c[j]==r.x))
c.splice(j,1)
else{if(!p.c[c[j]]){p.c[c[j]]=[]
p.k++}p.c[c[j++]].push(n)}}p.d.push(new p.N(t,c,s))
p.d[n++].t.src="images/"+h}}}if((p.f|=1)&&(p.l==p.d.length))
p.R()}else{f.fI.innerHTML+='<br />'+x.status+', retrying...'
window.setTimeout(X,5000)
x=null}}}
x.open("GET","images/",true)
if(window.XMLHttpRequest)
x.send(null)
else
x.send()}X()

