// GALLERY JAVASCRIPT - Copyright (C) 2006-2009 Charles A Upsdell, All Rights Reserved; www.upsdell.com


// Initialization .................... executed when the page is starting to load

	// Set global constants
	var sHidden = '(hidden)';

	// Set global variables - may be overridden by gallery.js
	var sThumbnailsDirection = 'vertical';
	var nThumbnailRows = 3;
	var nThumbnailColumns = 2;
	var nThumbnailMapColumns = 5;
	var nBigPhotoColumnWidth = 395;
	var nForSaleMarkerWidth = 7;
	var sBuyPhotoSeparator = ' ';
	var sLimitedSalesSeparator = '<br>';
	var sDefaultFiletype = '.jpg';
	var sImageFolder = '';
	var sPhotoFolder = '';
	var sForSale = '<img src="' + sPhotoFolder + oState.imageFilename('ico_fs','png') + '" alt="For sale" title="For sale">';
	var sLimitedSales = '<img src="' + sPhotoFolder + oState.imageFilename('ico_nfs','png') + '" alt="Limited sales" title="Limited sales">';
	var sThumbPrefix = 'thb_';
	var sPhotoPrefix = 'med_';
	var sGallerySeparator = '<br>\n';
	var sGalleriesHeader = '<h3 class="galleries">Galleries</h3>\n';
	var sServicesGallery = '';
	var bNavButtons = true;
	var bNavButtonsWrap = true;
	var sServicesPhoto = '';
	var sView = 'onclick';

	// Set local values
	var oBigPhoto = null;
	var objImage = null;
	var sCaption1 = '';
	var sCaption2 = '';
	var sFirstGallery = null;
	var sGallery = null;
	var sPhoto = null;
	var Gallery = [];
	var Photo = [];
	var OrderedPhotos = [];


// Global functions .................. called by other modules

// addGallery: Set info for one gallery

function addGallery ( name, preamble )
{
	if ( arguments.length < 1 )
	  {
		alert( 'addGallery error: you forgot to specify a gallery name' );
	  }
	if ( arguments.length < 2 )
	  {
		preamble = '';
	  }
	var i = Gallery.length;
	if ( i > 0 )
	  {
		var j;
		for ( j = 0; j < i; ++j )
		  {
			if ( Gallery[j].name == name )
			  {
				alert( 'addGallery error: you used the gallery name "' + name + '" more than once.' );
			  }
		  }
	  }
	sGallery = name;
	Gallery[i] = new cGallery( name, preamble );
	if ( i == 0 )
	  {
		setFirstGallery( name );
	  }
}

// cGallery: define cGallery class

function cGallery ( gallery_name, preamble )
{
	this.name = gallery_name;
	this.preamble = preamble;
	this.limited = 0;
	this.photo = [];
}
cGallery.prototype.addPhoto = function ( photo_index )
{
	this.photo[this.photo.length] = photo_index;
	if ( !(Photo[photo_index].for_sale) )
		this.limited += 1;
}

// addPhoto: Set info for one photo (assumes current gallery)

function addPhoto ( photo, caption1, caption2, thb_name, med_name, limited_sales )
{
	var for_sale = false;
	if ( arguments.length < 1 )
		alert( 'addPhoto error:  you forgot to specify a photo name for gallery ' + sGallery );
	if ( arguments.length < 2 )
		caption1 = '';
	if ( arguments.length < 3 )
		caption2 = '';
	if ( (oState.testmode==1) && ((arguments.length > 3) && (arguments.length != 6)) )
		alert( 'addPhoto: warning, ' + arguments.length + ' parameters for photo ' + photo + ', 3 or 6 expected' );
	if ( (oState.testmode==1) && !caption1 )
		caption1 = '{no title for ' + photo + '}';
	if ( (oState.testmode==1) && !caption2 )
		caption2 = '{no description for ' + photo + '}';
	if ( (arguments.length < 4) || (thb_name == '-') || (thb_name == '') )
		thb_name = sPhotoFolder + sThumbPrefix + photo + sDefaultFiletype;
	else
		thb_name = sPhotoFolder + thb_name;
	if ( (arguments.length < 5) || (med_name == '-') || (med_name == '') )
		med_name = sPhotoFolder + sPhotoPrefix + photo + sDefaultFiletype;
	else
		med_name = sPhotoFolder + med_name;
	if ( (arguments.length < 5) || (limited_sales != 'limited') )
	  {
		for_sale = true;
		if ( (arguments.length >= 6) && (limited_sales != '') )
			alert( 'addPhoto: warning, "' + limited_sales + '" for-sales parameter for photo "' + photo + '"is not valid' );
	  }

	sPhoto = photo;
	Photo[Photo.length] = new cPhoto( sGallery, photo, caption1, caption2, thb_name, med_name, for_sale );
	if ( sGallery != null )
		Gallery[getGalleryIndex(sGallery)].addPhoto( Photo.length - 1 );
	else
		alert( 'addPhoto error:  you forgot to use the addGallery function before specifying a photo.' );
}

// cPhoto: define cPhoto class

function cPhoto ( gallery_name, photo_name, caption1, caption2, thb_name, med_name, for_sale )
{
	this.gallery = gallery_name;
	this.name = photo_name;
	this.caption1 = caption1;
	this.caption2 = caption2;
	this.thb_name = new Array();
	for ( var i = 0; i < Theme.length; ++i )
		this.thb_name[i] = thb_name;
	this.med_name = new Array();
	for ( var i = 0; i < Theme.length; ++i )
		this.med_name[i] = med_name;
	this.for_sale = for_sale;
}
cPhoto.prototype.titleHTML = function ( buy_filename )
{
	if ( arguments.length == 0 )
		buy_filename = '';
	var sHTML = '';
	sHTML += this.caption1HTML();
	if ( (sForSale != '') && (this.for_sale == true) )
	  {
		sHTML += sBuyPhotoSeparator;
		if ( buy_filename )
			sHTML += '(<a href="' + buy_filename + '" onclick="oState.gotoPage(\'buy.html\');return(false);">buy&nbsp;photo</a>)';
	  }
	else
	  {
		sHTML += sLimitedSalesSeparator;
		sHTML += '<span class="limited" style="line-height:1;">(<span style="color:#c00; font-size:large; vertical-align:middle;">&#8226;</span>= limited sales of this image. <a href="help.html#limited_sales" onclick="oState.gotoPage(\'help.html#limited_sales\');return(false);">click here</a> for more info)</span>';
	  }
	return( sHTML );
}
cPhoto.prototype.caption1HTML = function ( )
{
	return( '<span class="photo_title">' + this.caption1 + '</span>' );
}
cPhoto.prototype.caption2HTML = function ( )
{
	return( '<span class="photo_description">' + this.caption2 + '</span>' );
}
cPhoto.prototype.forsaleHTML = function ( )
{
	if ( !sForSale )
		return( '' );
	if ( this.for_sale == true )
		return( sForSale );
	else
		return( sLimitedSales );
}
cPhoto.prototype.photoHTML = function ( img_options )
{
	var sHTML = '<img src="' + this.med_name[oState.nTheme] + '" ';
	if ( arguments.length > 0 )
		sHTML += img_options;
	sHTML += 'title="' + this.caption1 + '" alt="' + this.caption1 + '">';
	return( sHTML );
}
cPhoto.prototype.thumbHTML = function ( img_options )
{
	var sHTML = '<img src="' + this.thb_name[oState.nTheme] + '" ';
	if ( arguments.length > 0 )
		sHTML += img_options;
	sHTML += 'title="' + this.caption1 + '" alt="' + this.caption1 + '">';
	return( sHTML );
}

// getGalleryIndex:  get index into Gallery array for a specified gallery, or for current gallery if not specified

function getGalleryIndex( name )
{
	if ( (arguments.length == 0) && (oState.gallery != null) )
		name = oState.gallery;

	for ( var i = 0; i < Gallery.length; ++i )
	  {
		if ( Gallery[i].name == name )
			return( i );
	  }
	if ( (oState.testmode==1) )
		alert( 'getGalleryIndex error:  gallery ' + name + ' does not exist' );
	return( -1 );
}

function getFirstGallery ()
{
	return( Gallery[0].name );
}

function getLastGallery ()
{
	return( getPreviousGallery(Gallery[0].name) );
}

function getNextGallery ( gallery_name )
{
	if ( arguments.length == 0 )
		gallery_name = sGallery;
	var nGallery = getGalleryIndex( gallery_name );
	if ( nGallery == -1 )
		alert( 'getNextGallery error: gallery not found, ' + gallery_name );
	nGallery++;
	if ( nGallery >= Gallery.length )
		nGallery = 0;
	if ( (Gallery[nGallery].name == sHidden) && (oState.testmode!=1) )
		nGallery = 0;
	return( Gallery[nGallery].name );
}

function getPreviousGallery ( gallery_name )
{
	if ( arguments.length == 0 )
		gallery_name = sGallery;
	var nGallery = getGalleryIndex( gallery_name );
	if ( nGallery == -1 )
		alert( 'getPreviousGallery error: gallery not found, ' + gallery_name );
	nGallery--;
	if ( nGallery < 0 )
		nGallery = Gallery.length - 1;
	if ( (Gallery[nGallery].name == sHidden) && (oState.testmode!=1) )
		nGallery--;
	return( Gallery[nGallery].name );
}


// getObject: get object associated with an ID, or null if no object

function getObject ( id )
{
	var obj = null;
	if ( id == "" )
		return( null );
	if ( document.getElementById && (obj = document.getElementById(id)) )
		;
	else if ( document.all && (obj = document.all[id]) )
		;
	else /* DOM not supported, or no object */
		return( null );
	return( obj );
}

// getNamedFirstObject: get first object associated with a NAME, or null if no object

function getNamedFirstObject ( name )
{
	if ( name == "" )
		return( null );
	sArray = document.getElementsByName( name );
	if ( sArray.length == 0 )
		return( null );
	else
		return( sArray[0] );
}

// getPhotoIndex:  get index into Photo array for a specified gallery and photo

function getPhotoIndex( gallery, photo )
{
	var i;
	for ( i = 0; i < Photo.length; ++i )
	  {
		if ( (Photo[i].name == photo) && ((Photo[i].gallery == gallery) || (gallery == null)) )
			return( i );
	  }
	return( -1 );
}

// myGalleriaInsertPhoto: insert photo

function myGalleriaInsertPhoto ( name )
{
	var id = getPhotoIndex( sGallery, name );
	if ( id >= 0 )
		setArgPhoto( name );

	var obj_bigphoto = getObject( 'bigphoto' );
	if ( obj_bigphoto == null )
		return;

	var obj_fs = getObject( 'bigphoto_fs' );
	var obj_caption1 = getObject( 'caption1' );
	var obj_caption2 = getObject( 'caption2' );
	oBigPhoto = id;
	sCaption1 = '';
	sCaption2 = '';

	if ( name == null )
	  {
		alert( 'myGalleriaInsertPhoto: error, photo name not specified' );
		return;
//		if ( obj_fs != null )
//			obj_fs.src = sPhotoFolder + oState.imageFilename('ico_fs','png');
//		sCaption1 = sCaption2 = '';
//		myTriggerImage( sPhotoFolder + oState.imageFilename(sMedMessage,'png') );
	  }
	else
	  {
		var sBuyFilename = 'buy.html';
		if ( obj_fs != null )
			obj_fs.src = sPhotoFolder + (((sForSale != '') && (Photo[id].for_sale == true)) ? oState.imageFilename('ico_fs','png') : oState.imageFilename('ico_nfs','png'));
		if ( obj_caption1 != null )
		  {
			sCaption1 = Photo[id].titleHTML( sBuyFilename );
			if ( oState.size == 'small' )
				sCaption1 += '<br>&nbsp;<br>&nbsp;<span class="small">(you may need to scroll down to see all the gallery controls)</span>';
		  }
		if ( obj_caption2 != null )
			sCaption2 = Photo[id].caption2HTML();
		myTriggerImage( Photo[id].med_name[oState.nTheme] );
	  }
}

// myGalleriaInsertPhotoControls: insert photo controls

function myGalleriaInsertPhotoControls ( id, bLink )
{
	if ( arguments.length < 2 )
		bLink = true;
	if ( (typeof(bNavButtons) !== typeof(noSuchData)) && (bNavButtons) )
	  {
		var o = getObject( id );
		var sHTML = '';
		if ( bLink )
			sHTML += '<a href="index.html" onclick="oState.gotoPreviousPhoto(OrderedPhotos);return(false);">';
		sHTML += Photo[getPhotoIndex(sHidden,'but_prev_photo')].photoHTML( 'title="Go to previous photo" ' );
		if ( bLink )
			sHTML += '</a>';
		sHTML += '<span style="padding-left:20px; padding-right:20px;">&nbsp;</span>';
		if ( bLink )
			sHTML += '<a href="index.html" onclick="oState.gotoNextPhoto(OrderedPhotos);return(false);">';
		sHTML += Photo[getPhotoIndex(sHidden,'but_next_photo')].photoHTML( 'title="Go to next photo" ' );
		if ( bLink )
			sHTML += '</a>';
		if ( o )
			o.innerHTML = sHTML;
	  }
}


// myGalleriaModeGalleryList - set Galleries page gallery list mode
function myGalleriaModeGalleryList ( )
{
	var o = getObject( 'caption3a' );
	if ( o )
	  {
		o.innerHTML = 'this photograph is from the gallery&nbsp; <a href="index.html" onclick="oState.gotoPage(\'index.html\');return(false);">' + sGallery + '</a>';
	  }
	myInsertListOfGalleries( 'list', 'ins_thumbnails' );
}

// myGalleriaModeThumbnailList - switch to Galleries page thumbnail list mode
function myGalleriaThumbnailGalleryList ( gallery_name )
{
	if ( arguments.length < 1 )
		gallery_name = sGallery;
	oState.gotoPage( 'index.html', null, null, gallery_name );
}

// myGalleriaSetMenu - insert HTML for selection of image size and/or theme
function myGalleriaSetMenu ( )
{
	var sFilename = myGetFilename();
	myGalleriaSetImageSizeMenu( 'ins_size', sFilename );
	myGalleriaSetThemeMenu( 'ins_theme', sFilename );
	if ( oState.getGalleryModeState() )
	  {
		var o = getObject( 'galleries_link' );
		if ( o ) o.style.color = 'black';
	  }
}

function myGalleriaSetImageSizeMenu ( id, filename )
{
	if ( arguments.length < 2 )
		filename = myGetFilename();
	var oInsImageSize = getObject( id );
	if ( oInsImageSize )
	  {
		var sHTML = '<span class="prompt">image&nbsp;size:</span>&nbsp;';
		if ( oState.size == 'large' )
			sHTML += '<a href="' + filename + '" onclick="oState.gotoPage(\'' + filename + '\',\'small\');return(false);">small</a>&nbsp;<span class="current">large</span>';
		else // default is small
			sHTML += '<span class="current">small</span>&nbsp;<a href="' + filename + '" onclick="oState.gotoPage(\'' + filename + '\',\'large\');return(false);">large</a>';
		oInsImageSize.innerHTML = sHTML;
	  }
}

function myGalleriaSetThemeMenu ( id, filename )
{
	if ( arguments.length < 2 )
		filename = myGetFilename();
	var oInsTheme = getObject( id );
	if ( oInsTheme )
	  {
		var sHTML = '<span class="prompt">background:</span>&nbsp;';
		sHTML += Theme[oState.nTheme].selectHTML( filename, 'list' );
		oInsTheme.innerHTML = sHTML;
	  }
}

function myInsertCaption3 ( )
{
	var sHTML = '<p><span class="menu"><span><a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getPreviousGallery());return(false);">previous&nbsp;gallery</a></span>&nbsp; <span><a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getNextGallery());return(false);">next&nbsp;gallery</a></span></span></p><p class="current">';
	sHTML += 'view the <a href="index_map.html" onclick="oState.gotoPage(\'index_map.html\');return(false);">gallery&nbsp;map</a> or the <a href="index_list.html" onclick="oState.gotoPage(\'index_list.html\');return(false);">list&nbsp;of&nbsp;galleries</a></p>';
	var o = getObject( 'caption3' );
	if ( o ) o.innerHTML = sHTML;
}

function myInsertGalleryNameAndControls()
{
	var o = getObject( 'ins_galleryname' );
	var bInsertButtons = ( (typeof(bNavButtons) !== typeof(noSuchData)) && (bNavButtons) );
	var sHTML = '';
	if ( bInsertButtons )
	  {
		sHTML += '<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getPreviousGallery());return(false);" class="button" alt="Go to previous gallery" title="Go to previous gallery">' + Photo[getPhotoIndex(sHidden,'but_prev_gallery')].photoHTML('class="button" ') + '</a>&nbsp;&nbsp;';
	  }
	else
	  {
		sHTML = '<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getFirstGallery());return(false);" class="button" alt="Go to first gallery" title="Go to first gallery">&lt;&lt;</a>&nbsp;&nbsp;';
		sHTML += '<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getPreviousGallery());return(false);" class="button" alt="Go to previous gallery" title="Go to previous gallery">&lt;</a>&nbsp;&nbsp;';
	  }
	sHTML += '<span class="current">' + oState.gallery + '</span>';
	if ( bInsertButtons )
	  {
		sHTML += '&nbsp;&nbsp;<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getNextGallery());return(false);" class="button" alt="Go to next gallery" title="Go to next gallery">' + Photo[getPhotoIndex(sHidden,'but_next_gallery')].photoHTML('class="button" ') + '</a>';
	  }
	else
	  {
		sHTML += '&nbsp;&nbsp;<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getNextGallery());return(false);" class="button" alt="Go to next gallery" title="Go to next gallery">&gt;</a>';
		sHTML += '&nbsp;&nbsp;<a href="index.html" onclick="oState.gotoPage(\'index.html\',null,null,getLastGallery());return(false);" class="button" alt="Go to last gallery" title="Go to last gallery">&gt;&gt;</a>';
	  }
	if ( o ) o.innerHTML = sHTML;
}

function myInsertThumbnails ( id, gallery, columns, rows )
{
	if ( sThumbnailsDirection == 'horizontal' )
		return( myInsertThumbnailsHorizontal( id, 'galleries', gallery, columns, true ) );
	else
		return( myInsertThumbnailsVertical( id, 'galleries', gallery, columns, rows ) );
}

function myInsertThumbnailsHorizontal ( id, type, gallery, columns, blanks )
{
	var obj_ins_thumbnails = getObject( id );
	var i;
	var nColumn = 0;
	var nPhoto = 0;
	var nGallery = getGalleryIndex( gallery );
	var sHTML = '<table class="thumbnails" cellspacing="0">\n';
	for ( i = 0; i < Gallery[nGallery].photo.length; ++i )
	  {
		nPhoto = Gallery[nGallery].photo[i];
		if ( (blanks == false) && (Photo[nPhoto].name == '') )
			continue;
		if ( nColumn == 0 )
		  {
			if ( (i+1) >= Gallery[nGallery].photo.length )
				sHTML += '<tr class="lastrow"><td>';
			else
				sHTML += '<tr><td>';
		  }
		else
			sHTML += '<td>';
		if ( type == 'galleries' )
		  {
			sHTML += Photo[nPhoto].thumbHTML( sView + '="myGalleriaInsertPhoto(\'' + Photo[nPhoto].name + '\')"' );
			sHTML += Photo[nPhoto].forsaleHTML();
		  }
		else if ( type == 'map' )
		  {
			var sGalleryFilename = 'index.html';
			sHTML += '<span class="map_thumbnail"><a href="' + sGalleryFilename + '" onclick="oState.gotoPage(\'index.html\',null,null,\'' + Gallery[nGallery].name + '\',\'' + Photo[nPhoto].name + '\');return(false);">';
			sHTML += Photo[nPhoto].thumbHTML();
			sHTML += '<\/a>';
			sHTML += Photo[nPhoto].forsaleHTML();
			sHTML += '<\/span>';
		  }
		else
			alert( 'myInsertThumbnailsHorizontal error, type invalid: ' + type );
		sHTML += '</td>';
		if ( ++nColumn == columns )
		  {
			nColumn = 0;
			sHTML += '</tr>\n';
		  }
	  }
	if ( nColumn != 0 )
	  {
		for ( ; nColumn < columns; ++nColumn )
		  {
			sHTML += '<td>&nbsp;</td>';
		  }
		sHTML += '</tr>\n';
	  }
	sHTML += '</table>\n';
	if ( obj_ins_thumbnails == null )
		return( sHTML );
	obj_ins_thumbnails.innerHTML = sHTML;
	return( '' );
}

function myInsertThumbnailsVertical ( id, type, gallery, columns, rows )
{
	var obj_ins_thumbnails = getObject( id );
	var i, j, nRows, nPhoto;
	var nColumn = 0;
	var nGallery = getGalleryIndex( gallery );
	if ( Gallery[nGallery].photo.length > (rows * columns) )
		nRows = Math.ceil( Gallery[nGallery].photo.length/columns );
	else
		nRows = rows;

	var sHTML = '<table class="thumbnails" cellspacing="0">\n';
	OrderedPhotos.length = 0;
	for ( i = 0; i < nRows; ++i )
	  {
		if ( (i+1) >= nRows )
			sHTML += '<tr class="lastrow">';
		else
			sHTML += '<tr>';
		for ( j = 0; j < columns; ++j )
		  {
			sHTML += '<td>';
			nPhoto = i + j*nRows;
			if ( ((nPhoto+1) > Gallery[nGallery].photo.length) || (Photo[Gallery[nGallery].photo[nPhoto]].name == '') )
			  {
				sHTML += '&nbsp;';
			  }
			else
			  {
				OrderedPhotos[OrderedPhotos.length] = Photo[Gallery[nGallery].photo[nPhoto]].name;
				if ( type == 'galleries' )
				  {
					sHTML += Photo[Gallery[nGallery].photo[nPhoto]].thumbHTML( sView + '="myGalleriaInsertPhoto(\'' + Photo[Gallery[nGallery].photo[nPhoto]].name + '\')" ' );
					sHTML += Photo[Gallery[nGallery].photo[nPhoto]].forsaleHTML();
				  }
				else if ( type == 'map' )
				  {
					var sGalleryFilename = 'index.html';
					sHTML += '<span class="map_thumbnail"><a href="' + sGalleryFilename + '" onclick="oState.gotoPage(\'galleries.html\',null,null,\'' + Gallery[nGallery].name + '\',\'' + Photo[nPhoto].name + '\');return(false);">';
					sHTML += Photo[nPhoto].thumbHTML();
					sHTML += '<\/a>';
					sHTML += Photo[nPhoto].forsaleHTML();
					sHTML += '<\/span>';
				  }
				else
					alert( 'myInsertThumbnailsVertical error, type invalid: ' + type );
			  }
			sHTML += '</td>';
		  }
		sHTML += '</tr>';
	  }
	sHTML += '</table>';
	if ( obj_ins_thumbnails == null )
		return( sHTML );
	obj_ins_thumbnails.innerHTML = sHTML;
	return( '' );
}

// setPhotoNames: Set photo filenames for a photo

function setPhotoNames ( photo_name, theme, thb_name, med_name )
{
	if ( sPhoto == null )
		alert( 'setPhotoNames error:  you forgot the prior addPhoto function.' );
	if ( (arguments.length < 1) || ('' == photo_name) )
		photo_name = sPhoto;
	if ( arguments.length < 2 )
		theme = '-';
	if ( arguments.length < 3 )
		thb_name = '-';
	if ( arguments.length < 4 )
		med_name = '-';

	var nPhoto = getPhotoIndex( sGallery, photo_name );
	if ( nPhoto == -1 )
	  {
		alert( 'setPhotoNames error:  there is no photo named ' + photo_name );
		return( null );
	  }

	if ( theme == '-' )
	  {
		for ( var i = 0; i < Theme.length; ++i )
		  {
			setPhotoNames( photo_name, Theme[i].name, thb_name, med_name );
		  }
	  }
	else
	  {
		var nTheme = getThemeIndex( theme );
		if ( nTheme == -1 )
		  {
			alert( 'setPhotoNames error at photo ' + photo_name + ':  there is no theme named ' + theme );
		  }
		else
		  {
			if ( thb_name == '-' )
				Photo[nPhoto].thb_name[nTheme] = sPhotoFolder + sThumbPrefix + photo_name + Theme[nTheme].filename_suffix + sDefaultFiletype;
			else
				Photo[nPhoto].thb_name[nTheme] = sPhotoFolder + thb_name;
 			if ( med_name == '-' )
				Photo[nPhoto].med_name[nTheme] = sPhotoFolder + sPhotoPrefix + photo_name + Theme[nTheme].filename_suffix + sDefaultFiletype;
			else
				Photo[nPhoto].med_name[nTheme] = sPhotoFolder + med_name;
		  }
	  }

	return( nPhoto );
}


// Local functions ................... called from within this module only


function myCheckImageDone()
{
	var obj_bigphoto = getObject( 'bigphoto' );
	if ( obj_bigphoto == null )
		return;

	if ( objImage == null )
	  {
		; // do nothing
	  }
	if ( objImage.complete == true )
	  {
		if ( typeof(isTrulyIE5) === typeof(noSuchData) )
		  {
			if ( Photo[oBigPhoto].for_sale == true )
				obj_bigphoto.style.cursor = 'pointer';
			else
				obj_bigphoto.style.cursor = 'default';
		  }
		obj_bigphoto.style.width = objImage.width.toString() + 'px';
		obj_bigphoto.style.height = objImage.height.toString() + 'px';
		obj_bigphoto.style.backgroundColor = 'transparent';
		obj_bigphoto.style.backgroundImage = 'url(' + objImage.src + ')';
		obj_bigphoto.style.backgroundRepeat = 'no-repeat';
		obj_bigphoto.style.visibility = 'visible';
		var obj_captions = getObject( 'captions' );
		var obj_caption1 = getObject( 'caption1' );
		var obj_caption2 = getObject( 'caption2' );
		var nSizeOfPhotoIndent = (nBigPhotoColumnWidth - objImage.width)/2;
		if ( obj_captions != null )
			obj_captions.style.width = (objImage.width).toString() + 'px';
		 
		if ( obj_caption1 != null )
		  {
//			obj_caption1.style.width = (objImage.width).toString() + 'px';
//			obj_caption1.style.marginLeft = nSizeOfPhotoIndent.toString() + 'px';
			obj_caption1.innerHTML = sCaption1;
			obj_caption1.style.visibility = 'visible';
			sCaption1 = '';
		  }
		if ( obj_caption2 != null )
		  {
//			obj_caption2.style.width = (objImage.width).toString() + 'px';
//			obj_caption2.style.marginLeft = nSizeOfPhotoIndent.toString() + 'px';
			obj_caption2.innerHTML = sCaption2;
			obj_caption2.style.visibility = 'visible';
			sCaption1 = '';
		  }
		objImage = null;
	  }
	else
	  {
		setTimeout("myCheckImageDone()",10);
	  }
}

function myGetFilename ( pathname )
{	// Get filename portion of a pathname
	var sFilename;
	if ( (arguments.length == 0) || (pathname == null) )
		pathname = document.location.pathname;
	var nSlash = pathname.lastIndexOf( '/' );
	if ( nSlash == -1 )
		sFilename = pathname;
	else
		sFilename = pathname.substring(nSlash+1);
	nSlash = pathname.lastIndexOf( '\\' );
	if ( nSlash != -1 )
		sFilename = sFilename.substring(nSlash);
	return( sFilename );
}

function myTriggerImage( filename )
{
	objImage = new Image();
	objImage.src = filename;
	setTimeout("myCheckImageDone()",10);
}

function setFirstGallery( gallery )
{
	if ( arguments.length < 1 )
		alert( 'setFirstGallery error: you forgot to specify a gallery name' );
	sFirstGallery = gallery;
	var nGallery = getGalleryIndex( sFirstGallery );
	if ( nGallery == -1 )
		alert( 'setFirstGallery error: the gallery specified (' + sFirstGallery + ') does not exist.' );
}

function setArgImageSize ( image_size )
{
	oState.size = image_size;
	oState.saveState();
}

function setArgGallery ( gallery, photo )
{
	if ( arguments.length >= 2 )
		setArgPhoto( photo );
	oState.gallery = gallery;
	oState.saveState();
}

function setArgPhoto ( photo )
{
	oState.photo = photo;
	oState.saveState();
}

