d = document;
popularityData = {};
/* define empty data as a fallback just in case the script data fails to load */
d.write('<script src="PopularityData.js"></script>');
function S(s) { return s.match(/(\S+)/g); }
function L(s) { return s.match(/(\S[^\r\n]*)/g); }
ids = S('instructions buttons thumbnails overlay frame buttons2');
for (i=0; i<ids.length; i++)
d.write('<div id="', ids[i], '"></div>');
function dId(a) { return document.getElementById(a); }
function turnOn() {
dId('overlay').style.display = '';
dId('frame').style.display = '';
var x = dId('votes');
if (x)
x.style.display = '';
}
function turnOff() {
dId('overlay').style.display = 'none';
dId('frame').style.display = 'none';
document.nextBig = 0;
document.lastBig = 0;
var x = dId('vote_status');
if (x) {
x.src = '../1x1t.gif';
dId('votes').style.display = 'none';
}
}
function bigLoad(img) {
document.lastBig = img.previousSibling;
document.nextBig = img.nextSibling;
var src = img.src.replace(/Small\//, 'Big/');
var alt = img.title;
var name = alt.substring(alt.indexOf(' '));
document.prevBig = src;
var s1, s2;
if (s1 = dId('g4')) {
s1.selectedIndex = self.cart.e4[src] || 0;
dId('g8').selectedIndex = self.cart.e8[src] || 0;
}
dId('frame').innerHTML = '<div class="outer"><div class="inner"><img title="' + alt + '" onclick="turnOff()" src="' + src + '" /><h2 style="color: white">' + name + '</h2></div></div>';
dId('overlay').onclick = turnOff;
dId('frame').onclick = turnOff;
turnOn();
}
sort_images = 0;
function showThumbs(a, b) {
var imgs = sort_images || main_images;
var s = '', i;
var p = self.baseimage || '';
for (i=a; i<imgs.length&&i<b; i++) {
var x = S(imgs[i]);
s += '<img src="' + p + 'Small/' + x[0] + '" onclick="bigLoad(this)" title="' + x.join(' ') + '" />';
}
dId('thumbnails').innerHTML = s;
}

function sortPopular() {
var s = {}, x = [], y = main_images, i, j;
for (i=0; i<y.length; i++) {
j = y[i];
var score = popularityData[S(j)[0]] || 0;
s[j] = score;
x[i] = j;
}
x.sort(function(a,b){return s[b]-s[a];});
for (i=0; i<x.length; i++)
x[i] += ' (Clicks: ' + s[x[i]] + ')';
sort_images = x;
}

function boldButton(it) {
var f = it.form || d.forms[0];
var i;
for (i=0; i<f.elements.length; i++) {
var x = f.elements[i];
if (x.type != 'button') continue;
if (x.value == it.value)
x.style.fontWeight = 'bold';
else
x.style.fontWeight = 'normal';
}
}

onload = function() {
turnOff();
var imgs = L(dId('images').value);
main_images = imgs;
var size = d.sheetsize || 60;
if (imgs.length < 3*size)
size = Math.round(size/3);
var s = '', i;
for (i=0; i<imgs.length; i+=size) {
var a, b;
a = i+1;
b = i+size; if (b > imgs.length) b = imgs.length;
s += '<input type="button" name="clicks" value="' + (a) + '-' + (b) + '" onclick="showThumbs(' + (a-1) + ', ' + (b) + ');boldButton(this);" />';

}
if (size > 10)
dId('buttons').innerHTML = '<br clear="all" />' + s;
dId('buttons2').innerHTML = s;
showThumbs(0, 4);


if (d.minimal)
return;
dId('instructions').innerHTML = '<table class="h1" cellpadding="0" cellspacing="0"><tr><th style="font-size: 400%" valign="top">Y</t'
+ 'h><td valign="middle"><table cellpadding="0" cellspacing="0"><tr><td style="font-size: 150%; font-weight: bold">our Best'
+ ' Photographer</td></tr><tr><td valign="top"'
+ '><i>www.yourbestphotographer.com</i></td></tr></table'
+ '></td></tr></table><h3>' + d.title + '</h3><table><tr><td>\n'
+ '<ul><li>Click any button to display a thumbnail sheet for the indicated range of photographs.</li>'
+ '<li>Click any image to show an enlarged preview (originals are still much higher quality).</li>'
+ '<li>Click again on the enlarged preview to return to viewing of the thumbnail sheet.</li>'
+ '<li>Click the button to <input type="button" value="toggle photo sorting" onclick="if (sort_images) { sort_images = 0; } else { sortPopular(); } showThumbs(0, 4); boldButton({});" /> by chronological order (photo date recorded by the camera) or popularity (approximate number of clicks)</li>'
+ (location.search.indexOf('order') > -1 ? '<li>Click <input type="button" onclick="showCart()" value="Show Cart" /> to show any items you may have added to your cart.</li>' : '')
+ '</ul></td></tr></table>';

}

if (d.minimal) {
} else {
advert = '<br /><center><iframe src="http://rcm.amazon.com/e/cm?t=myersdaily&o=1&p=48&l=ur1&category=endless&banner=17S7RZF1ABZ9A1SAAC82&m=endless&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe></center>';
d.write('<script src="PopularityData.js"></script>');
d.write('<script src="../Votes.js"></script>');
d.write(advert);
d.write('<address><p>&copy; 1998-2010 <a href="http://josephmyers.com/">Joseph K. Myers</a>, jkm at josephmyers&#x2e;com</p></address>');
}
