var ie5 = navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.match(/MSIE\s+(\d+)\.\d+/)[1] >= 5;
var ns4 = navigator.appName == 'Netscape' && (navigator.appVersion.match(/^(\d+)\.\d+/)[1] == 4);
var ns6 = navigator.appName == 'Netscape' && (navigator.appVersion.match(/^(\d+)\.\d+/)[1] >= 5);  // For some reason Netscape 6 reports 5 in appVersion!!
var use_css = (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.match(/MSIE\s+(\d+)\.\d+/)[1] >= 5) || (navigator.appName == 'Netscape' && navigator.appVersion.match(/^(\d+\.\d+)/)[1] >= 5);
var use_layers = (!use_css) && navigator.appName == 'Netscape' && navigator.appVersion.match(/^(\d+)\.\d+/)[1] >= 4;

var z_index = 0;
function main_image_begin(image_id, image_width, image_height) {
	var str = '';
	if (use_css) {
		str += '<div style="position:relative; top:0px; left:0px;">';
	} else if (use_layers) {
		str += '<ilayer>\n';
	}
	str += '<img src="'+directory+'/jpg/medium/'+image_id+'.jpg" width="'+image_width+'" height="'+image_height+'" border=1 xstyle="border-color: 000000;" alt="">\n';
	document.write(str);
}

function inset_image(image_id, image_left, image_top, image_width, image_height, big_width, big_height, photographer, title) {
	var str = '';
	z_index += 1;
	if (use_css) {
		if (ns6) { str += '<a href="javascript:void()">' }
		str += '<img src="'+directory+'/jpg/small/'+image_id+'.jpg" name="'+image_id+'" width="'+image_width+'" height="'+image_height+'" style="position:absolute;top:'+image_top+'px;left:'+image_left+'px;z-index:'+z_index+'; border-color:cccccc" border=1 onClick="show_big_image(\''+image_id+'\','+big_width+','+big_height+',\''+photographer+'\',\''+title+'\')" alt="'+title+'" onMouseOver="return display(\'\')" onMouseDown="begin_drag(event)" onMouseMove="drag_image(event)" onMouseUp="end_drag(event)">'
		if (ns6) { str += '</a>' }
	} else if (use_layers) {
		str += '<layer top="'+image_top+'" left="'+image_left+'">\n'
		str += '<a href="javascript:show_big_image(\''+image_id+'\','+big_width+','+big_height+',\''+photographer+'\',\''+title+'\')"><img src="'+directory+'/jpg/small/'+image_id+'.jpg" width="'+image_width+'" height="'+image_height+'" border=1 alt="'+title+'"></a>\n'
		str += '</layer>\n';
	} else {
		str += '<a href="javascript:show_big_image(\''+image_id+'\','+big_width+','+big_height+',\''+photographer+'\',\''+title+'\')"><img src="'+directory+'/jpg/small/'+image_id+'.jpg" width="'+image_width+'" height="'+image_height+'" border=1 alt="'+title+'"></a>\n'
	}

	document.writeln(str);
}
function main_image_end() {
	var str = '';
	if (use_css) {
		str += '</div>';
	} else if (use_layers) {
		str += '</ilayer>';
	}
	document.write(str);
}
function mini_image(image_id, image_width, image_height, big_width, big_height, photographer, title) {
	var str = '';
	z_index += 1;
	if (use_css) {
		str += '<img src="'+directory+'/jpg/small/'+image_id+'.jpg" name="'+image_id+'" width="'+image_width+'" height="'+image_height+'" border=1 onClick="show_big_image(\''+image_id+'\','+big_width+','+big_height+',\''+photographer+'\',\''+title+'\')" alt="'+title+'" onMouseOver="return display(\'\')" onMouseDown="begin_drag(event)" onMouseMove="drag_image(event)" onMouseUp="end_drag(event)">'
	} else if (use_layers) {
		str += '<a href="javascript:show_big_image(\''+image_id+'\','+big_width+','+big_height+',\''+photographer+'\',\''+title+'\')"><img src="'+directory+'/jpg/small/'+image_id+'.jpg" width="'+image_width+'" height="'+image_height+'" border=1 alt="Click to show bigger image"></a>\n'
	}
	document.writeln(str);
}

var disable_big_image = false;
var imgWin;
function show_big_image(image, width, height, photographer, title) {
	var str = '';
	if (!disable_big_image) {
		if (use_layers) {
			width += 15;
			height += 10;
		}	
		if (imgWin && !imgWin.closed) { imgWin.close() }
 		imgWin = window.open('', 'BigImage', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+(width+4)+',height='+(height+26))
 		str += '<html><head><link rel=stylesheet type="text/css" href="'+directory+'/include/style.css"><title>'+title+'</title></head>';
 		str += '<body style="margin: 0" bgcolor="#302040">';
 		str += '<img src="'+directory+'/jpg/medium/'+image+'.jpg" hspace=2 vspace=2><br>';
 		str += '<table width="100%"><tr><td><font size="1">&copy; 2001-2002 • <b>Photo</b> '+photographer+'</font></td><td align=right><a href="javascript:window.close()"><b>Close</b></a>&nbsp;</td></tr></table>';
 		str += '</body></html>';
 		imgWin.document.open('text/html');
 		imgWin.document.write (str);
 		imgWin.document.close();
 		imgWin.focus();
  	} else {
 		disable_big_image = false;
 	}

}

function close_big_image() {
	if (imgWin && !imgWin.closed) { imgWin.close() }
}

var origin_x = 0;
var origin_y = 0;
var last_x = 0;
var last_y = 0;
var dragging = '';
function begin_drag(evnt) {
   origin_x = evnt.clientX;
   origin_y = evnt.clientY;
   last_x = origin_x;
   last_y = origin_y;
	dragging = evnt.srcElement.name;
	evnt.srcElement.style.zIndex = z_index++;
	evnt.srcElement.setCapture();
}

function drag_image(evnt) {
	if (dragging == event.srcElement.name) {
		var new_x = evnt.clientX;
		var new_y = evnt.clientY;
		evnt.srcElement.style.posLeft = evnt.srcElement.style.posLeft + new_x - last_x;
		evnt.srcElement.style.posTop = evnt.srcElement.style.posTop + new_y - last_y;
		last_x = new_x;
		last_y = new_y;
		window.status = 'X: ' + evnt.srcElement.style.posLeft + ' Y: '+evnt.srcElement.style.posTop;
		if (Math.abs(origin_x - new_x) + Math.abs(origin_y - new_y) > 3) {
			disable_big_image = true;
		}
		return true;
	}
}

function end_drag(evnt) {
	if (dragging == event.srcElement.name) {
		dragging = '';
		evnt.srcElement.releaseCapture();
	}
}
function display(text) {
  if (use_css) { event.srcElement.style.cursor = "hand"; }
  window.status = text;
  return true;
}