var savedIndex = -1;
var savedImage = "";
var JPG_SUFFIX	= ".jpg";
var ALT_SUFFIX	= "-alt" + JPG_SUFFIX;
function debug( message ){
    alert( message );
}
// find the index with document.images for an image with the given name
function getImgIndex( name )
{
	var	result	= -1;
	
	if ( document.images && document.images.length != 0 )
	{
		for( i = 0; i < document.images.length; ++i )
		{
			if ( document.images[ i ].src == name )
			{
				result	= i;
				break;
			}
		}
	}
	return result;
}
// note: overAlt is used only in a tiny handful of instances, mostly in DIP
function overAlt(name)
{
	overSuffix(name,JPG_SUFFIX, ALT_SUFFIX);
}
// note: overPrefix is used only in a dozen cases in ZF and twice in DAP
function overPrefix(name, origPrefix, newPrefix)
{
	if ( document.images )
	{
		var idx = getImgIndex( name );
		if ( idx >= 0 )
		{
			savedIndex = idx;
			savedImage	= new Image();
			savedImage.src	= document.images[ savedIndex ].src;
			
			var pathDelimIdx = name.lastIndexOf("/");
			var path = "";
			var filename = name;
			if ( pathDelimIdx >= 0 )
			{
				path = name.substring( 0, pathDelimIdx + 1 );
				filename = name.substring( pathDelimIdx + 1, name.length);
			}
			
			var suffix = filename.substring( origPrefix.length, name.length );
			//debug( "suffix: " + suffix );
			var newName = newPrefix + suffix;
			//debug( "newName: " + newName );
			var fullNewName = path + newName;
			//debug( "fullNewName: " + fullNewName );
			var rolled	= new Image();
			rolled.src = fullNewName;
			document.images[ savedIndex ].src = rolled.src;
		}
	}
}
// note: overSuffix used heavily (2000+ times)
function overSuffix(name, origSuffix, newSuffix)
{
	if ( document.images )
	{
		var idx = getImgIndex( name );
		if ( idx >= 0 )
		{
			savedIndex = idx;
			savedImage	= new Image();
			savedImage.src	= document.images[ savedIndex ].src;
			
			var base = name.substring( 0, name.length - origSuffix.length );
			var rolled	= new Image();
			rolled.src = base + newSuffix;
			document.images[ savedIndex ].src = rolled.src;
		}
	}
}
// note overExtra scarcely used: a few times in the articles, a couple times in blog, once in DIP
function overExtra(name, newSuffix)
{
		overSuffix( name, '.jpg', newSuffix + '.jpg' );
}
function out(name)
{
  if(document.images && savedIndex != -1 )
  {
	document.images[ savedIndex ].src = savedImage.src;
	savedIndex	= -1;
	savedImage	= null;
  }
}

// == functions used by the non-jquery-based javascript-based mouseover comparison galleries
function compareGallerySwitch(imgDocID,imgObjName)
{
    document[imgDocID].src = eval(imgObjName + '.src');
}
function updateTextByID(docID,s)
{
    document.getElementById(docID).innerHTML = s;
}


// == script for adding cryptic email links (heavily employed)
function emailComment(subject) {
//var ref = document.referrer; 
var e1 = "comments1";
var e2 = "@";
var e3 = "diglloyd.com";
var em = e1 + e2 + e3;
var b = "%0D";
var b3 = b+b+b;
var footer =  b +"Which web page (url) are you commenting on (if any)? " + b + b + "-----%0dThank you--please enter your comments above.";
var body_message = b3 + footer;
var mtLink = 'mailto:' + em + '?subject=' + subject + '&body=' + body_message;

win = window.open(mtLink,'emailWindow'); 
if (win && win.open &&!win.closed) win.close();
} 

// == function used by the select-box article navigators
function gopage(dest)
		{
			var x;
			x=dest.options[dest.selectedIndex].value
			if (x) {
				location.href=x;
			}
		}

// B&H search box (from an elaborate advertisement supplied by B&H)
// eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('b i(t){9 a=0.3.4.5;0.3.4.5=a==s?"":a.6(/[\\q-\\c]|#|`|ô|\\?/g,\'\').6(/ì|î|Ñ/g,\'"\').6(/ë|í|Ç/g,"\'");m(0.3.4.5.l<2||0.3.4.5.k(/[^\\*].*[^\\*]/)==-1){f("- e r 8 2 h j o");7 d}n{0.3.p()}}',30,30,'document|||searchForm|shs|value|replace|return|keyword|var||function|xBF|false|Please|alert||letters|validateForm|or|search|length|if|else|more|submit|xA0|enter|null|form'.split('|'),0,{}))

