#target bridge

/*-------------------------------------------------------------------------------------------------------------- 
	ADOBE SYSTEMS INCORPORATED
	Copyright 2006 - Adobe Systems Incorporated
	All Rights Reserved
	All Rights Reserved
 
	If this file is provided by Adobe in modifiable form (e.g., source code or JavaScript), then you may modify this file.  
	You may use and distribute this file, in modified or unmodified form, provided that you must reproduce the above
	acknowledgement and this notice with all copies of the file.
 
	THIS SOFTWARE IS PROVIDED BY ADOBE SYSTEMS INCORPORATED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, 
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ADOBE BE LIABLE TO YOU FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
	WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------------------------------*/

/* ContactSheet_ID_CS3.jsx
	Author: 		Bob Stucky
	Description:	Creates a Contact Sheet in InDesign
	Version:		2.0.0.12
	Dated:		11/15/2006
*/
/*  
@@@BUILDINFO@@@ ContactSheet_ID_CS3.jsx 2.0.0.12  1.0000  14-Nov-2006 
*/
$.level = 0;
if ( BridgeTalk.appName == "bridge" )  {
	ContactSheet = {};
	ContactSheet.strings = {};
	ContactSheet.enableFacingPagesCheckBox = true;

	//--------------------------------------------------------------------
	// COMMAND FUNCTIONS
	//--------------------------------------------------------------------
	ContactSheet.showDialog = function()  {
		var specifier = BridgeTalk.getSpecifier( "indesign-5.0" );
		if ( specifier == null ) {
			alert( localize( "$$$/WAS/ContactSheet/norunme=InDesign 5.0 (CS3) or higher must be installed for this feature to run" ) );
		    // Watson 1474388: don't proceed if ID not available
		    return;
		}
		try {
			//var files = WasLib.cullFolders( WasLib.getBridgeFiles() );
			// Watson 1463927: if it's not valid file type, don't attempt to place it. Filters out
			// most things that we don't want to be placing into InDesign. But not all- we probably want something
			// that spans PS + AI openable
			var files = WasLib.getBridgeFilesOnlyIgnoringFolders( WasLib.fileFilters.getValue( "Contact Sheet" ) );
			
			if ( !files || ( files.length == 0 ) ) {
				alert( localize( "$$$/WAS/ContactSheet/noFilesSelected1=No Files Selected" ) );
				return;
			}
			var d = ContactSheet.getDialog( ContactSheet.config, files );
//		  	var okClicked = d.show() == 1 ? true : false;
			d.show();
		} catch ( a ) {
			alert( a );
		}
	}
	ContactSheet.executeFromDialog = function( d ) {
		app.document.bringToFront();
		if ( true )  {
			try {
				ContactSheet.config.files = d.files;
				ContactSheet.config.rowCount = d.layoutGroup.rows.rows.text;
				ContactSheet.config.colCount = d.layoutGroup.columns.columns.text;
				ContactSheet.config.verticalGap = d.layoutGroup.vGap.edit.text;
				ContactSheet.config.horizontalGap = d.layoutGroup.hGap.edit.text;
				ContactSheet.config.removeFrames = "true";
				if ( ContactSheet.config.captionArray.length > 0 ) {
					ContactSheet.config.label = true;			
				} else {
					ContactSheet.config.label = false;
				}
				ContactSheet.config.place = d.layoutGroup.place.place.selection.text;
				if ( ContactSheet.config.rotation == ContactSheet.strings.Clockwise ) {
					ContactSheet.config.rotationValue = 270;
				} else {
					ContactSheet.config.rotationValue = 90;
				}
				ContactSheet.execute( ContactSheet.config ); 
			} catch ( e ) {
				alert( e ); 
			}
		}
	}
	ContactSheet.execute = function( config ) {
		var files = new Array();
		var captions = new Array();
		for ( var i = 0; i < config.files.length; i++ ) { // get rid of any Folder objects in the file array
			if ( File( encodeURI( config.files[ i ].fsName ) ) instanceof File ) {
				files.push( config.files[ i ] );
				captions.push( ContactSheet.parseCaption( config.files[ i ], config.captionArray, true ) );
			}
		}
		theScript = "var ContactSheet = {}; \n";
		theScript += "ContactSheet.strings = {}; \n";
		theScript += "ContactSheet.strings.accept = \"" + ContactSheet.strings.accept + "\";\n";
		theScript += "ContactSheet.strings.acrossFirst = \"" + ContactSheet.strings.acrossFirst + "\";\n";
		theScript += "ContactSheet.strings.frames = \"" + ContactSheet.strings.frames + "\";\n";
		theScript += "ContactSheet.strings.placing = \"" + ContactSheet.strings.placing + "\";\n";
		theScript += "ContactSheet.strings.complete = \"" + ContactSheet.strings.complete + "\";\n";
		theScript += "sendBackStatus( 1, ContactSheet.strings.accept ); \n";
		theScript += "$.level = 0; \n";
		theScript += "ContactSheet.config = {}; \n";
		theScript += "ContactSheet.config.files = eval( " + files.toSource() + " ); \n";
		theScript += "ContactSheet.config.captions = eval( " + captions.toSource() + " ); \n";
		var outputFile = "null";
		config.saveNewFile = false;
		if ( config.saveAsPDF ) {
			var f = new File( config.output );
			var f = f.getFileWithExtension( "pdf" );
			if ( f.exists ) {
				if ( !confirm( f.name + ContactSheet.strings.overwrite ) ) {
					alert( ContactSheet.strings.cancelledByUser );
					return;
				}
			}
			config.output = f;
			outputFile = config.output.toSource();
			theScript += "ContactSheet.config.output = eval( " + outputFile + " ); \n";
		} else {
			config.makeNewFile = true;
			theScript += "ContactSheet.config.output = null; \n";
		}
		if ( config.useTemplate ) {
			theScript += "ContactSheet.config.templateFile = eval( " + config.templateFile.toSource() + " ); \n";
		} else {
			theScript += "ContactSheet.config.templateFile = null; \n";
		}
		theScript += "ContactSheet.config.rotate = " + config.rotate + "; \n";
		theScript += "ContactSheet.config.rotation = " + parseInt( config.rotationValue ) + "; \n";
		theScript += "ContactSheet.config.PDFPreset = '" + config.PDFPreset + "'; \n";
		theScript += "ContactSheet.config.useTemplate = " + config.useTemplate + ";\n";
		theScript += "ContactSheet.config.saveAsPDF = " + config.saveAsPDF + ";\n";
		theScript += "ContactSheet.config.closeFile = " + config.closeFile + ";\n";
		theScript += "ContactSheet.config.grayBoxes = " + config.grayBoxes + ";\n";
		theScript += "ContactSheet.config.rowCount = " + parseInt( config.rowCount ) + "; \n";
		theScript += "ContactSheet.config.colCount = " + parseInt( config.colCount ) + "; \n";
		theScript += "ContactSheet.config.verticalGap = " + parseFloat( config.verticalGap ) + "; \n";
		theScript += "ContactSheet.config.overImages = " + config.overImages + "; \n";
		theScript += "ContactSheet.config.overImageGap = " + parseFloat( config.overImageGap ) + "; \n";
		theScript += "ContactSheet.config.horizontalGap = " + parseFloat( config.horizontalGap ) + "; \n";
		theScript += "ContactSheet.config.removeFrames = eval( '" + config.removeFrames + "' ); \n";
		theScript += "ContactSheet.config.label = " + config.label + "; \n";
		theScript += "ContactSheet.config.labelStyle = " + config.labelStyle + "; \n";
		theScript += "ContactSheet.config.caption = eval( " + config.caption.toSource() + " ); \n";
		theScript += "ContactSheet.config.autospace = " + config.autospace + "; \n";
		theScript += "ContactSheet.config.place = '" + config.place + "'; \n";
		theScript += "ContactSheet.config.pageSetup = {}; \n";
		theScript += "ContactSheet.config.pageSetup.units = '" + config.pageSetup.units + "'; \n";
		theScript += "ContactSheet.config.pageSetup.pageSize = '" + config.pageSetup.pageSize + "'; \n";
		theScript += "ContactSheet.config.pageSetup.width = " + parseFloat( config.pageSetup.width ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.height = " + parseFloat( config.pageSetup.height ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.facingPages = " + config.pageSetup.facingPages + "; \n";
		theScript += "ContactSheet.config.pageSetup.margins = {}; \n";
		theScript += "ContactSheet.config.pageSetup.margins.top = " + parseFloat( config.pageSetup.margins.top ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.margins.bottom = " + parseFloat( config.pageSetup.margins.bottom ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.margins.inside = " + parseFloat( config.pageSetup.margins.inside ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.margins.outside = " + parseFloat( config.pageSetup.margins.outside ) + "; \n";
		theScript += "ContactSheet.config.pageSetup.orientation = '" + config.pageSetup.orientation + "'; \n";
		theScript += "ContactSheet.margins = " + ContactSheet.margins.toString() + "\n";
		theScript += "ContactSheet.drawSheet = " + ContactSheet.drawSheet.toString() + "\n";
		theScript += "ContactSheet.drawSheet( ContactSheet.config );"
					
	// make things happen!
		try {
			// Last param "switchTargetOnCompletion"
			var bt = WasLib.BridgeTalkLongProcess.factory( true, ContactSheet.strings.generating, ContactSheet.strings.contactSheet, false,
			 "indesign-5.0", theScript, true );
			
			bt.send();
		} catch( e ) {
			alert( e );
		}
	}
			
		ContactSheet.drawSheet = function ( config ){
			var fpp = config.rowCount * config.colCount;
			var doc = null;
			if ( !ContactSheet.config.useTemplate ) {
				doc = app.documents.add();
			} else {
				doc = app.open( config.templateFile );
			}
			doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
			doc.viewPreferences.horizontalMeasurementUnits = eval( config.pageSetup.units );
			doc.viewPreferences.verticalMeasurementUnits = eval( config.pageSetup.units );
			config.inset = config.horizontalGap;
			if ( config.pageSetup.units.indexOf( "INCHES" ) > -1 ) {
				config.imageInset = 0.1;
				if ( config.verticalGap > .125 ) {
					config.minGap = .125;
				} else {
					config.minGap = 0;
				}
			} else {
				config.imageInset = ( 0.1 * 25.4 );
				if ( config.verticalGap > 3.175 ) {
					config.minGap = 3.175;
				} else {
					config.minGap = 0;
				}
			}
			
			if ( !config.useTemplate ) {
				doc.viewPreferences.horizontalMeasurementUnits = eval( config.pageSetup.units );
				doc.viewPreferences.verticalMeasurementUnits = eval( config.pageSetup.units );
				config.inset = config.horizontalGap;
				if ( doc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.millimeters ) {
					config.imageInset = 0.1;
					if ( config.verticalGap > .125 ) {
						config.minGap = .125;
					} else {
						config.minGap = 0;
					}
				} else {
					config.imageInset = ( 0.1 * 25.4 );
					if ( config.verticalGap > 3.175 ) {
						config.minGap = 3.175;
					} else {
						config.minGap = 0;
					}
				}
				var prefs = doc.documentPreferences;
				var totalFrames = config.files.length;
				var pageCount = Math.round( totalFrames / fpp );
				if ( ( pageCount * fpp ) < totalFrames ) {
					pageCount++; // handle round off error
				}
				prefs.facingPages = config.pageSetup.facingPages;
				if ( pageCount > doc.pages.length ) {
					prefs.pagesPerDocument = pageCount;
				}
				var page = doc.pages.item( 0 );
				var margins = page.marginPreferences;
				margins.left = config.pageSetup.margins.outside;
				margins.top = config.pageSetup.margins.top;
				margins.right = config.pageSetup.margins.inside;
				margins.bottom = config.pageSetup.margins.bottom;		
				prefs.pageWidth = config.pageSetup.width;
				prefs.pageHeight = config.pageSetup.height;
				
			} else {
				var prefs = doc.documentPreferences;
				config.inset = config.horizontalGap;
				if ( doc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.millimeters ) {
					config.imageInset = 0.1;
					if ( config.verticalGap > .125 ) {
						config.minGap = .125;
					} else {
						config.minGap = 0;
					}
				} else {
					config.imageInset = ( 0.1 * 25.4 );
					if ( config.verticalGap > 3.175 ) {
						config.minGap = 3.175;
					} else {
						config.minGap = 0;
					}
				}
				
				var totalFrames = config.files.length;
				var pageCount = Math.round( totalFrames / fpp );
				if ( ( pageCount * fpp ) < totalFrames ) {
					pageCount++; // handle round off error
				}
				if ( pageCount > doc.pages.length ) {
					prefs.pagesPerDocument = pageCount;
				}
				var page = doc.pages.item( 0 );
				var margins = page.marginPreferences;

			}
			wMargins = {};
			wMargins.top = margins.top + config.inset;
			wMargins.bottom = margins.bottom + config.inset;
			wMargins.left = margins.left + config.inset;
			wMargins.right = margins.right + config.inset;
	//		var workingWidth = 	prefs.pageWidth - ( margins.left + margins.right );
	//		var workingHeight = prefs.pageHeight - ( margins.top + margins.bottom );
			var workingWidth = 	prefs.pageWidth - ( wMargins.left + wMargins.right );
			var workingHeight = prefs.pageHeight - ( wMargins.top + wMargins.bottom );
			var colWidth = workingWidth / config.colCount;
			var frameWidth = ( workingWidth - ( ( config.colCount - 1 ) * config.horizontalGap ) ) / config.colCount;
			var rowHeight = workingHeight / config.rowCount;
			var frameHeight = rowHeight - config.verticalGap - config.minGap;
			var pages = doc.pages;
			
			var ltGrayCMYKColor = doc.colors.add( {model:ColorModel.process, colorValue:[0,0,0,15], name:"LightGrayCMYK"} );
			var dkGrayCMYKColor = doc.colors.add( {model:ColorModel.process, colorValue:[0,0,0,30], name:"DarkGrayCMYK"} );
			var CMYKblack = doc.colors.add( {model:ColorModel.process, colorValue:[0,0,0,100], name:"BlackCMYK"} );
		
			//Create the object layer and styles if they doesn't exist
			var objectLayer = doc.layers.item( 'objects' ); 
			try{ 
				objectLayer.name; 
			} 
			catch ( e ){ 
				objectLayer = doc.layers.add({name:'objects'}); 
			} 
		 	var imageFrameStyle = doc.objectStyles.item( 'imageFrames' );
		 	try {
		 		imageFrameStyle.name;
		 	} catch ( e ) {
		  		imageFrameStyle = doc.objectStyles.add( {name:'imageFrames'} );
		  		if ( config.grayBoxes ) {
			  		imageFrameStyle.fillColor = ltGrayCMYKColor;
			  		imageFrameStyle.strokeWeight = 0;
			  		imageFrameStyle.strokeColor = ltGrayCMYKColor;
		  		}
			}

			var imageStyle = doc.objectStyles.item('images'); 
			try{ 
				imageStyle.name; 
			} 
			catch ( e ){ 
				imageStyle = doc.objectStyles.add({name:'images'}); 
	//			imageStyle.enableDropshadowAndFeather = true;
		  		if ( config.grayBoxes ) {
					imageStyle.strokeColor = CMYKblack;
					imageStyle.strokeWeight = 0.5;
				}
			} 
		 	var captionObjectStyle = doc.objectStyles.item( 'captions' );
		  	try {
		  		captionObjectStyle.name;
		  	} catch ( e ) {
		  		captionObjectStyle = doc.objectStyles.add( {name:'captions'} );
		  		if ( config.grayBoxes ) {
			  		captionObjectStyle.fillColor = dkGrayCMYKColor;
			  		captionObjectStyle.strokeWeight = 0;
			  		captionObjectStyle.strokeColor = dkGrayCMYKColor;
		  		}
		  	}
			if ( config.grayBoxes ) {
		  		imageFrameStyle.fillColor = ltGrayCMYKColor;
		  		imageFrameStyle.strokeWeight = 0;
		  		imageFrameStyle.strokeColor = ltGrayCMYKColor;
		  		captionObjectStyle.fillColor = dkGrayCMYKColor;
		  		captionObjectStyle.strokeWeight = 0;
		  		captionObjectStyle.strokeColor = dkGrayCMYKColor;
				imageStyle.strokeColor = CMYKblack;
				imageStyle.strokeWeight = 0.5;
		  	}
			
			var labelStyle = null;
			var labelLayer = null;
			//Create the label paragraph style if it does not already exist. 
			labelStyle = doc.paragraphStyles.item('labels'); 
			try { 
				labelStyle.name; 
			} 
			catch ( e ) { 
				labelStyle = doc.paragraphStyles.add( {name:'labels'} );
				labelStyle.justification = Justification.centerAlign; 
			} 
			labelStyle.pointSize = 10; 
			//Create the label layer if it does not already exist. 
			var labelLayer = doc.layers.item('labels'); 
			try{ 
				labelLayer.name; 
			} 
			catch ( e ){ 
				labelLayer = doc.layers.add({name:'labels'}); 
			} 

			// set up for place by rows or colums
			var OLloop = config.rowCount;
			var ILloop = config.colCount;
			var OLp1 = 'wMargins.top + ( rowHeight * ( a - 1) )';
			var OLp2 = 'op1 + frameHeight';
			var ILp1 = 'facingPagesHack + ( colWidth * ( b - 1 ) )';
			var ILp2 = 'ip1 + frameWidth';
			var swatch = doc.swatches.item('None');
			//	var frameMaker = 'thisPage.rectangles.add( doc.layers.item(-1), undefined, undefined, { geometricBounds:[op1, ip1, op2, ip2], strokeWeight:0, strokeColor:swatch } )';
			var frameMaker = '[op1,ip1,op2,ip2]';
			if ( config.place != ContactSheet.strings.acrossFirst ) {
				OLloop = config.colCount;
				ILloop = config.rowCount;
				ILp1 = 'wMargins.top + ( rowHeight * ( b - 1) )';
				ILp2 = 'ip1 + frameHeight';
				OLp1 = 'facingPagesHack + ( colWidth * ( a - 1 ) )';
				//		OLp1 = 'margins.left + ( colWidth * ( a - 1 ) )';
				OLp2 = 'op1 + frameWidth';
				//		frameMaker = 'thisPage.rectangles.add( doc.layers.item(-1), undefined, undefined, { geometricBounds:[ip1, op1, ip2, op2], strokeWeight:0, strokeColor:swatch } )';
				frameMaker = '[ip1, op1, ip2, op2]';
			}
			// create frames 
			for ( var i = 0; i < doc.rectangles.length; i++ ) {
				doc.rectangles[ i ].label = '_CSScriptIgnore,_CSScriptHasContent';
			}
			sendBackStatus( 10, ContactSheet.strings.frames );
			RectSet = function( frame, image ) {
				this.frame = frame;
				this.image = image;
				this.hasContent = false;
			}
			var csRects = new Array();
			for ( var i = ( pages.length - 1 ); i >= 0; i--){  
				var thisPage = pages.item( i ); 
	//			var margins = thisPage.marginPreferences;
				var facingPagesHack = 0;
				if ( !config.useTemplate ) {
	//				margins.top = config.pageSetup.margins.top;
	//				margins.bottom = config.pageSetup.margins.bottom;
	//				margins.left = config.pageSetup.margins.inside;
	//				margins.right = config.pageSetup.margins.outside;
					if ( config.pageSetup.facingPages ) {
						if ( i%2 == 1 ) {
							facingPagesHack = config.pageSetup.margins.outside + config.inset;
						} else {
							facingPagesHack = config.pageSetup.margins.inside + config.inset;
						}
					} else {
						facingPagesHack = margins.left + config.inset;
					}
				} else {
					if ( doc.documentPreferences.facingPages ) {
						if ( i%2 == 1 ) {
							facingPagesHack = margins.right + config.inset;
						} else {
							facingPagesHack = margins.left + config.inset;
						}
					} else {
						facingPagesHack = margins.left;
					}
				}
				for ( var a = OLloop; a >= 1; a-- ) {  
					var op1 = eval( OLp1 );
					var op2 = eval( OLp2 );
					for ( var b = ILloop; b >= 1; b-- ) {  
						var ip1 = eval( ILp1 ); 
						var ip2 = eval( ILp2 );
						var thisRect = thisPage.rectangles.add( objectLayer );
						thisRect.move( undefined, ['1p', '1p'] );
						thisRect.geometricBounds = eval( frameMaker );
						var imageRect = thisPage.rectangles.add( objectLayer );
						imageRect.move( undefined, ['1p', '1p'] );
						var imageBounds = eval( frameMaker );
						imageBounds[ 0 ] += config.imageInset;
						imageBounds[ 1 ] += config.imageInset;
						imageBounds[ 2 ] -= config.imageInset;
						imageBounds[ 3 ] -= config.imageInset;
						imageRect.geometricBounds = imageBounds;
						var set = new RectSet( thisRect, imageRect );
						csRects.push( set );
					}
				}
			}
			// Because we constructed the frames in reverse order, rectangle 1  
			// is the first rectangle on page 1, so we can simply iterate through  
			// the rectangles, placing a file in each one in turn.
			csRects.reverse();
			var prog = 10;
			var inc = Math.round( 80 / config.files.length );
		 	var frameSkipper = 0;
			for ( var i = 0; i < config.files.length; i++){ 
				aFile = config.files[ i ];
				prog += inc;
		 		sendBackStatus( prog, decodeURI( aFile.name ), undefined, true, ContactSheet.strings.placing );
				var rSet = csRects[ i ];
				rSet.frame.applyObjectStyle( imageFrameStyle, true );
				var rect = rSet.image;	
				rect.applyObjectStyle( imageStyle, true );
				var graphic = rect.place( aFile )[ 0 ]; // change in CS3 - place takes array of files, and returns an array
				rSet.hasContent = true;
				var rHeight = rect.geometricBounds[2] - rect.geometricBounds[0];
				var rWidth = rect.geometricBounds[3] - rect.geometricBounds[1];
				var gHeight = graphic.geometricBounds[2] - graphic.geometricBounds[0];
				var gWidth = graphic.geometricBounds[3] - graphic.geometricBounds[1];	

				if ( config.rotate ) {
					if ( rWidth > rHeight ) {
						if ( gWidth < gHeight ) {
							graphic.absoluteRotationAngle = config.rotation;
						}
					} else {
						if ( gWidth > gHeight ) {
							graphic.absoluteRotationAngle = config.rotation;
						}
					}
				} 
				graphic.fit( FitOptions.proportionally );

				
/*
				if ( config.rotate ) {
					if ( rWidth > rHeight ) {
						if ( gWidth < gHeight ) {
							graphic.absoluteRotationAngle = config.rotation;
//							graphic.rotate( config.rotation );
							graphic.fit( FitOptions.fillProportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );
						} else {
							graphic.fit( FitOptions.proportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );				
						}
					} else {
						if ( gWidth > gHeight ) {
							graphic.absoluteRotationAngle = config.rotation;
//							graphic.rotate( config.rotation );
							graphic.fit( FitOptions.fillProportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );
						} else {
							graphic.fit( FitOptions.proportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );
						}
					}
				} else {
					if ( rWidth > rHeight ) {
						if ( gWidth < gHeight ) {
	//						graphic.rotate( config.rotation );
							graphic.fit( FitOptions.proportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );
						} else {
							graphic.fit( FitOptions.proportionally );
							graphic.fit( FitOptions.centerContent );
							graphic.fit( FitOptions.frameToContent );				
						}
					} else {
						graphic.fit( FitOptions.proportionally );
						graphic.fit( FitOptions.centerContent );
						graphic.fit( FitOptions.frameToContent );
					}
				}
*/
					//Add the label, if necessary.
				if( config.label ){ 
					var x1 = rSet.frame.geometricBounds[1]; 
					var y1 = rSet.frame.geometricBounds[2]; 
					var x2 = rSet.frame.geometricBounds[3]; 
					if ( config.overImages ) {
						var y2 = rSet.frame.geometricBounds[2] - config.overImageGap;
					} else {
						var y2 = rSet.frame.geometricBounds[2] + config.verticalGap; 
					}
					// caption code came from here
					var str = "";
					for ( var a = 0;  a < config.captions[ i ].length; a++ ) {
						if ( a > 0 ) {
							str += String.fromCharCode( 10 );
						}
						// Part of Watson 941662; we applied encodeURIComponent
						// to send the data over the wire via BridgeTalk, so reverse that encoding
						str += decodeURIComponent( config.captions[ i ][ a ] );
					}
					var tFrame = rect.parent.textFrames.add( labelLayer, undefined, undefined,{geometricBounds:[y1, x1, y2, x2], contents:str}); 
					tFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset; 
					tFrame.paragraphs.item( 0 ).appliedParagraphStyle = labelStyle; 
					tFrame.applyObjectStyle( captionObjectStyle, true );
				} 
			}
			if ( config.removeFrames ) {
				for ( i = 0; i < csRects.length; i++ ) {
					if ( !csRects[ i ].hasContent ) {
						csRects[ i ].image.remove();
						csRects[ i ].frame.remove()
					}
				}
		 	}
			//	app.viewPreference.rulerOrigin = saveVP;
		   if ( config.saveAsPDF ) {
				var PDFPreset = app.pdfExportPresets.item[ ContactSheet.config.PDFPreset ];
		 		sendBackStatus( 90, 'Exporting to PDF...');
				doc.exportFile( ExportFormat.pdfType, config.output, false, PDFPreset );
			}
			sendBackStatus( 100, ContactSheet.strings.complete );
		}
				
	ContactSheet.resetUI = function( dlg ) {
		WasLib.setupDropdown( dlg.layoutGroup.rotGroup.rotation, ContactSheet.rotation, ContactSheet.config.rotation );
		dlg.layoutGroup.rotGroup.rotation.enabled = ContactSheet.config.rotate;
		dlg.layoutGroup.rotGroup.rotate.value = ContactSheet.config.rotate;
		WasLib.setupDropdown( dlg.layoutGroup.place.place, ContactSheet.places, ContactSheet.config.place );
		dlg.layoutGroup.columns.columns.text = ContactSheet.config.colCount; 
		dlg.layoutGroup.rows.rows.text = ContactSheet.config.rowCount;
		dlg.layoutGroup.autoSpacing.value = ContactSheet.config.autospace;
		dlg.layoutGroup.hGap.edit.text = ContactSheet.config.horizontalGap;
		dlg.layoutGroup.vGap.edit.text = ContactSheet.config.verticalGap;
		dlg.layoutGroup.rotGroup.rotate.onClick();	
		dlg.layoutGroup.autoSpacing.onClick();
		dlg.layoutGroup.grayBoxes.value = ContactSheet.config.grayBoxes;

		dlg.captionGroup.overImages.value = ContactSheet.config.overImages;
		dlg.captionGroup.updateSample();

		dlg.templateGroup.useTemplate.value = ContactSheet.config.useTemplate;
		if ( ContactSheet.config.useTemplate ) {
			if (ContactSheet.config.templateFile ) {
				dlg.templateGroup.fileSpec.text = File.decode( ContactSheet.config.templateFile.fsName );
			} else {
				dlg.templateGroup.fileSpec.text = "";
				ContactSheet.config.useTemplate = false;
				dlg.templateGroup.useTemplate.value = false;
			}
		}


			
	}
	ContactSheet.getDialog = function( config, files )  {
		// first off, it helps to use "panel" objects instead of groups 
		// while you're actually working on a dialog. The panels are framed, and you can
		// see the actual grouping and alignment you are getting.
//		var dlg = new Window( "dialog", ContactSheet.strings.contactSheet );		
		var dlg = new Window( "palette", ContactSheet.strings.contactSheet );
		ContactSheet.dialog = dlg;
		dlg.files = files;
		dlg.orientation = "row"; 	// at the window level, I want two "groups", one to hold the 
								// all the "value entering" controls, and one to hold OK,CANCEL, etc
								// buttons in a vertical column on the right.
								
		dlg.alignChildren = "top"; 	// the default is center, you want both the value and button groups
									// at the top of the window
		
		dlg.val = dlg.add( "group" );	// this is the group that will hold all of the value stuff
		dlg.val.orientation = "column";
		
		dlg.btn = dlg.add( "group" );
		dlg.btn.orientation = "column";
		dlg.btn.spacing = 30; // in the button group, I want to have groups of buttons the first two will
							// always be OK, Cancel. But if you want to add a Page Setup, for example,
							// I want it to be an extra 10 pixels down from the Cancel button to differentiate
	
		dlg.presetPanel = dlg.val.add( "panel", undefined, localize( "$$$/WAS/ContactSeet/ui/presets=Presets" ) );
		dlg.presetPanel.orientation = "row";
		dlg.presetPanel.alignment = "fill";
		dlg.presetPanel.alignChildren = "left";
		dlg.presets = dlg.presetPanel.add( "dropdownlist" );
		// Watson 1467051- make fit for de_DE, as this looks widest
		dlg.presets.preferredSize.width = 165;
		dlg.savePresetBtn = dlg.presetPanel.add( "button", undefined, localize( "$$$/WAS/ContactSheet/ui/presetsSave=Save Settings" ) );
		dlg.removePresetBtn = dlg.presetPanel.add( "button", undefined, localize( "$$$/WAS/ContactSheet/ui/presetsRemove=Remove" ) );
		dlg.presetsFolder = new Folder( Folder.userData.absoluteURI + "/Adobe/Scripts/ContactSheet/Settings" );
		dlg.presetsFolder.verify();
		dlg.removePresetBtn.enabled = false;
		dlg.loadPresets = function() {
			var files = dlg.presetsFolder.getFiles( );
			this.presets.removeAll();
			if ( files.length == 0 ) {
				var item = this.presets.add( "item", localize( "$$$/WAS/ContactSheet/ui/presetsNoneToSel=None Saved" ) );
				item.selected = true;
				dlg.presets.enabled = false;
			} else {
				dlg.presets.enabled = true;
				var item = this.presets.add( "item", localize( "$$$/WAS/ContactSheet/ui/presetsSel=Select Preset" ) );
				item.selected = true;
				for ( var i in files ) {
					this.presets.add( "item", files[ i ].nameWithoutExtension() );
				}
			}
		}
		dlg.loadPresets();
		dlg.presets.onChange = function() {
			if ( this.selection ) {
				if ( this.selection.index > 0 ) {
					this.window.removePresetBtn.enabled = true;
					var file = new File( this.window.presetsFolder.absoluteURI + "/" + this.selection.text + ".jsx" );
					if ( file.exists ) {
						try {
							file.open( "r" );
							var buf = file.read();
							file.close();
							var settings = eval( buf );
							var files = ContactSheet.config.files;
							ContactSheet.config = settings;
							ContactSheet.config.files = files;
							ContactSheet.resetUI( this.window ); 
						} catch ( e ) {
						}
					}
				} else {
					this.window.removePresetBtn.enabled = false;
				}
			} else {
				this.window.removePresetBtn.enabled = false;
			}
		} 
		dlg.savePresetBtn.onClick = function() {

			var fName = prompt( localize( "$$$/WAS/ContactSheet/savePresetName=Enter a name for your preset" ) );
			if ( fName != null ) {
				var file = new File( dlg.presetsFolder.absoluteURI + "/" + fName + ".jsx"  );
				if ( file.exists ) {
					if ( !confirm ( fName + localize( "$$$/WAS/ContactSheet/presetExists= exists, overwrite?" ) ) ) {
						return;
					}
				}		
				file.open( "w" );
				file.write( ContactSheet.config.toSource() );
				file.close();
				this.window.loadPresets();
			}
		}
		dlg.removePresetBtn.onClick = function() {
			if ( this.window.presets.selection ) {
				if ( this.window.presets.selection.index > 0 ) {
					var file = new File( this.window.presetsFolder.absoluteURI +"/" +  this.window.presets.selection.text + ".jsx" );
					if ( file.exists ) {
						file.remove();
						this.window.loadPresets();
					}
				}
			}
		}
		
		dlg.layoutGroup = dlg.val.add( "panel", undefined, ContactSheet.strings.layout );
						// dlg.layoutGroup is the first visible element, a panel to hold the items common to layout
		dlg.layoutGroup.firstGroup = dlg.layoutGroup.add( "group" );
		dlg.layoutGroup.leftSideSubGroup = dlg.layoutGroup.firstGroup.add( "group" );
		
		dlg.layoutGroup.place = dlg.layoutGroup.leftSideSubGroup.add( "group" ); 
		dlg.layoutGroup.leftSideSubGroup.orientation = "column";		
		dlg.layoutGroup.leftSideSubGroup.alignChildren = "right";
		
		// Watson 1468420 dlg.layoutGroup.place.stat = dlg.layoutGroup.place.add( "statictext", undefined, ContactSheet.strings.place );
		dlg.layoutGroup.place.place = dlg.layoutGroup.place.add( "dropdownlist" );// note the repeating pattern here for
	//	dlg.layoutGroup.place.place.add( "item", ContactSheet.strings.acrossFirst);	// aligning captions with drop downs or edit boxes
	//	dlg.layoutGroup.place.place.add( "item", ContactSheet.strings.downFirst );     // the next two code sections are almost identical
		dlg.layoutGroup.place.place.preferredSize.width = 170; // Watson 1468420 100;
		dlg.layoutGroup.columns = dlg.layoutGroup.leftSideSubGroup.add( "group" );
		dlg.layoutGroup.columns.stat = dlg.layoutGroup.columns.add( "statictext", undefined, ContactSheet.strings.columns );
		dlg.layoutGroup.columns.columns = dlg.layoutGroup.columns.add( "edittext" );
		dlg.layoutGroup.columns.columns.preferredSize.width = 100;
		
		dlg.layoutGroup.rows = dlg.layoutGroup.leftSideSubGroup.add( "group" );
		dlg.layoutGroup.rows.stat = dlg.layoutGroup.rows.add( "statictext", undefined, ContactSheet.strings.rows );
		dlg.layoutGroup.rows.rows = dlg.layoutGroup.rows.add( "edittext" );
		dlg.layoutGroup.rows.rows.preferredSize.width = 100;



		dlg.layoutGroup.forAlignment = dlg.layoutGroup.firstGroup.add( "group" ); // analogous to dlg.layoutGroup.leftSideSubGroup
		dlg.layoutGroup.autoSpacing = dlg.layoutGroup.forAlignment.add( "checkbox", undefined, ContactSheet.strings.autoSpacing ); // here's the check box
		
//		dlg.layoutGroup.autoSpacing.alignment = "right";

		dlg.layoutGroup.forAlignment.alignChildren = "right";
		dlg.layoutGroup.forAlignment.orientation = "column";
			
		dlg.layoutGroup.hGap = dlg.layoutGroup.forAlignment.add( "group" ); //and another repeating pattern
		dlg.layoutGroup.hGap.stat = dlg.layoutGroup.hGap.add( "statictext", undefined, ContactSheet.strings.horizGap );
		dlg.layoutGroup.hGap.edit = dlg.layoutGroup.hGap.add( "edittext" );
		dlg.layoutGroup.hGap.edit.preferredSize.width = 75;
		
		dlg.layoutGroup.vGap = dlg.layoutGroup.forAlignment.add( "group" );
		dlg.layoutGroup.vGap.stat = dlg.layoutGroup.vGap.add( "statictext", undefined, ContactSheet.strings.vertGap );
		dlg.layoutGroup.vGap.edit = dlg.layoutGroup.vGap.add( "edittext" );
		dlg.layoutGroup.vGap.edit.preferredSize.width = 75;
		dlg.layoutGroup.alignChildren = "left";
		dlg.layoutGroup.alignment = "fill";

		
		dlg.layoutGroup.rotGroup = dlg.layoutGroup.add( "group" );
		dlg.layoutGroup.rotGroup.orientation = "row";
		dlg.layoutGroup.rotGroup.alignChildren = "center";
		dlg.layoutGroup.rotGroup.rotate = dlg.layoutGroup.rotGroup.add( "checkbox", undefined, ContactSheet.strings.rotateForBestFit );
		dlg.layoutGroup.rotGroup.rotation = dlg.layoutGroup.rotGroup.add( "dropdownlist" );
		
		dlg.layoutGroup.grayGroup = dlg.layoutGroup.add( "group" );
		dlg.layoutGroup.grayBoxes = dlg.layoutGroup.grayGroup.add( "checkbox", undefined, localize("$$$/WAS/ContactSheet/grayboxed=Use Gray Image Frames" ) );
		dlg.layoutGroup.grayBoxes.onClick = function() {
			ContactSheet.config.grayBoxes = this.value;
		}
		dlg.layoutGroup.rotGroup.rotate.onClick = function() {
			this.parent.rotation.enabled = this.value;
			ContactSheet.config.rotate = this.value;
		}	
		dlg.layoutGroup.rotGroup.rotation.onChange = function() {
			if ( this.selection ) {
				ContactSheet.config.rotation = this.selection.text;
			}
		}
		dlg.layoutGroup.place.place.onChange = function() {
			if ( this.selection ) {
				ContactSheet.config.place = this.selection.text;
			}
		}	
		
	// set up initial values
		WasLib.setupDropdown( dlg.layoutGroup.rotGroup.rotation, ContactSheet.rotation, ContactSheet.config.rotation );
		dlg.layoutGroup.rotGroup.rotation.enabled = ContactSheet.config.rotate;
		dlg.layoutGroup.rotGroup.rotate.value = ContactSheet.config.rotate;
		WasLib.setupDropdown( dlg.layoutGroup.place.place, ContactSheet.places, ContactSheet.config.place );
		dlg.layoutGroup.columns.columns.text = config.colCount;
		dlg.layoutGroup.rows.rows.text = config.rowCount;
		dlg.layoutGroup.autoSpacing.value = config.autospace;
		dlg.layoutGroup.hGap.edit.text = config.horizontalGap;
		dlg.layoutGroup.vGap.edit.text = config.verticalGap;
		dlg.layoutGroup.grayBoxes.value = ContactSheet.config.grayBoxes;
	// layoutGroup handlers
		dlg.layoutGroup.autoSpacing.onClick = function() {
			if ( dlg.layoutGroup.autoSpacing.value ) {
				dlg.layoutGroup.hGap.edit.enabled = false;
				dlg.layoutGroup.vGap.edit.enabled = false;
	//			dlg.captionGroup.getCaptionBoxes();
			} else {
				dlg.layoutGroup.hGap.edit.enabled = true;
				dlg.layoutGroup.vGap.edit.enabled = true;
			}
			ContactSheet.config.autospace = dlg.layoutGroup.autoSpacing.value;
		}
		dlg.layoutGroup.columns.columns.onChange = function() {
			if ( isNaN( parseInt( this.text ) ) ) {
				this.text = ContactSheet.config.colCount;
				alert( ContactSheet.strings.columnAlert );
			} else if ( parseInt( this.text ) <= 0 ) {
				this.text = ContactSheet.config.colCount;
				alert( ContactSheet.strings.columnAlertZero );
			} else {
				ContactSheet.config.colCount = parseInt( this.text );
				dlg.reportGroup.updateReport( );
			}
		}
		dlg.layoutGroup.rows.rows.onChange = function() {
			if ( isNaN( parseInt( this.text ) ) ) {
				this.text = ContactSheet.config.rowCount;
				alert( ContactSheet.strings.rowAlert );
			} else if ( parseInt( this.text ) <= 0 ) {
				this.text = ContactSheet.config.rowCount;
				alert( ContactSheet.strings.rowAlertZero );
			} else {
				ContactSheet.config.rowCount = parseInt( this.text );
				dlg.reportGroup.updateReport();
			}
		}
		dlg.layoutGroup.vGap.edit.onChange = function() {
			var units = ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.INCHES ? " in" : " mm";
			if ( isNaN( parseFloat( this.text ) ) ) {
				this.text = parseFloat( ContactSheet.config.verticalGap ) + units;
				alert( ContactSheet.strings.vertAlert );
			} else if ( parseFloat( this.text ) < 0 ) {
				this.text = parseFloat( ContactSheet.config.verticalGap ) + units;
				alert( ContactSheet.strings.vertAlertZero );
			} else  {
				this.text = parseFloat( this.text ) + units;
			}
		}
		dlg.layoutGroup.hGap.edit.onChange = function() {
			var units = ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.INCHES ? " in" : " mm";
			if ( isNaN( parseFloat( this.text ) ) ) {
				this.text = parseFloat( ContactSheet.config.horizontalGap ) + units;
				alert( ContactSheet.strings.horizAlert );
			} else if ( parseFloat( this.text ) < 0 ) {
				this.text = parseFloat( ContactSheet.config.horizontalGap ) + units;
				alert( ContactSheet.strings.horizAlertZero );
			} else {
				this.text = parseFloat( this.text ) + units;
			}
		}
		dlg.captionGroup = dlg.val.add( "panel", undefined, localize( "$$$/WAS/ContactSheet/panelNameCaption=Caption" ) ); // all check boxes in this panel, talk about simple...
		var cGroup = dlg.captionGroup.add( "group" );
		cGroup.alignment = "fill";
//		dlg.captionGroup.overImages = cGroup.add( "checkbox", undefined, ContactSheet.strings.placeOverImages );
		dlg.captionGroup.createButton = cGroup.add( "button", undefined, localize( "$$$/WAS/ContactSheet/createCp=Define..." ) );
		dlg.captionGroup.caption = dlg.captionGroup.add( "edittext", undefined, localize( "$$$/WAS/ContactSheet/noDefCp=No Caption Defined" ), { multiline:true, readonly:true} );
		dlg.captionGroup.caption.preferredSize.height = 60;
		dlg.captionGroup.caption.alignment = "fill";
//		dlg.captionGroup.overImages.value = ContactSheet.config.overImages;
//		dlg.captionGroup.caption.enabled = false;
		dlg.layoutTweaks = new Array();
		var tweak = {};
		tweak.toMove = dlg.captionGroup.createButton;
		tweak.moveTo = "dlg.captionGroup.caption.bounds.right";
		dlg.layoutTweaks.push( tweak );
		dlg.captionGroup.updateSample = function() {
			dlg.captionGroup.caption.text = ContactSheet.parseCaption( dlg.files[0], ContactSheet.config.captionArray, false );
			if ( dlg.layoutGroup.autoSpacing.value ) {
				if ( ContactSheet.config.captionArray.length == 0 ) {
					if ( ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.MILLIMETERS ) {
						dlg.layoutGroup.vGap.edit.text = ContactSheet.toMM( .125 ) + " mm";
						dlg.layoutGroup.hGap.edit.text = ContactSheet.toMM( .125 ) + " mm";
					} else {
						dlg.layoutGroup.hGap.edit.text = ".125 in";
						dlg.layoutGroup.vGap.edit.text = ".125 in";
					}
				} else {
					if ( ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.MILLIMETERS ) {
						if ( ContactSheet.config.overImages ) {
							dlg.layoutGroup.vGap.edit.text = ContactSheet.toMM( .125 ) + " mm";
							ContactSheet.config.overImageGap = ContactSheet.toMM( .25 * ContactSheet.config.captionArray.length );
						} else {
							dlg.layoutGroup.vGap.edit.text = ContactSheet.toMM( .25 * ContactSheet.config.captionArray.length ) + " mm";
							ContactSheet.config.overImageGap = ContactSheet.toMM( .25 * ContactSheet.config.captionArray.length );
						}
						dlg.layoutGroup.hGap.edit.text = ContactSheet.toMM( .125 ) + " mm";
					} else {
						dlg.layoutGroup.hGap.edit.text = ".125 in";
						if ( ContactSheet.config.overImages ) {
							dlg.layoutGroup.vGap.edit.text = ".125 in";
							ContactSheet.config.overImageGap = .25 * ContactSheet.config.captionArray.length;
						} else {
							dlg.layoutGroup.vGap.edit.text = .25 * ContactSheet.config.captionArray.length + " in";
							ContactSheet.config.overImageGap = .25 * ContactSheet.config.captionArray.length;
						}
					}
				}
			}
		}
	//	dlg.captionGroup.overImages.onClick = function() {
	//		ContactSheet.config.overImages = this.value;
	//	}
	//	dlg.captionGroup.overImages.value = ContactSheet.config.overImages;
		dlg.captionGroup.updateSample();
		dlg.captionGroup.createButton.onClick = function() {
			var captionDlg = ContactSheet.captionDialog( dlg );
			if ( captionDlg.show() == 1 ) { 
				ContactSheet.config.captionArray = eval( captionDlg.captionArray.toSource() );
				dlg.captionGroup.updateSample();
			}
		}
		dlg.captionGroup.alignChildren = "left";
		dlg.captionGroup.alignment = "fill";

		dlg.templateGroup = dlg.val.add( "panel", undefined, localize( "$$$/WAS/ContactSheet/templPanelText=Template" ) );
		dlg.templateGroup.alignment = "fill";
		dlg.templateGroup.btnGroup = dlg.templateGroup.add( "group" );
		dlg.templateGroup.btnGroup.alignment = "fill";
		dlg.templateGroup.useTemplate = dlg.templateGroup.btnGroup.add( "checkbox", undefined, localize( "$$$/WAS/ContactSheet/useIDTemplate=Use InDesign Template" ) );
		dlg.templateGroup.getTemplate = dlg.templateGroup.btnGroup.add( "button", undefined, localize( "$$$/WAS/ContactSheet/templButton=Pick Template..." ) );
		dlg.templateGroup.fileSpec = dlg.templateGroup.add( "edittext" );
		dlg.templateGroup.fileSpec.preferredSize = [300,20];
		dlg.templateGroup.fileSpec.alignment = "fill";
		dlg.templateGroup.useTemplate.fileSpecEdit = dlg.templateGroup.fileSpec;
		dlg.templateGroup.useTemplate.getTemplateButton = dlg.templateGroup.getTemplate;
		dlg.templateGroup.getTemplate.fileSpecEdit = dlg.templateGroup.fileSpec;
		var tweak = {};
		tweak.toMove = dlg.templateGroup.getTemplate;
		tweak.moveTo = "dlg.templateGroup.fileSpec.bounds.right";
		dlg.layoutTweaks.push( tweak );
		
		dlg.templateGroup.useTemplate.value = config.useTemplate;
		if ( ContactSheet.config.useTemplate ) {
			if (ContactSheet.config.templateFile ) {
				dlg.templateGroup.fileSpec.text = File.decode( ContactSheet.config.templateFile.fsName );
			} else {
				dlg.templateGroup.fileSpec.text = "";
				ContactSheet.config.useTemplate = false;
				dlg.templateGroup.useTemplate.value = false;
			}
		}
		dlg.isEmpty = function( stuff) {
			if ( !stuff ) { return true;}
			return ( stuff.length == 0 ) || ( stuff == "" );
		}
		dlg.templateGroup.useTemplate.onClick = function() {
			ContactSheet.config.useTemplate = this.value;
			this.fileSpecEdit.enabled = this.value;
			this.getTemplateButton.enabled = this.value;
			dlg.pageSetupGroup.pageSetup.enabled = !this.value;
			if ( this.value ) {
				if ( dlg.outputGroup.saveAsPDF.value ) {
					dlg.buttonGroup.okButton.enabled = !dlg.isEmpty( dlg.outputGroup.outputFile.text ) && !dlg.isEmpty( this.fileSpecEdit.text );
				} else {
					dlg.buttonGroup.okButton.enabled = !dlg.isEmpty( this.fileSpecEdit.text );
				}
			} else {
				if ( dlg.outputGroup.saveAsPDF.value ) {
					dlg.buttonGroup.okButton.enabled = !dlg.isEmpty( dlg.outputGroup.outputFile.text );
				} else {
					dlg.buttonGroup.okButton.enabled = true;
				}
			}
		}
		ContactSheet.checkMacFile = function( file ) {
			if ( file instanceof Folder ) {
				return true;
			} 
			return file.isFileType( "INDT,INDD," );
		}
		dlg.templateGroup.getTemplate.onClick = function() {
			if ( File.fs == "Windows" ) {
				var templateFile = File.openDialog( localize( "$$$/WAS/ContactSheet/selectTemplFile=Select the Template File" ), "InDesign Files:*.indt;*.indd" );
			} else {
				var templateFile = File.openDialog( localize( "$$$/WAS/ContactSheet/selectTemplFile=Select the Template File" ), ContactSheet.checkMacFile );			
			}
			if ( templateFile ) {
				this.fileSpecEdit.text = decodeURI( templateFile.fsName );
				ContactSheet.config.templateFile = templateFile;
				if ( dlg.outputGroup.saveAsPDF.value ) {
					dlg.buttonGroup.okButton.enabled = !dlg.isEmpty( dlg.outputGroup.outputFile.text );
				} else {
					dlg.buttonGroup.okButton.enabled = true;
				}
			} else {
				this.fileSpecEdit.text = "";
				dlg.buttonGroup.okButton.enabled = false;
				ContactSheet.config.templateFile = undefined;
			}
		}
		
		
		
		dlg.outputGroup = dlg.val.add( "panel", undefined, ContactSheet.strings.outputOptions );
		dlg.outputGroup.format = dlg.outputGroup.add( "group" );
		dlg.outputGroup.format.alignment = "fill";
		dlg.outputGroup.saveAsPDF = dlg.outputGroup.format.add( "checkbox", undefined, localize( "$$$/WAS/ContactSheet/saveAsPDFCkBox=Save As PDF" ) );	
		dlg.outputGroup.outputFileBtn = dlg.outputGroup.format.add( "button", undefined, ContactSheet.strings.OutputFile );
		dlg.outputGroup.outputFile = dlg.outputGroup.add( "edittext" );
		dlg.outputGroup.outputFile.alignment = "fill";
		dlg.outputGroup.alignment = "fill";
		dlg.outputGroup.orientation = "column";
		dlg.outputGroup.presetStat = dlg.outputGroup.add( "statictext", undefined, "                                                                    " );
		ContactSheet.presetStat = dlg.outputGroup.presetStat;
		var tweak = {};
		tweak.toMove = dlg.outputGroup.outputFileBtn;
		tweak.moveTo = "dlg.outputGroup.outputFile.bounds.right";
		dlg.layoutTweaks.push( tweak );

		dlg.outputGroup.saveAsPDF.outputEdit = dlg.outputGroup.outputFile;
		dlg.outputGroup.saveAsPDF.getOutputFileButton = dlg.outputGroup.outputFileBtn;
		dlg.outputGroup.saveAsPDF.onClick = function() {
			if ( this.value ) {
				ContactSheet.showPDFDialog();
			}
			ContactSheet.config.saveAsPDF = this.value;
			this.outputEdit.enabled = this.value;
			this.getOutputFileButton.enabled = this.value;
			if ( this.value ) {
				if ( dlg.templateGroup.useTemplate.value ) {
					dlg.buttonGroup.okButton.enabled = ( dlg.outputGroup.outputFile.text.length != 0 ) && ( dlg.templateGroup.fileSpec.text.length != 0 );
				} else {
					dlg.buttonGroup.okButton.enabled = ( dlg.outputGroup.outputFile.text.length != 0 );
				}
			} else {
				if ( dlg.templateGroup.useTemplate.value ) {
					dlg.buttonGroup.okButton.enabled = ( dlg.templateGroup.fileSpec.text.length != 0 );
				} else {
					dlg.buttonGroup.okButton.enabled = true;
				}
			}
		}
		ContactSheet.checkMacFilePDF = function( file ) {
			if ( file instanceof Folder ) {
				return true;
			}
			return file.isFileType( TYPES.PDF );
		}
		dlg.outputGroup.outputFileBtn.onClick = function() {
			if ( File.fs == "Windows" ) {
				var f = File.saveDialog( ContactSheet.strings.fileCaption,  "PDF Files:*.pdf" );
			} else {
				var f = File.saveDialog( ContactSheet.strings.fileCaption, ContactSheet.checkMacFilePDF );			
			}
	//		var f = File.openDialog( ContactSheet.strings.fileCaption );
			if ( f ) {
				dlg.outputGroup.outputFile.text = decodeURI( f.fsName );
				if ( dlg.templateGroup.useTemplate.value ) {
					dlg.buttonGroup.okButton.enabled = !dlg.isEmpty( dlg.templateGroup.fileSpec.text );
				} else {
					dlg.buttonGroup.okButton.enabled = true;
				}
				ContactSheet.config.output = f;
			} else {
				dlg.outputGroup.outputFile.text = "";
				dlg.buttonGroup.okButton.enabled = false;
				ContactSheet.config.output = undefined;
			}
		}
		
		
		// this is the OK/Cancel button group
		dlg.buttonGroup = dlg.btn.add( "group", undefined );
		dlg.buttonGroup.preferredSize.width = 100;
		dlg.buttonGroup.orientation = "column";
		dlg.buttonGroup.okButton = dlg.buttonGroup.add( "button", undefined, ContactSheet.strings.okButton );
		dlg.buttonGroup.okButton.window = dlg;
		dlg.buttonGroup.cancelButton = dlg.buttonGroup.add( "button", undefined, ContactSheet.strings.cancelButton );
		dlg.buttonGroup.cancelButton.window = dlg;
		dlg.buttonGroup.okButton.onClick = function() {
			this.window.close();
			ContactSheet.executeFromDialog( this.window );
		}
		dlg.buttonGroup.cancelButton.onClick = function() {
			this.window.close();
		}
		// this is a second button group with Page Setup and Files
		// because we set spacing to 30, this group will show up 30 pixels below the cancel button
		dlg.pageSetupGroup = dlg.btn.add( "group" );
		dlg.pageSetupGroup.pageSetup = dlg.pageSetupGroup.add( "button", undefined, ContactSheet.strings.pageSetupButton );
		// ipaterso this was preferredWidth? expected dlg.pageSetupGroup.preferredSize.width = 100;
		// line below fixes Watson 1435320- clipping of bottom of pagesetup button on Mac
		dlg.pageSetupGroup.preferredSize = [100,60];
		dlg.pageSetupGroup.orientation = "column";
				
		// in the reportGroup, I wanted to have everything lined up to a specific point. The captions right
		// justified, the values left. The longest caption determines the location of that point.
		// So I made two columnar groups, and put the captions and values in different columns.
		// This works because I have statictext in both columns. It Does NOT work in something like the layout panel
		// because the vertical sizes are different between edit boxes and statictext
		dlg.reportGroup = dlg.val.add( "panel", undefined, ContactSheet.strings.report );
		dlg.reportGroup.orientation = "row";
		dlg.reportGroup.spacing = 2;
		dlg.reportGroup.alignment = "fill";
		dlg.reportGroup.reportText = dlg.reportGroup.add( "group" );
		dlg.reportGroup.reportText.orientation = "column";
		dlg.reportGroup.reportValues = dlg.reportGroup.add( "group" );
		dlg.reportGroup.reportValues.orientation = "column";
		dlg.reportGroup.reportValues.spacing = 2;
		dlg.reportGroup.reportText.spacing = 2;
		// Watson 1435348
		dlg.reportGroup.reportText.alignChildren =  "left";
		dlg.reportGroup.reportValues.alignChildren = "fill";
		dlg.reportGroup.reportText.stat = dlg.reportGroup.reportText.add( "statictext", undefined, ContactSheet.strings.imagesSelected + ":        " );
		dlg.reportGroup.reportValues.images = dlg.reportGroup.reportValues.add( "statictext", undefined, "100" );
	//	dlg.reportGroup.reportValues.images.preferredSize = [40,13];
		dlg.reportGroup.reportText.stat = dlg.reportGroup.reportText.add( "statictext", undefined, ContactSheet.strings.imagesPerPage + ":       " );
		dlg.reportGroup.reportValues.imagesPerPage = dlg.reportGroup.reportValues.add( "statictext", undefined, "100" );
	//	dlg.reportGroup.reportValues.imagesPerPage.preferredSize = [40,13];
		dlg.reportGroup.reportText.stat = dlg.reportGroup.reportText.add( "statictext", undefined, ContactSheet.strings.pagesInSheet + ":        " );
		dlg.reportGroup.reportValues.pagesPerSheet = dlg.reportGroup.reportValues.add( "statictext", undefined, "100" );
	//	dlg.reportGroup.reportValues.pagesPerSheet.preferredSize = [40,13];
						
		dlg.reportGroup.updateReport = function( extend ) {
			var fileCount = 0;
			for ( var i = 0; i < dlg.files.length; i++ ) {
				if ( dlg.files[ i ] instanceof File ) {
					fileCount++
				}
			}
			var imagesPerPage = parseInt( dlg.layoutGroup.columns.columns.text ) * parseInt( dlg.layoutGroup.rows.rows.text );
			var pageCount = Math.round( fileCount / imagesPerPage );
			if ( ( pageCount * imagesPerPage ) < fileCount ) { 
				pageCount++; // handle round off error
			}
			var spacer = "";
			if ( extend ) {
				spacer = "              ";
			}
			dlg.reportGroup.reportValues.images.text = new String( fileCount ) + spacer;
			dlg.reportGroup.reportValues.imagesPerPage.text = imagesPerPage + spacer;
			dlg.reportGroup.reportValues.pagesPerSheet.text = pageCount + spacer;	
		}

		dlg.pageSetupGroup.pageSetup.onClick = function() {
			var d = ContactSheet.getPageSetupDialog( dlg.layoutGroup.vGap.edit, dlg.layoutGroup.hGap.edit );
		  	var okClicked = d.show() == 1 ? true : false;
			if ( okClicked )  {
				with ( ContactSheet.config.pageSetup ) {
					measurementUnits = d.units.selection.text;
					initialUnits = d.units.selection.text;
					ContactSheet.config.pageSetup.units = ContactSheet.measurementUnits.getValue( d.units.selection.text );
					pageSize = d.pageGroup.pageSize.selection.text;
					width = parseFloat( d.pageGroup.width.text );
					height = parseFloat( d.pageGroup.height.text );
					facingPages = d.pageGroup.facingPages.value;
					margins.top = parseFloat( d.marginGroup.top.text );
					margins.bottom = parseFloat( d.marginGroup.bottom.text );
					margins.inside = parseFloat( d.marginGroup.inside.text );
					margins.outside = parseFloat( d.marginGroup.outside.text );
					if ( d.pageGroup.portrait.value ) {
						orientation = ContactSheet.strings.orientPortrait;
					} else {
						orientation = ContactSheet.strings.orientLandscape;
					}
				}
			}
		}
// if you would like to modify the script for user specified file filters, here's the code
//		dlg.filterChangeCallback = function( name, filter ) {
//			ContactSheet.config.filterName = name;
//			ContactSheet.config.filter = filter;
//			ContactSheet.config.files = WasLib.cullFolders( WasLib.getBridgeFiles( ContactSheet.config.filter ) );
//		}
//		dlg.filterPanel = WasLib.fileFilterPanel( dlg.val, dlg.filterChangeCallback )
//		if ( ContactSheet.config.filterName != WasLib.theWordCustom ) {
//			dlg.filterPanel.setFilterName( ContactSheet.config.filterName );
//		} else {
//			dlg.filterPanel.setCustomFilter( ContactSheet.config.filter );
//		}
			
		dlg.layoutGroup.autoSpacing.onClick();
		dlg.templateGroup.useTemplate.onClick();
		dlg.outputGroup.saveAsPDF.onClick();
		
		dlg.reportGroup.updateReport( true );
		dlg.onShow = function() { // tweaks layout to make the buttons align left to each other - not possible in straight ScriptUI layout
			for ( var i in dlg.layoutTweaks ) {
				var txt = this.layoutTweaks[ i ].moveTo;
				var toPix = eval( txt );
				var obj = this.layoutTweaks[ i ].toMove;	
				var width = obj.bounds.right - obj.bounds.left;			
				obj.bounds.left = toPix - ( obj.bounds.right - obj.bounds.left ) - obj.parent.spacing - 5; // Watson 1468273
				obj.bounds.right = toPix - obj.parent.spacing - 5; 
			}
		}

		dlg.center();

		return dlg;
	}
	ContactSheet.loadCaptionPresets = function( list ) {
		ContactSheet.captionPresetsFolder
		var files = ContactSheet.captionPresetsFolder.getFiles( );
		list.removeAll();
		if ( files.length == 0 ) {
			var item = list.add( "item", localize( "$$$/WAS/ContactSheet/ui/presetsNone=No Saved Presets" ) );
			item.selected = true;
			list.enabled = false;
			list.window.removePresetBtn.enable = false;
		} else {
		var item = list.add( "item", localize( "$$$/WAS/ContactSheet/ui/presetsSel=Select Preset" ) );
		item.selected = true;
			for ( var i in files ) {
				list.add( "item", files[ i ].nameWithoutExtension() );
			}
			list.enabled = true;
		}
	}
	ContactSheet.captionDialog = function() {
		ContactSheet.captionDialog.refreshUI = function( dlg, captionArray ) {
			dlg.captionArray = captionArray;
			dlg.initList( captionArray );
			dlg.refreshSample();
			dlg.textBox.onChange();
			dlg.list.onChange();
		}
		ContactSheet.captionPresetsFolder = new Folder( Folder.userData.absoluteURI + "/Adobe/Scripts/ContactSheet/Captions" );
		ContactSheet.captionPresetsFolder.verify();
		ContactSheet.captionDialog.dataFile = new File( Folder.commonFiles + "/Adobe/Bridge CS3 Extensions/Adobe Workflow Automation/Resources/ContactSheet_ID.data" );
		if ( !ContactSheet.captionDialog.dataFile.exists ) { // initializes sample captions IF they have never been intialized before
			try {
				ContactSheet.captionDialog.strings = {};
				ContactSheet.captionDialog.strings.file = localize( "$$$/WAS/ContactSheet/cd/capFile=File: " );
				ContactSheet.captionDialog.strings.pixels = localize( "$$$/WAS/ContactSheet/cd/capPix=Pixels (x,y): " );
				ContactSheet.captionDialog.strings.fNumber = localize( "$$$/WAS/ContactSheet/cd/capFNumber=F: " );
				ContactSheet.captionDialog.strings.ExposureTime = localize( "$$$/WAS/ContactSheet/cd/capexp=Exposure: " );
				ContactSheet.captionDialog.strings.size = localize( "$$$/WAS/ContactSheet/cd/capsize=Size: " );
				ContactSheet.captionDialog.strings.focalLength = localize( "$$$/WAS/ContactSheet/cd/caplen=Focal Length: " );
				ContactSheet.captionDialog.strings.sample = localize( "$$$/WAS/ContactSheet/cd/capsamp=Sample" );
				
				ContactSheet.captionDialog.sample1 = [ContactSheet.captionDialog.strings.file + "<var filename>", ContactSheet.captionDialog.strings.pixels + "<var metadata[exif:PixelXDimension]>, <var metadata[exif:PixelYDimension]>"];
				ContactSheet.captionDialog.sample2 = [ContactSheet.captionDialog.strings.file + "<var filename>", ContactSheet.captionDialog.strings.pixels + "<var metadata[exif:PixelXDimension]>, <var metadata[exif:PixelYDimension]>", ContactSheet.captionDialog.strings.size + "<var filesize[M]>"];
				ContactSheet.captionDialog.sample3 = [ContactSheet.captionDialog.strings.file + "<var filename>", ContactSheet.captionDialog.strings.fNumber + "<var metadata[exif:FNumber]>, " + ContactSheet.captionDialog.strings.ExposureTime + "<var metadata[exif:ExposureTime]>", ContactSheet.captionDialog.strings.focalLength + "<var metadata[exif:FocalLength]>"];
				var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" + ContactSheet.captionDialog.strings.sample + " 1.jsx" );
				file.open( "w" );
				file.write( ContactSheet.captionDialog.sample1.toSource() );
				file.close();
				var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" + ContactSheet.captionDialog.strings.sample + " 2.jsx" );
				file.open( "w" );
				file.write( ContactSheet.captionDialog.sample2.toSource() );
				file.close();
				var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" + ContactSheet.captionDialog.strings.sample + " 3.jsx" );
				file.open( "w" );
				file.write( ContactSheet.captionDialog.sample3.toSource() );
				file.close();
				ContactSheet.captionDialog.dataFile.open( "w" );
				ContactSheet.captionDialog.dataFile.writeln( "ContactSheet Script loaded Once" );
				ContactSheet.captionDialog.dataFile.close();
			} catch ( e ) {
			}
		}
		
		var dlg = new Window( "dialog", localize( "$$$/WAS/ContactSheet/cd/dtitle=Create or Modify Caption" ) );
		dlg.orientation = "row";
		var g0 = dlg.add( "group" );
		var gb = dlg.add( "group" );
		gb.orientation = "column";
		gb.alignment = "fill";
		gb.alignChildren = "top";
		dlg.okBtn = gb.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/ok=OK" ) );
		dlg.cancelBtn = gb.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/cancel=Cancel" ) );
		dlg.okBtn.onClick = function() {
			this.window.close( 1 );
		}
		dlg.cancelBtn.onClick = function() {
			this.window.close( 2 );
		}
		g0.orientation = "column";
		var p0 = g0.add( "panel", undefined, localize( "$$$/WAS/ContactSheet/cd/presets=Presets" ) );
		p0.orientation = "row";
		p0.alignChildren = "left";
		p0.alignment = "fill";
		dlg.presetsList = p0.add( "dropdownlist" );
		// Watson 1467052
		dlg.presetsList.preferredSize.width = 165;
		dlg.savePresetBtn = p0.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/savep=Save Settings" ) );
		dlg.removePresetBtn = p0.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/removep=Remove" ) );
		ContactSheet.loadCaptionPresets( dlg.presetsList );
		dlg.savePresetBtn.onClick = function() {
			var fName = prompt( localize( "$$$/WAS/ContactSheet/savePresetName=Enter a name for your preset" ) );
			if ( fName != null ) {
				var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" + fName + ".jsx"  );
				if ( file.exists ) {
					if ( !confirm ( fName + localize( "$$$/WAS/ContactSheet/presetExists= exists, overwrite?" ) ) ) {
						return;
					}
				}
				file.open( "w" );
				file.write( this.window.captionArray.toSource() );
				file.close();
				ContactSheet.loadCaptionPresets( this.window.presetsList );
			}
		}
		dlg.removePresetBtn.onClick = function() {
			if ( this.window.presetsList.selection ) {
				if ( this.window.presetsList.selection.index > 0 ) {
					var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" + this.window.presetsList.selection.text + ".jsx" );
					if ( file.exists ) {
						file.remove();
						ContactSheet.loadCaptionPresets( this.window.presetsList );
					}
				}
			}
		}
		dlg.presetsList.onChange = function() {
			if ( this.selection ) {
				if ( this.selection.index > 0 ) {
					var file = new File( ContactSheet.captionPresetsFolder.absoluteURI + "/" +  this.window.presetsList.selection.text + ".jsx" );
					if ( file.exists ) {
						file.open( "r" );
						buf = file.read();
						file.close();
						var ar = eval( buf );
						this.window.captionArray = ar;
						ContactSheet.captionDialog.refreshUI( this.window, ar );
					}
				}
			}
		}
		var p1 = g0.add( "panel", undefined, localize( "$$$/WAS/ContactSheet/cd/defPanel=Caption Definition" ) );
		dlg.captionArray = eval( ContactSheet.config.captionArray.toSource() ); // clone the caption array so we don't change it unless OK is clicked
		p1.orientation = "column";
		p1.alignChildren = "left";
		var g2 = p1.add( "group" );
		g2.orientation = "row";
		g2.alignChildren = "left";
		dlg.up = g2.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/upBtn=Move Up" ) );
		dlg.down = g2.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/dnBtn=Move Down" ) );
		dlg.removeBtn = g2.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/removeBtn=Remove" ) );
		var g1 = p1.add( "group" );
		g1.alignChildren = "left";
		g1.orientation = "column";
		var g12 = g1.add( "group" );
		dlg.list = g12.add( "listbox" );
		dlg.list.preferredSize = [ 300, 90 ];
		var g3 = g1.add( "group" );
		dlg.textBox = g3.add( "edittext" );
		dlg.textBox.preferredSize = [ 300, 20 ];
		var g31 = g3.add( "group" );
		g31.orientation = "column";
		dlg.addBtn = g31.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/addBtn=Add" ) );
		dlg.updateBtn = g31.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/updateBtn=Update" ) );
		var g4 = p1.add( "group" );
		var st = g4.add( "statictext", undefined, localize( "$$$/WAS/ContactSheet/cd/stat=Select from the list:" ) );
		dlg.dropList = g4.add( "dropdownlist" );
		dlg.dropAddBtn = g4.add( "button", undefined, localize( "$$$/WAS/ContactSheet/cd/addBtn2=Add" )  );
		WasLib.setupDropdown( dlg.dropList, ContactSheet.captionSyntax, ContactSheet.strings.select );	
		var p2 = g0.add( "panel", undefined, localize( "$$$/WAS/ContactSheet/cd/samplePanel=Sample Caption" ) );
		p2.alignment = "fill";
		dlg.sample = p2.add( "edittext", undefined, undefined, { readonly:true, multiline:true } );
		dlg.sample.alignment = "fill";
		dlg.sample.preferredSize.height = 90;
		dlg.dropAddBtn.onClick = function() {
			if ( this.window.dropList.selection ) {
				var syntax = ContactSheet.captionSyntax.getValue( this.window.dropList.selection.text );
				if ( syntax == "select" ) { return; };
				if ( syntax == "metadata" ) {
					var md = ContactSheet.metadataUI();
					if ( md ) {
						syntax = "<var metadata[" + md + "]>";
					} else {
						return;
					}
				}
				this.window.textBox.textselection = syntax;
				this.window.textBox.onChange();
			}
		}
		dlg.list.onChange = function() {
			if ( this.selection ) {
				this.window.up.enabled = ( this.selection.index > 0 );
				this.window.down.enabled = ( this.selection.index < ( this.items.length -1 ) );
				this.window.removeBtn.enabled = true;
				this.window.textBox.text = this.selection.text;
				this.window.updateBtn.enabled = true;
			} else {
				this.window.up.enabled = false;
				this.window.down.enabled = false;
				this.window.removeBtn.enabled = false;
				this.window.updateBtn.enabled =false;
			}
			this.window.textBox.onChange();
		}
		dlg.up.onClick = function() {
			if ( this.window.list.selection ) {
				var ar = new Array();
				for ( var i = 0; i < this.window.list.items.length; i++ ) {
					if ( i <  ( this.window.list.selection.index - 1 ) ) {
						ar.push( this.window.list.items[ i ].text );
					} if ( i > this.window.list.selection.index ) {
						ar.push( this.window.list.items[ i ].text );
					} if ( i == ( this.window.list.selection.index - 1 ) ) {
						var savedI = ar.length;
						ar.push( this.window.list.selection.text );
						ar.push( this.window.list.items[ i ].text );
					}
				}
				this.window.initList( ar, savedI );
				this.window.captionArray = ar;
				this.window.list.onChange();
				this.window.refreshSample();
			}
		}
		dlg.initList = function( ar, sel ) {
			this.list.removeAll();
			for ( var i in ar ) {
				var item = this.list.add( "item", ar[ i ] );
				if ( sel != undefined ) {
					item.selected = ( i == sel );
				}
			}
		}
		dlg.down.onClick = function() {
			if ( this.window.list.selection ) {
				var ar = new Array();
				for ( var i = 0; i < this.window.list.items.length; i++ ) {
					if ( i <  this.window.list.selection.index  ) {
						ar.push( this.window.list.items[ i ].text );
					} else if ( i == this.window.list.selection.index ) {
						ar.push( this.window.list.items[ ( i + 1 ) ].text );
						ar.push( this.window.list.selection.text );
						var savedI = ar.length -1;
					} else if ( i > ( this.window.list.selection.index + 1 ) ) {
						ar.push( this.window.list.items[ i ].text );
					} 
				}
				this.window.initList( ar, savedI );
				this.window.captionArray = ar;
				this.window.list.onChange();
				this.window.refreshSample();
			}
		}
		dlg.removeBtn.onClick = function() {
			if ( this.window.list.selection ) {
				this.window.list.remove( this.window.list.selection.index ); 
				var ar = new Array();
				for ( var i = 0; i < this.window.list.items.length; i++ ) {
					ar.push( this.window.list.items[ i ].text );
				}
				this.window.captionArray = ar;
				this.window.initList( this.window.captionArray );
				this.window.refreshSample();
			}
		}
		dlg.textBox.onChange = function() {
			this.window.addBtn.enabled = ( this.text.length > 0 );
			try { 
		 		this.window.updateBtn.enabled = ( this.window.list.selection != undefined );
		 	} catch ( e ) {
		 		this.window.updateBtn.enabled = false;
		 	}
		}
		dlg.textBox.onChanging = function() {
			this.onChange();
		}
		dlg.updateBtn.onClick = function() {
			if ( this.window.list.selection ) {
				var a = this.window.list.selection.index;
				this.window.captionArray[ a ] = this.window.textBox.text;
				this.window.initList( this.window.captionArray, a );
				this.window.textBox.text = "";
				this.window.refreshSample();
			}
		}
		dlg.addBtn.onClick = function() {
			this.window.captionArray.push( this.window.textBox.text );
			this.window.initList( this.window.captionArray );
			this.window.textBox.text = "";
			this.window.refreshSample();
		}
		dlg.refreshSample = function() {
			var files = WasLib.getBridgeFilesOnlyIgnoringFolders( WasLib.fileFilters.getValue( "Contact Sheet" ) );
			if ( files.length == 0 ) {
				this.sample.text = localize( "$$$/WAS/ContactSheet/cd/nofileSelected=No Files Selected..." );
			} else if ( this.captionArray.length == 0 ) {
				this.sample.text = localize( "$$$/WAS/ContactSheet/cd/noCaptionDefined=No Caption Defined..." );
			} else {
				this.sample.text = ContactSheet.parseCaption( files[ 0 ], this.captionArray );
			}
		}
		dlg.init = function() {
			if ( this.captionArray ) {
				this.initList( this.captionArray );
				this.refreshSample();
			}
			dlg.textBox.onChange();
			dlg.list.onChange();
		}
		dlg.init();
		
		dlg.center();
		return dlg;
	}
	ContactSheet.parseCaption = function( file, captionArray, forId ) {
		var txt = "";
		var array = new Array();
		for ( var i in captionArray ) { 
			try {
				if ( forId ) {
				    // Watson 941662: \u is being translated to \\u at the target (ID), so make preventive encoding
					array.push( encodeURIComponent( ContactSheet.parseTemplate( file, captionArray[ i ] ) ) );
				} else {
					txt += ContactSheet.parseTemplate( file, captionArray[ i ] ) + "\n";
				}
			} catch ( e ) {
				txt += localize( "$$$/WAS/ContactSheet/cd/parseError=Error: " ) + e;
			}
		}
		if ( forId ) {
			return array;
		} else {
			return txt;
		}
	}
	ContactSheet.strings.illegalPathIndex = localize( "$$$/WAS/Lib3/illegalIndex=Illegal Path Index" );
	ContactSheet.strings.pathIndexOB = localize( "$$$/WAS/Lib3/pathIndexOB=Path index out of bounds" );
	ContactSheet.strings.supportedVariable = localize( "$$$/WAS/Lib3/unsupported=Unsupported renaming variable" );
	ContactSheet.strings.substringIndexError = localize( "$$$/WAS/CS/cd/sbsindxerr=Substring Index Error" );

	ContactSheet.parseTemplate = function( file, template )  {
		var s = template;
		var front = WasLib.getCharsBefore( s, "<var " );
		if ( front == s ) { // means there isn't another "<var..." statement
			return front;
		}
		var junk = WasLib.getCharsAfter( s, "<var " );
		var key = WasLib.trim( WasLib.getCharsBefore( junk, ">" ) );
		var back = WasLib.getCharsAfter( junk, ">" );
		if ( WasLib.startsWith( key, "filename" ) ) { 
			if ( file ) {
				name = decodeURI( file.name );
				var sub = WasLib.getCharsAfter( key, "[" );
				var sub = WasLib.getCharsBefore( sub, "]" );
				if ( ( sub.length ) == 0 || ( sub == "" ) ) {
					sub = "0";
				}
				if ( WasLib.getCharsBefore( sub, "," ) == sub ) {
					var sub0 = parseInt( sub );
					if ( isNaN( sub0 ) ) {
						throw ContactSheet.strings.substringIndexError;
					}
					name = name.substr( sub0 );
					
				} else {
					var sub0 = parseInt( WasLib.getCharsBefore( sub, "," ) );
					var sub1 = parseInt( WasLib.getCharsAfter( sub, "," ) );
					if ( isNaN( sub0 ) || isNaN( sub1 ) ) {
						throw ContactSheet.strings.substringIndexError;
					}
					name = name.substr( sub0, sub1 );
				}
			} else {
				var name = localize( "$$$/WAS/CSID/noFileSel=[No File(s) Selected]" );
			}
			s = front + name + back;
			return ContactSheet.parseTemplate( file, s );
		} else if (WasLib. startsWith( key, "date" ) ) {
			var fmt = WasLib.getCharsAfter( key, "[" );
			var fmt =WasLib.getCharsBefore( fmt, "]" );
			if ( file ) {
				s = front + new Date().format( fmt ) + back;
			} else {
				s = front + localize( "$$$/WAS/CSID/noFileSel1=[No File(s) Selected]" ) + back;
			}
			return ContactSheet.parseTemplate( file, s);				
		} else if ( WasLib.startsWith( key, "cdate" ) ) {
			var fmt = WasLib.getCharsAfter( key, "[" );
			var fmt = WasLib.getCharsBefore( fmt, "]" );
			if ( file ) {
				s = front + new Date( file.created ).format( fmt ) + back;
			} else {
				s = front + localize( "$$$/WAS/CSID/noFileSel2=[No File(s) Selected]" ) + back;
			}
			return ContactSheet.parseTemplate( file, s );		
		} else if ( WasLib.startsWith( key, "mdate" ) ) {
			var fmt = WasLib.getCharsAfter( key, "[" );
			var fmt = WasLib.getCharsBefore( fmt, "]" );
			if ( file ) {
				s = front + new Date( file.modified ).format( fmt ) + back;
			} else {
				s = front + localize( "$$$/WAS/CSID/noFileSel3=[No File(s) Selected]" ) + back;
			}
			return ContactSheet.parseTemplate( file, s );
		} else if ( WasLib.startsWith( key, "filesize" ) ) {
			var fmt = WasLib.getCharsAfter( key, "[" );
			var fmt = WasLib.getCharsBefore( fmt, "]" );
			var size = 0;
			if ( file ) {
				size = file.length;
			}
			var scale = "";
			if ( size/1000000 < 0.1 ) {
				fmt = "k"; //force to KB for files under 0.1 MB
			}
			if ( size/1000 > 9999 ) {
				fmt = "m" // force to MB for files 10MB or larger
			}

			if ( fmt.toLowerCase() == "k" ) {
				size = size/1000;
				scale = "KB";
			} else if ( fmt.toLowerCase() == "m" ) {
				size = size/1000000;
				scale = "MB";
			}
			size = Math.round( 10 * size )/10;
			s = front + size + " " + scale + back;
			return ContactSheet.parseTemplate( file, s );
		} else if ( WasLib.startsWith( key, "metadata" ) ) {
			var fmt = WasLib.getCharsAfter( key, "[" );
			var fmt = WasLib.getCharsBefore( fmt, "]" );
			var fmtElement = WasLib.getCharsAfter( fmt, ":" );
			var tn = new Thumbnail( file );
			var md = tn.synchronousMetadata;
			if ( !md ) {
				mData = localize( "$$$/WAS/lib3/mdNotAvail=[Metadata Not Available]" );
			} else {
				var mdElement = MdNs.elements.getValue( fmt );
				var mData =  undefined;
				if ( mdElement ) {
					mData =  mdElement.getValue( md );
				} else {
					mData =  localize( "$$$/WAS/lib3/badMDHandle=[Invalid Metadata Element]" );
				}
			}
			if ( !mData ) {
				mData = localize( "$$$/WAS/lib3/mdNotAvail2=[Metadata Not Available]" );
			}
			s = front + mData + back;
			return ContactSheet.parseTemplate( file, s );
		} 
	}

	ContactSheet.getPageSetupDialog = function( vGapControl, hGapControl )  {
		var dlg = new Window( "dialog", ContactSheet.strings.pageSetup ); 
		dlg.parentVerticalGapControl = vGapControl;
		dlg.parentHorizontalGapControl = hGapControl;
		dlg.orientation = "row";
		var contentGroup = dlg.add( "group" );
		var btnGroup = dlg.add( "group" );
		dlg.orientation = "row";
		dlg.alignChildren = "left";
		
		contentGroup.orientation = "column";
		contentGroup.alignChildren = "left";
		dlg.unitsGroup = contentGroup.add( "group" );
		dlg.unitsStat = dlg.unitsGroup.add( "statictext", undefined, ContactSheet.strings.units );
		dlg.unitsStat.justify = "right";	
		dlg.units = dlg.unitsGroup.add( "dropdownlist" );
		WasLib.setupDropdown( dlg.units, ContactSheet.measurementUnits, ContactSheet.config.pageSetup.measurementUnits );
		
		dlg.setVerticalGap = function() {
			if ( ContactSheet.config.autospace ) {
				if ( ContactSheet.config.caption.length == 0 ) {
					if ( ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.MILLIMETERS ) {
						dlg.parentHorizontalGapControl.text = ContactSheet.toMM( .125 ) + " mm";
						dlg.parentVerticalGapControl.text = ContactSheet.toMM( .125 ) + " mm";
					} else {
						dlg.parentHorizontalGapControl.text = ".125 in";
						dlg.parentVerticalGapControl.text = ".125 in";
					}
				} else {
					if ( ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.MILLIMETERS ) {
						dlg.parentHorizontalGapControl.text = ContactSheet.toMM( .125 ) + " mm";
						dlg.parentVerticalGapControl.text = ContactSheet.toMM( .25 * ContactSheet.config.caption.length ) + " mm";
					} else {
						dlg.parentHorizontalGapControl.text = ".125 in";
						dlg.parentVerticalGapControl.text = .25 * ContactSheet.config.caption.length + " in";
					}
				}
			} else {
				ContactSheet.convertControl( dlg.parentVerticalGapControl );
				ContactSheet.convertControl( dlg.parentHorizontalGapControl );
			}
		}
		dlg.units.onChange = function() {
			if ( dlg.units.selection ) {
				ContactSheet.config.pageSetup.measurementUnits = dlg.units.selection.text;
			}
			try {
				if ( !isNaN( parseFloat( dlg.pageGroup.width.text ) ) ) {
					ContactSheet.convertControl( dlg.pageGroup.width );
				}
				if ( !isNaN( parseFloat( dlg.pageGroup.height.text ) ) ) {
					ContactSheet.convertControl( dlg.pageGroup.height );
				}
				ContactSheet.convertControl( dlg.marginGroup.top );
				ContactSheet.convertControl( dlg.marginGroup.bottom );
				ContactSheet.convertControl( dlg.marginGroup.inside );
				ContactSheet.convertControl( dlg.marginGroup.outside );
				dlg.setVerticalGap();
			} catch ( e ) {
				alert( e );
			} finally {
				if ( dlg.units.selection ) {
					ContactSheet.config.pageSetup.initialUnits = dlg.units.selection.text;
				} else {
					ContactSheet.config.pageSetup.initialUnits = ContactSheet.config.pageSetup.measurementUnits;
				}
			}		
		}
		
		dlg.pageGroup = contentGroup.add( "panel", undefined, ContactSheet.strings.pageSize );
		dlg.pageGroup.alignment = "fill";
		dlg.pageGroup.orientation = "row";
		dlg.pageGroup.alignChildren = "right";

		dlg.pageGroup.left = dlg.pageGroup.add( "group" );
		dlg.pageGroup.left.orientation = "column";
		dlg.pageGroup.left.alignChildren = "right";
		
		dlg.pageGroup.left.pSize = dlg.pageGroup.left.add( "group" );
		// Watson 1468171
		// dlg.pageGroup.pageSizeStat = dlg.pageGroup.left.pSize.add( "statictext", undefined, ContactSheet.strings.pageSize );
		dlg.pageGroup.pageSize = dlg.pageGroup.left.pSize.add( "dropdownlist" );
		WasLib.setupDropdown( dlg.pageGroup.pageSize, ContactSheet.pageSizes, ContactSheet.config.pageSetup.pageSize );
		dlg.pageGroup.pageSize.preferredSize.width = 80; // Watson 1468171
		
		dlg.pageGroup.widthGroup = dlg.pageGroup.left.add( "group" );
		dlg.pageGroup.wStat = dlg.pageGroup.widthGroup.add( "statictext", undefined, ContactSheet.strings.pageWidth );
		dlg.pageGroup.wStat.justify = "right";
		dlg.pageGroup.width = dlg.pageGroup.widthGroup.add( "edittext" );
		dlg.pageGroup.width.preferredSize = [80,20];

		dlg.pageGroup.heightGroup = dlg.pageGroup.left.add( "group" );
		dlg.pageGroup.heightGroup.alignChildren = "right";
		dlg.pageGroup.hStat = dlg.pageGroup.heightGroup.add( "statictext", undefined, ContactSheet.strings.pageHeight );
		dlg.pageGroup.hStat.justify = "right";	
		dlg.pageGroup.height = dlg.pageGroup.heightGroup.add( "edittext" );
		dlg.pageGroup.height.preferredSize = [80,20];

		dlg.pageGroup.right = dlg.pageGroup.add( "group" );
		dlg.pageGroup.right.orientation = "column";
		dlg.pageGroup.right.alignChildren = "left";
		dlg.pageGroup.portrait = dlg.pageGroup.right.add( "radiobutton", undefined, ContactSheet.strings.portrait );
		dlg.pageGroup.landscape = dlg.pageGroup.right.add( "radiobutton", undefined, ContactSheet.strings.landscape );
		
		if ( ContactSheet.config.pageSetup.orientation == ContactSheet.strings.orientPortrait ) {
			dlg.pageGroup.portrait.value = true;
		} else {
			dlg.pageGroup.landscape.value = true;
		}
		dlg.pageGroup.currentOrientation = ContactSheet.config.pageSetup.orientation;
		dlg.pageGroup.width.text = ContactSheet.config.pageSetup.width;
		dlg.pageGroup.width.savedValue = ContactSheet.config.pageSetup.width;
		dlg.pageGroup.height.text = ContactSheet.config.pageSetup.height;
		dlg.pageGroup.height.savedValue = ContactSheet.config.pageSetup.height;
		dlg.pageGroup.height.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		dlg.pageGroup.width.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		
		dlg.pageGroup.portrait.onClick = function() {
			if ( dlg.pageGroup.currentOrientation == ContactSheet.strings.orientLandscape ) {
				var h = dlg.pageGroup.height.text;
				var w = dlg.pageGroup.width.text;
				dlg.pageGroup.height.text = w;
				dlg.pageGroup.width.text = h;	
			}
			dlg.pageGroup.currentOrientation = ContactSheet.strings.orientPortrait;
	//		dlg.pageGroup.setPageDimensions();
		}
		dlg.pageGroup.landscape.onClick = function() {
			if ( dlg.pageGroup.currentOrientation == ContactSheet.strings.orientPortrait ) {
				var h = dlg.pageGroup.height.text;
				var w = dlg.pageGroup.width.text;
				dlg.pageGroup.height.text = w;
				dlg.pageGroup.width.text = h;	
			}
			dlg.pageGroup.currentOrientation = ContactSheet.strings.orientLandscape;
	//		dlg.pageGroup.setPageDimensions();
		}
		dlg.pageGroup.pageSize.onChange = function() {
			dlg.pageGroup.setPageDimensions();
		}
		dlg.pageGroup.setPageDimensions = function() {
			var sel = ContactSheet.strings.pageSizeLetter;
			if ( dlg.pageGroup.pageSize.selection ) {
				var sel = dlg.pageGroup.pageSize.selection.text;
			}
			var	dim = ContactSheet.pageSizes.getValue( sel );
			if ( dim ) {
				var h = dim.horizontal;
				var v = dim.vertical;
				if ( dlg.pageGroup.landscape.value ) {
						var h = dim.vertical;
					var v = dim.horizontal;
				}
				if ( dim.units == ContactSheet.strings.MILLIMETERS ) {
					if ( ContactSheet.config.pageSetup.initialUnits != ContactSheet.strings.MILLIMETERS ) {
						dlg.units.selection = 1;
						ContactSheet.config.pageSetup.measurementUnits = ContactSheet.strings.MILLIMETERS;
						dlg.units.onChange();
					}
				} else {
					if ( ContactSheet.config.pageSetup.initialUnits != ContactSheet.strings.INCHES ) {
						dlg.units.selection = 0;
						ContactSheet.config.pageSetup.measurementUnits = ContactSheet.strings.INCHES;
						dlg.units.onChange();
					}
				}
				dlg.pageGroup.height.text = v;
				dlg.pageGroup.width.text = h;
				dlg.pageGroup.width.savedValue = h;
				dlg.pageGroup.height.savedValue = v;
				dlg.pageGroup.height.savedUnits = ContactSheet.config.pageSetup.measurementUnits;
				dlg.pageGroup.width.savedUnits = ContactSheet.config.pageSetup.measurementUnits;
				
			}	
		}
		dlg.pageGroup.facingPages = dlg.pageGroup.left.add( "checkbox", undefined, ContactSheet.strings.facingPages );
		dlg.pageGroup.facingPages.value = ContactSheet.config.pageSetup.facingPages;
	//	dlg.pageGroup.facingPages.value = false;
	//	dlg.pageGroup.facingPages.visible = false;
	// Note, ContactSheet.enableFacingPagesCheckBox is set in line 25 to make turning
	// this on and off easier while the ID bug exists
		dlg.pageGroup.facingPages.enabled = ContactSheet.enableFacingPagesCheckBox;
		dlg.pageGroup.facingPages.onClick = function() {
			if ( dlg.pageGroup.facingPages.value ) {
				dlg.marginGroup.iStat.text = ContactSheet.strings.insideMargin + ":";
				dlg.marginGroup.oStat.text = ContactSheet.strings.outsideMargin + ":";
			} else {
				dlg.marginGroup.iStat.text = "      " + ContactSheet.strings.leftMargin + ":";
				dlg.marginGroup.oStat.text = "      " + ContactSheet.strings.rightMargin + ":";
			}
		}
		
		dlg.marginGroup = contentGroup.add( "panel",undefined, ContactSheet.strings.margins );
		dlg.marginGroup.alignment = "fill";
		dlg.marginGroup.orientation = "row";
		dlg.marginGroup.leftGroup = dlg.marginGroup.add( "group" );
		dlg.marginGroup.leftGroup.orientation = "column";
		dlg.marginGroup.leftGroup.alignChildren = "right";
		
		dlg.marginGroup.topGroup = dlg.marginGroup.leftGroup.add( "group" );
		dlg.marginGroup.tStat = dlg.marginGroup.topGroup.add( "statictext", undefined, ContactSheet.strings.topMargin + ":" );
		dlg.marginGroup.tStat.justify = "right";
		dlg.marginGroup.top = dlg.marginGroup.topGroup.add( "edittext" );
		dlg.marginGroup.top.preferredSize = [80,20];
		dlg.marginGroup.top.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		dlg.marginGroup.top.savedValue = ContactSheet.config.pageSetup.margins.top;


		dlg.marginGroup.botGroup = dlg.marginGroup.leftGroup.add( "group" );
		dlg.marginGroup.bStat = dlg.marginGroup.botGroup.add( "statictext", undefined, ContactSheet.strings.bottomMargin + ":" );
		dlg.marginGroup.bStat.justify = "right";
		dlg.marginGroup.bottom = dlg.marginGroup.botGroup.add( "edittext" );
		dlg.marginGroup.bottom.preferredSize = [80,20];
		dlg.marginGroup.bottom.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		dlg.marginGroup.bottom.savedValue = ContactSheet.config.pageSetup.margins.bottom;
		
		dlg.marginGroup.rightGroup = dlg.marginGroup.add( "group" );
		dlg.marginGroup.rightGroup.orientation = "column";
		dlg.marginGroup.rightGroup.alignChildren = "right";
		dlg.marginGroup.inGroup = dlg.marginGroup.rightGroup.add( "group" );
		dlg.marginGroup.iStat = dlg.marginGroup.inGroup.add( "statictext", undefined, ContactSheet.strings.insideMargin + ":" );
		dlg.marginGroup.iStat.justify = "right";
		dlg.marginGroup.inside = dlg.marginGroup.inGroup.add( "edittext" );
		dlg.marginGroup.inside.preferredSize = [80,20];
		dlg.marginGroup.inside.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		dlg.marginGroup.inside.savedValue = ContactSheet.config.pageSetup.margins.inside;

		
		dlg.marginGroup.outGroup = dlg.marginGroup.rightGroup.add( "group" );
		dlg.marginGroup.oStat = dlg.marginGroup.outGroup.add( "statictext", undefined, ContactSheet.strings.outsideMargin + ":" );
		dlg.marginGroup.oStat.justify = "right";
		dlg.marginGroup.outside = dlg.marginGroup.outGroup.add( "edittext" );
		dlg.marginGroup.outside.preferredSize = [80,20];
		dlg.marginGroup.outside.savedUnits =  ContactSheet.config.pageSetup.measurementUnits;
		dlg.marginGroup.outside.savedValue = ContactSheet.config.pageSetup.margins.outside;
		
		
		dlg.pageGroup.facingPages.onClick();
		dlg.marginGroup.top.text = ContactSheet.config.pageSetup.margins.top;
		dlg.marginGroup.bottom.text = ContactSheet.config.pageSetup.margins.bottom;
		dlg.marginGroup.inside.text = ContactSheet.config.pageSetup.margins.inside;
		dlg.marginGroup.outside.text = ContactSheet.config.pageSetup.margins.outside;

		dlg.goodToClose = true;
		dlg.closeTime = new Date();

		dlg.validateNumber = function( control, min, max ) {
			if ( isNaN( parseFloat( control.text ) ) ) {
				control.text = control.savedValue;
	//			alert( str + " " + ContactSheet.strings.mustBeNumber );
		dlg.goodToClose = false;
		dlg.closeTime = new Date();
					ContactSheet.convertControl( control );
					
					return false;
			}
			if ( min ) {
				if ( parseFloat( control.text ) < min ) {
					control.text = control.savedValue;
					ContactSheet.convertControl( control );
	//				alert( str + " " + ContactSheet.strings.mustBeGreaterThan + " " + min );
		dlg.goodToClose = false;
		dlg.closeTime = new Date();
					return false;
				}
			}
			if ( max ) {
				if ( parseFloat( control.text ) > max ) {
					control.text = control.savedValue;
					ContactSheet.convertControl( control );
	//				alert( str + " " + ContactSheet.strings.mustBeLessThan + " " + max );
		dlg.goodToClose = false;
		dlg.closeTime = new Date();
					return false;
				}
			}
	//		alert( "ret: " + ret );
			ContactSheet.convertControl( control );
		dlg.goodToClose = true;
			return true;
		}
		dlg.marginGroup.top.onChange = function() {
			dlg.validateNumber( this, 0, parseFloat( dlg.pageGroup.height.text ) );
		}
		dlg.marginGroup.bottom.onChange = function() {
			dlg.validateNumber( this, 0,  parseFloat( dlg.pageGroup.height.text ) );
		}
		dlg.marginGroup.inside.onChange = function() {
			dlg.validateNumber( this, 0,  parseFloat( dlg.pageGroup.width.text ) );
		}
		dlg.marginGroup.outside.onChange = function() {
			dlg.validateNumber( this, 0,  parseFloat( dlg.pageGroup.width.text ) );
		}
		dlg.pageGroup.width.onChange = function() {
			var min = 0.1667;
			var max = 216;
			if ( ContactSheet.config.pageSetup.measurementUnits != ContactSheet.strings.INCHES ) {
				min = ContactSheet.toMM( min );
				max = ContactSheet.toMM( max );
			}
			dlg.validateNumber( this, min , max );
		}
		dlg.pageGroup.height.onChange = function() {	
			var min = 0.1667;
			var max = 216;
			if ( ContactSheet.config.pageSetup.measurementUnits != ContactSheet.strings.INCHES ) {
				min = ContactSheet.toMM( min );
				max = ContactSheet.toMM( max );
			}
			dlg.validateNumber( this, min, max );
		}

		dlg.onClose = function() {
			var temp = dlg.goodToClose;
			if ( !temp ) {
				var t = new Date();
				temp = ( ( t - dlg.closeTime ) > 250 );
			}
			dlg.goodToClose = true;
			return temp;
		}
		dlg.pageGroup.setPageDimensions();
		
		dlg.okBtnGroup = dlg.add( "group" );
		dlg.okBtnGroup.orientation = "column";
		dlg.okBtnGroup.okBtn = dlg.okBtnGroup.add( "button", undefined, ContactSheet.strings.okButton );
		dlg.okBtnGroup.okBtn.enabled = true;
		dlg.okBtnGroup.cancelBtn = dlg.okBtnGroup.add( "button", undefined, ContactSheet.strings.cancelButton );
		dlg.okBtnGroup.cancelBtn.onClick = function() {
			dlg.close( 2 ); 
		}
		dlg.okBtnGroup.okBtn.onClick = function() {
			dlg.close( 1 );
		}

		dlg.center();
		return dlg;
	}
	// set up localization strings

	ContactSheet.strings.accept = localize( "$$$/WAS/ContactSheet/accept=InDesign has accepted the job" );
	ContactSheet.strings.frames = localize( "$$$/WAS/ContactSheet/frames=Creating Image Frames" );
	ContactSheet.strings.placing = localize( "$$$/WAS/ContactSheet/placing=Placing Image" );
	ContactSheet.strings.complete = localize( "$$$/WAS/ContactSheet/complete=Complete" );
	ContactSheet.strings.generating = localize( "$$$/WAS/ContactSheet/generating=Generating Contact Sheet" );
	ContactSheet.strings.contactSheet = localize( "$$$/WAS/ContactSheet/cd=Contact Sheet" );
	ContactSheet.strings.contactSheetMenu = localize( "$$$/WAS/ContactSheet/menu=Create InDesign Contact Sheet" );
	ContactSheet.strings.dialogTitle = localize( "$$$/WAS/ContactSheet/dtitle=Create Contact Sheet (InDesign)" );
	ContactSheet.strings.place = localize( "$$$/WAS/ContactSheet/place=Place:" );
	ContactSheet.strings.columns = localize( "$$$/WAS/ContactSheet/cols=Columns:" );
	ContactSheet.strings.layout = localize( "$$$/WAS/ContactSheet/layout=Layout" );
	ContactSheet.strings.rows = localize( "$$$/WAS/ContactSheet/rows=Rows:" );
	ContactSheet.strings.autoSpacing = localize( "$$$/WAS/ContactSheet/auto=Auto-Spacing" );
	ContactSheet.strings.horizGap = localize( "$$$/WAS/ContactSheet/horiz=Horizontal Gap:" );
	ContactSheet.strings.vertGap = localize( "$$$/WAS/ContactSheet/vert=Vertical Gap:" );
	ContactSheet.strings.columnAlert = localize( "$$$/WAS/ContactSheet/colint=Columns must be an integer" );
	ContactSheet.strings.rowAlert = localize( "$$$/WAS/ContactSheet/rowint=Rows must be an integer" );
	ContactSheet.strings.vertAlert = localize( "$$$/WAS/ContactSheet/vertreal=Vertical Gap must be a number" );
	ContactSheet.strings.horizAlert = localize( "$$$/WAS/ContactSheet/horizreal=Horizontal Gap must be a number" );
	ContactSheet.strings.columnAlertZero = localize( "$$$/WAS/ContactSheet/colintz=Columns must be greater than zero" );
	ContactSheet.strings.rowAlertZero = localize( "$$$/WAS/ContactSheet/rowintz=Rows must be greater than zero" );
	ContactSheet.strings.vertAlertZero = localize( "$$$/WAS/ContactSheet/vertrealz=Vertical Gap must be greater than zero" );
	ContactSheet.strings.horizAlertZero = localize( "$$$/WAS/ContactSheet/horizrealz=Horizontal Gap must be greater than zero" );
	ContactSheet.strings.caption = localize( "$$$/WAS/ContactSheet/caption=Caption" );
	ContactSheet.strings.fileName = localize( "$$$/WAS/ContactSheet/fileName=File Name" );
	ContactSheet.strings.modDate = localize( "$$$/WAS/ContactSheet/modDate=Modification Date" );
	ContactSheet.strings.fileSize = localize( "$$$/WAS/ContactSheet/filesize=File Size" );
	ContactSheet.strings.output = localize( "$$$/WAS/ContactSheet/output=Output" );
	ContactSheet.strings.format = localize( "$$$/WAS/ContactSheet/format=Format:" );
	ContactSheet.strings.outputFile = localize( "$$$/WAS/ContactSheet/outputFile=Output File" );
	ContactSheet.strings.fileCaption = localize( "$$$/WAS/ContactSheet/selectOutput=Select the Contact Sheet Output File:");
	ContactSheet.strings.report = localize( "$$$/WAS/ContactSheet/report=Report" );
	ContactSheet.strings.imagesSelected = localize( "$$$/WAS/ContactSheet/numImages=Number of Images Selected" );
	ContactSheet.strings.imagesPerPage = localize( "$$$/WAS/ContactSheet/imagesPerpage=Number of Images per Page" );
	ContactSheet.strings.pagesInSheet = localize( "$$$/WAS/ContactSheet/numPages=Number of Pages" );
	ContactSheet.strings.okButton = localize( "$$$/WAS/ContactSheet/ok=OK" );
	ContactSheet.strings.cancelButton = localize( "$$$/WAS/ContactSheet/can=Cancel" );
	ContactSheet.strings.pageSetupButton = localize( "$$$/WAS/ContactSheet/pageSetup=Page Setup..." );
	ContactSheet.strings.pageSetup = localize( "$$$/WAS/ContactSheet/pageSetup2=Page Setup" );
	ContactSheet.strings.units = localize( "$$$/WAS/ContactSheet/units=Units:" );
	ContactSheet.strings.pageSize = localize( "$$$/WAS/ContactSheet/pageSize=Page Size:" );
	ContactSheet.strings.pageWidth = localize( "$$$/WAS/ContactSheet/width=Width:" );
	ContactSheet.strings.pageHeight = localize( "$$$/WAS/ContactSheet/ht=Height:" );
	ContactSheet.strings.portrait = localize( "$$$/WAS/ContactSheet/portrait=Portrait" );
	ContactSheet.strings.landscape = localize( "$$$/WAS/ContactSheet/landscape=Landscape" );
	ContactSheet.strings.widthNumber = localize( "$$$/WAS/ContactSheet/widthnum=Width must be a non-zero positive number" );
	ContactSheet.strings.heightNumber = localize( "$$$/WAS/ContactSheet/htnum=Height must be a non-zero positive number" );
	ContactSheet.strings.facingPages = localize( "$$$/WAS/ContactSheet/facing=Facing Pages" );
	ContactSheet.strings.insideMargin = localize( "$$$/WAS/ContactSheet/inside=Inside" );
	ContactSheet.strings.outsideMargin = localize( "$$$/WAS/ContactSheet/outside=Outside" );
	ContactSheet.strings.topMargin = localize( "$$$/WAS/ContactSheet/top=Top" );
	ContactSheet.strings.bottomMargin = localize( "$$$/WAS/ContactSheet/bottom=Bottom" );
	ContactSheet.strings.rightMargin = localize( "$$$/WAS/ContactSheet/right=Right" );
	ContactSheet.strings.leftMargin = localize( "$$$/WAS/ContactSheet/left=Left" );
	ContactSheet.strings.margins = localize( "$$$/WAS/ContactSheet/margins=Margins" );
	ContactSheet.strings.mustBeNumber = localize( "$$$/WAS/ContactSheet/marginnum=Margin must be a number" );
	ContactSheet.strings.contactSheet = localize( "$$$/WAS/ContactSheet/css2=Contact Sheet" );
	ContactSheet.strings.acrossFirst = localize( "$$$/WAS/ContactSheet/acrossfirst=Across First" );
	ContactSheet.strings.acrossFirstLower = localize( "$$$/WAS/ContactSheet/acFirst=across first" );
	ContactSheet.strings.downFirst = localize( "$$$/WAS/ContactSheet/downFirst=Down First" );
	ContactSheet.strings.downFirstLower = localize( "$$$/WAS/ContactSheet/dnFirst=down first" );
	ContactSheet.strings.overwrite = localize( "$$$/WAS/ContactSheet/overwrite= already exists, overwrite?" );
	ContactSheet.strings.cancelledByUser = localize( "$$$/WAS/ContactSheet/cancelled=Contact Sheet execution cancelled by user" );
	ContactSheet.strings.rotateForBestFit = localize( "$$$/WAS/ContactSheet/rotateBestFit=Rotate Image for best fit" );
	ContactSheet.strings.placeOverImages = localize( "$$$/WAS/ContactSheet/placeOver=Place over Images" );
	ContactSheet.strings.outputOptions = localize( "$$$/WAS/ContactSheet/outputOptions=Output Options" );
	ContactSheet.strings.OutputFile = localize( "$$$/WAS/ContactSheet/outputFile2=Output File..." );
	ContactSheet.strings.inputFiles = localize( "$$$/WAS/ContactSheet/files=Files..." );
	ContactSheet.strings.mustBeGreaterThan = localize( "$$$/WAS/ContactSheet/greaterThan=must be greater than" );
	ContactSheet.strings.mustBeLessThan = localize( "$$$/WAS/ContactSheet/lessThan=must be less than" );
	ContactSheet.strings.orientPortrait = localize( "$$$/WAS/ContactSheet/orientPortrait=Portrait" );
	ContactSheet.strings.orientLandscape = localize( "$$$/WAS/ContactSheet/orientLandscape=Landscape" );
	ContactSheet.strings.Clockwise = localize( "$$$/WAS/ContactSheet/CW=Clockwise" );
	ContactSheet.strings.CounterClockwise = localize( "$$$/WAS/ContactSheet/CCW=Counter-Clockwise" );
	ContactSheet.strings.idDocx = localize( "$$$/WAS/ContactSheet/idDocx=InDesign Document" );
	ContactSheet.strings.pdfDocx = localize( "$$$/WAS/ContactSheet/pdfDocx=PDF Document" );
	ContactSheet.strings.filterPS = localize( "$$$/WAS/ContactSheet/filterPS=Photoshop" );
	ContactSheet.strings.filterAI = localize( "$$$/WAS/ContactSheet/filterAI=Illustrator" );
	ContactSheet.strings.filterDEF = localize( "$$$/WAS/ContactSheet/filterDEF=Default" );
	ContactSheet.strings.filterPSALL = localize( "$$$/WAS/ContactSheet/filterPSALL=Photoshop - All" );
	ContactSheet.strings.filterAIALL = localize( "$$$/WAS/ContactSheet/filterAIALL=Illustrator - All" );
	ContactSheet.strings.filterPDF = localize( "$$$/WAS/ContactSheet/filterPDF=PDF" );
	ContactSheet.strings.pageSizeA4 = localize( "$$$/WAS/ContactSheet/pageSizeA4=A4" );
	ContactSheet.strings.pageSizeA5 = localize( "$$$/WAS/ContactSheet/pageSizeA5=A5" );
	ContactSheet.strings.pageSizeLetter = localize( "$$$/WAS/ContactSheet/pageSizeLetter=Letter" );
	ContactSheet.strings.pageSizeLegal = localize( "$$$/WAS/ContactSheet/pageSizeLegal=Legal" );
	ContactSheet.strings.INCHES = localize( "$$$/WAS/ContactSheet/INCHES=Inches" );
	ContactSheet.strings.MILLIMETERS = localize( "$$$/WAS/ContactSheet/MILLIMETERS=Millimeters" );
	ContactSheet.strings.select = localize( "$$$/WAS/ContactSheet/cd/select=Select" );
	ContactSheet.strings.fileName = localize( "$$$/WAS/ContactSheet/cd/filename=File Name" );
	ContactSheet.strings.creationDate = localize( "$$$/WAS/ContactSheet/cd/cd=Creation Date" );
	ContactSheet.strings.modificationDate = localize( "$$$/WAS/ContactSheet/cd/md=Modification Date" );
	ContactSheet.strings.fileSize = localize( "$$$/WAS/ContactSheet/cd/fs=File Size" );
	ContactSheet.strings.metadata = localize( "$$$/WAS/ContactSheet/cd/metadata=Metadata" );


	ContactSheet.outputDrop = undefined;
	// set up configuration objects
	ContactSheet.config = {};
	ContactSheet.config.rotate = false;
	ContactSheet.config.rotation = ContactSheet.strings.Clockwise;
	ContactSheet.config.files = new Array( 0 );
	ContactSheet.config.fileTypePreset = ContactSheet.strings.filterDEF;
	ContactSheet.config.output = undefined;
	ContactSheet.config.PDFPreset = undefined;
	ContactSheet.config.useTemplate = false;
	ContactSheet.config.templateFile = undefined;
	ContactSheet.config.saveAsPDF = false;
	ContactSheet.config.makeNewFile = false;
	ContactSheet.config.saveNewFile = false;
	ContactSheet.config.rowCount = 4;
	ContactSheet.config.colCount = 3;
	ContactSheet.config.autospace = true; 
	if ( app.locale == "en_US" ) { 
		ContactSheet.config.verticalGap = ".25 in";
		ContactSheet.config.horizontalGap = ".125 in";
	} else {
		ContactSheet.config.verticalGap = "6.35 mm";
		ContactSheet.config.horizontalGap = "3.175 mm";
	}
	ContactSheet.config.removeFrames = true;
	ContactSheet.config.recursive = true;
	ContactSheet.config.filter = ContactSheet.strings.filterDEF;
	ContactSheet.config.label = true;
	ContactSheet.config.labelStyle = 1;
	ContactSheet.config.caption = new Array();
	ContactSheet.config.caption.push( "filename" );
	ContactSheet.config.overImages = false;
	ContactSheet.config.overImageGap = 0;
	ContactSheet.config.format = ContactSheet.strings.idDocx;
	ContactSheet.config.place = ContactSheet.strings.acrossFirst;

	if ( app.locale == "en_US" ) {
		ContactSheet.config.pageSetup = {};
		ContactSheet.config.pageSetup.measurementUnits = ContactSheet.strings.INCHES;
		ContactSheet.config.pageSetup.initialUnits = ContactSheet.strings.INCHES;
		ContactSheet.config.pageSetup.units = "MeasurementUnits.INCHES_DECIMAL"; // or mm
		ContactSheet.config.pageSetup.pageSize = ContactSheet.strings.pageSizeLetter; // see ContactSheet.pageSizes Hashtable
		ContactSheet.config.pageSetup.width = "8.5 in";
		ContactSheet.config.pageSetup.height = "11 in";
		ContactSheet.config.pageSetup.facingPages = false;
		ContactSheet.config.pageSetup.margins = {};
		ContactSheet.config.pageSetup.margins.top = ".5 in";
		ContactSheet.config.pageSetup.margins.bottom = ".5 in";
		ContactSheet.config.pageSetup.margins.inside = ".5 in";
		ContactSheet.config.pageSetup.margins.outside = ".5 in";
		ContactSheet.config.pageSetup.orientation = ContactSheet.strings.orientPortrait;
	} else {
		ContactSheet.config.pageSetup = {};
		ContactSheet.config.pageSetup.measurementUnits = ContactSheet.strings.MILLIMETERS;
		ContactSheet.config.pageSetup.initialUnits = ContactSheet.strings.MILLIMETERS;
		ContactSheet.config.pageSetup.units = "MeasurementUnits.MILLIMETERS";
		ContactSheet.config.pageSetup.pageSize = ContactSheet.strings.pageSizeA4 // see ContactSheet.pageSizes Hashtable
		ContactSheet.config.pageSetup.width = "210 mm";
		ContactSheet.config.pageSetup.height = "297 mm";
		ContactSheet.config.pageSetup.facingPages = false;
		ContactSheet.config.pageSetup.margins = {};
		ContactSheet.config.pageSetup.margins.top = "12.7 mm";
		ContactSheet.config.pageSetup.margins.bottom = "12.7 mm";
		ContactSheet.config.pageSetup.margins.inside = "12.7 mm";
		ContactSheet.config.pageSetup.margins.outside = "12.7 mm";
		ContactSheet.config.pageSetup.orientation = ContactSheet.strings.orientPortrait;
	}
	ContactSheet.config.captionArray = [ "<var filename>" ];
	ContactSheet.strings.justifyCenter = localize( "$$$/WAS/ContactSheet/cd/center=Center" );
	ContactSheet.strings.justifyLeft = localize( "$$$/WAS/ContactSheet/cd/left=Left" );
	ContactSheet.strings.justifyRight = localize( "$$$/WAS/ContactSheet/cd/right=Right" );	
	ContactSheet.captionJustification = ContactSheet.strings.justifyCenter;
	ContactSheet.captionSyntax = new WasLib.Hashtable( true );
	// + Watson 1467054 Added the localize for keys for which translations exist
	ContactSheet.captionSyntax.putValue( localize("$$$/WAS/ContactSheet/fileName=File Name"), "<var filename>" );
	// Watson 1467054 no translation for the Substring element
	// ContactSheet.captionSyntax.putValue( "Filename - Substring", "<var filename[0,6]>" );
	ContactSheet.captionSyntax.putValue( localize("$$$/WAS/ContactSheet/cd/cd=Creation Date"), "<var cdate[YYMMDD]>" );
	ContactSheet.captionSyntax.putValue( localize("$$$/WAS/ContactSheet/modDate=Modification Date"), "<var mdate[YYMMDD]>" );
	ContactSheet.captionSyntax.putValue( localize("$$$/WAS/ContactSheet/filesize=File Size"), "<var filesize[K]>" );
	ContactSheet.captionSyntax.putValue( localize("$$$/WAS/ContactSheet/cd/metadata=Metadata"), "metadata" );
	// - Watson 1467054 
	ContactSheet.config.filterName = "Contact Sheet";
	ContactSheet.config.filter = WasLib.fileFilters.getValue( ContactSheet.config.filterName );
	ContactSheet.config.grayBoxes = false;
	
	// cuppla utility functions
	ContactSheet.toMM = function( inches ) {
		return inches * 25.4;
	}
	ContactSheet.toIN = function( mm ) {
		return mm / 25.4;
	}
	ContactSheet.convertControl = function( control ) {
		control.text = ContactSheet.convert( control.text, control.savedUnits );
		control.savedUnits = ContactSheet.config.pageSetup.measurementUnits;
		control.savedValue = control.text;
	}
	ContactSheet.convert = function( val, oUnits ) {
		var origUnits = ( oUnits != undefined ) ? oUnits : ContactSheet.config.pageSetup.initialUnits;
		var ret = parseFloat( val );
		if ( isNaN( ret ) ) {
			return;
		}
		var units = ContactSheet.config.pageSetup.measurementUnits == ContactSheet.strings.INCHES ? " in" : " mm";
		if ( ContactSheet.config.pageSetup.measurementUnits != origUnits ) {
			var ret = units == " in" ? ContactSheet.toIN( ret ) : ContactSheet.toMM( ret );
			if ( new String( ret ).length > 3 ) {
				ret = ContactSheet.round( ret, 3 );
			}
		}
		return ret + units;
	}
	ContactSheet.round = function( aNumber, toDecimalPlaces ) {
		if ( toDecimalPlaces == 0 ) {
			return Math.round( aNumber );
		} else {
			return ( Math.round( ( aNumber * 10 * toDecimalPlaces ) ) / ( 10 * toDecimalPlaces ) );
		}
	}
	// more configuration stuff
	ContactSheet.orientations = new WasLib.Hashtable( true );
	ContactSheet.orientations.putValue( ContactSheet.strings.orientPortrait, ContactSheet.strings.orientPortrait );
	ContactSheet.orientations.putValue( ContactSheet.strings.orientLandscape, ContactSheet.strings.orientLandscape );

	ContactSheet.rotation = new WasLib.Hashtable( true );
	ContactSheet.rotation.putValue( ContactSheet.strings.Clockwise, ContactSheet.strings.Clockwise );
	ContactSheet.rotation.putValue( ContactSheet.strings.CounterClockwise, ContactSheet.strings.CounterClockwise );


	ContactSheet.formats = new WasLib.Hashtable( true );
	ContactSheet.formats.putValue( ContactSheet.strings.idDocx, "indd" );
	ContactSheet.formats.putValue( ContactSheet.strings.pdfDocx, "pdf" );

	ContactSheet.places = new WasLib.Hashtable( true );
	ContactSheet.places.putValue( ContactSheet.strings.acrossFirst, ContactSheet.strings.acrossFirstLower );
	ContactSheet.places.putValue( ContactSheet.strings.downFirst, ContactSheet.strings.downFirstLower );

	ContactSheet.fileFilters = new WasLib.Hashtable( true );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterPS, "TYPES.PHOTOSHOP" );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterAI, "TYPES.ILLUSTRATOR" );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterDEF, "TYPES.DEFAULT_CONTACTSHEET" );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterPSALL, "TYPES.PHOTOSHOP_OPENABLE" );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterAIALL, "TYPES.ILLUSTRATOR_OPENABLE" );
	ContactSheet.fileFilters.putValue( ContactSheet.strings.filterPDF, "TYPES.PDF" );

	ContactSheet.measurementUnits = new WasLib.Hashtable( true );
	ContactSheet.measurementUnits.putValue( ContactSheet.strings.INCHES, "MeasurementUnits.INCHES_DECIMAL" );
	ContactSheet.measurementUnits.putValue( ContactSheet.strings.MILLIMETERS, "MeasurementUnits.MILLIMETERS" );
	ContactSheet.pageSize = function( txt, hor, vert, unit ) {
		this.display = txt;
		this.horizontal = hor;
		this.vertical = vert;
		this.units = unit;
	}

	ContactSheet.margins = function( top, bottom, inside, outside ) {
		this.inside = inside;
		this.outside = outside;
		this.top = top;
		this.bottom = bottom;
	}

	ContactSheet.pageSizes = new WasLib.Hashtable( true );
	ContactSheet.pageSizes.putValue( ContactSheet.strings.pageSizeA4, new ContactSheet.pageSize( ContactSheet.strings.pageSizeA4, "210 mm", "297 mm", ContactSheet.strings.MILLIMETERS ) );
	ContactSheet.pageSizes.putValue( ContactSheet.strings.pageSizeA5, new ContactSheet.pageSize( ContactSheet.strings.pageSizeA5, "148 mm", "210 mm", ContactSheet.strings.MILLIMETERS ) );
	ContactSheet.pageSizes.putValue( ContactSheet.strings.pageSizeLetter, new ContactSheet.pageSize( ContactSheet.strings.pageSizeLetter, "8.5 in", "11 in", ContactSheet.strings.INCHES ) );
	ContactSheet.pageSizes.putValue( ContactSheet.strings.pageSizeLegal, new ContactSheet.pageSize( ContactSheet.strings.pageSizeLegal, "8.5 in", "14 in", ContactSheet.strings.INCHES ) );

	ContactSheet.showPDFDialog = function() {
		ContactSheet.getPDFPresets();
	}
	ContactSheet._showPDFDialog = function()  {
		var d = ContactSheet.buildPDFDialog();
		d.center();
		ContactSheet.setPDFPresets();

	  	var okClicked = d.show() == 1 ? true : false;
		if ( !okClicked )  {
			ContactSheet.outputDrop.selection = ContactSheet.strings.idDocx
			ContactSheet.presetStat.text = "";
		} else {
			ContactSheet.presetStat.text = localize( "$$$/WAS/ContactSheet/usingpdfpreset=Using PDF Preset: " ) + ContactSheet.config.PDFPreset;
		}
	}
	ContactSheet.storePDFPresets = function( btObj ) {
		eval( "ContactSheet.PDFPresets = " + btObj.body );
//		ContactSheet.setPDFPresets();
		ContactSheet._showPDFDialog();
	}
	ContactSheet.setPDFPresets = function() {
		for ( var i = 0; i < ContactSheet.PDFPresets.length; i++ ) {
			var newItem = ContactSheet.presetList.add( "item", ContactSheet.PDFPresets[ i ] );
		}	
		ContactSheet.PDFStatus.text = localize( "$$$/WAS/ContactSheet/selectpdfPresetUse=Select the PDF Preset to use:" );
		BridgeTalk.bringToFront( "bridge" );
	}
	ContactSheet.getPDFPresets = function()  {
		var theScript = "var presets = app.pdfExportPresets; \n" +
									"var pString = new Array(); \n" +
									"for ( var i = 0; i < presets.length; i++ ) { \n" +
									"   pString.push( presets.item( i ).name ); \n" +
									"} \n" +
									"pString.toSource();"
		var bt = new BridgeTalk();
		var specifier = BridgeTalk.getSpecifier( "indesign-5.0" )
		if ( specifier != null ) {
			bt.target = specifier;
		} else {
			bt.target = "indesign";
		}
		bt.body = theScript;
		bt.onResult = ContactSheet.storePDFPresets;
		bt.send();
//		sendBridgeTalkMessage( "indesign", theScript, ContactSheet.storePDFPresets );
		BridgeTalk.bringToFront( "bridge" );
	}

	ContactSheet.buildPDFDialog = function( control )  {

		var dlg = new Window( "dialog", ContactSheet.strings.dialogTitleID );

	  	dlg.orientation = "row"; 	// at the window level, I want two "groups", one to hold the 
							// all the "value entering" controls, and one to hold OK,CANCEL, etc
							// buttons in a vertical column on the right.
		dlg.alignChildren = "top"; 	// the default is center, you want both the value and button groups
								// at the top of the window

		dlg.vGroup = dlg.add( "group" );	// this is the group that will hold all of the value stuff
		dlg.vGroup.orientation = "column";
		dlg.vGroup.alignChildren = "top";

		dlg.bGroup = dlg.add( "group" );
		dlg.bGroup.orientation = "column";
		dlg.bGroup.spacing = 30; // in the button group, I want to have groups of buttons the first two will
						// always be OK, Cancel. But if you want to add a Page Setup, for example,
						// I want it to be an extra 10 pixels down from the Cancel button to differentiate	

	// this is the OK/Cancel button group
		dlg.bGroup.okGroup = dlg.bGroup.add( "group", undefined );
		dlg.bGroup.okGroup.preferredSize.width = 100;
		dlg.bGroup.okGroup.orientation = "column";
		dlg.bGroup.okGroup.okButton = dlg.bGroup.okGroup.add( "button", undefined, ContactSheet.strings.okButton );
		
		dlg.bGroup.okGroup.cancelButton = dlg.bGroup.okGroup.add( "button", undefined, ContactSheet.strings.cancelButton );
		
		dlg.bGroup.okGroup.okButton.onClick = function() {
			dlg.close( 1 );
		}
		dlg.bGroup.okGroup.cancelButton.onClick = function() {
			dlg.close( 2 );
		}

		dlg.vGroup.status = dlg.vGroup.add( "statictext", undefined, localize( "$$$/WAS/ContactSheet/getpdfpresetfromID=Getting PDF Presets from InDesign" ), { multiline:true } );
	//	dlg.vGroup.status.preferredSize = [350,20];
		ContactSheet.PDFStatus = dlg.vGroup.status;
		
		dlg.vGroup.fileGroup = dlg.vGroup.add( "panel", undefined, ContactSheet.strings.availPresets );
		dlg.vGroup.fileGroup.preferredSize = [350,400];
		dlg.vGroup.fileGroup.fileList = dlg.vGroup.fileGroup.add( "listbox",undefined ,undefined, { multiselect: false} );
		ContactSheet.presetList = dlg.vGroup.fileGroup.fileList;
		dlg.vGroup.fileGroup.fileList.okButton = dlg.bGroup.okGroup.okButton;
		dlg.vGroup.fileGroup.fileList.preferredSize = [350,400];
		dlg.vGroup.fileGroup.fileList.onChange = function() {
			if ( this.selection ) {
				ContactSheet.config.PDFPreset = this.selection.text;
				this.okButton.enabled = true;
			} else {
				this.okButton.enabled = false;
			}
		}
		dlg.onShow = function() {
//			ContactSheet.getPDFPresets();
			//app.scheduleTask( ContactSheet.getPDFPresets, 100 );
			BridgeTalk.bringToFront( "bridge" );
		}
		dlg.bGroup.okGroup.okButton.enabled = false;
		dlg.center();
		return dlg;
	}
ContactSheet.metadataUI = function() {
		var mdWindow = new Window( "dialog", localize( "$$$/wsc/selMetadata=Select a Metadata Element" ) );
		ContactSheet.mdSelectWindow = mdWindow;
		mdWindow.orientation = "row";
		var gp1 = mdWindow.add( "group" );
		gp1.orientation = "column";
		gp1.alignChildren = "left";
		mdWindow.mdSelect = gp1.add( "dropdownlist" );
		mdWindow.mdSelect.preferredSize = [175, 20 ];
		mdWindow.mdList = gp1.add( "listbox" );
		mdWindow.mdList.preferredSize = [175,200];
		mdWindow.mdList.win = mdWindow;
		
		var gp3 = mdWindow.add( "group" );
		gp3.orientation = "column";
		gp3.alignment = "fill";
		gp3.alignChildren = "top";
		mdWindow.okButton = gp3.add( "button", undefined, WasLib.strings.OK );
		mdWindow.okButton.win = mdWindow;
		mdWindow.caButton = gp3.add( "button", undefined, WasLib.strings.cancel );
		mdWindow.caButton.win = mdWindow;
		mdWindow.okButton.onClick = function() {
			this.win.close( 1 );
		}
		mdWindow.caButton.onClick = function() {
			this.win.close( 2 );
		}
		mdWindow.mdSelect.onChange = function() {
			ContactSheet.mdSelectWindow.loadList();
		}
		mdWindow.loadList = function() {
			if ( ContactSheet.mdSelectWindow.mdSelect.selection ) {
				var ns = ContactSheet.mdSelectWindow.mdSelect.selection.ns;
				ContactSheet.mdSelectWindow.mdList.removeAll();
				for ( var j = 0; j < ns.children.length; j++ ) {
					var newItem = ContactSheet.mdSelectWindow.mdList.add( "item", ns.children[ j ].property );
					newItem.handle = ns.children[ j ].handle;
				}
			}	
		}
		for ( var i = 0; i < MdNs.namespaces.keyList.length; i++ ) {
			var ns = MdNs.namespaces.getValue( MdNs.namespaces.keyList[ i ] );
			var nsItem = mdWindow.mdSelect.add( "item", ns.common );
	 		nsItem.ns = ns;
		}
		mdWindow.mdSelect.items[ 0 ].selected = true;
		mdWindow.mdSelect.selection = mdWindow.mdSelect.items[ 0 ];
		mdWindow.loadList();
		mdWindow.center();
		if ( mdWindow.show() == 1 ) {
			return mdWindow.mdList.selection.handle;
		} else {
			return undefined;
		}
	}

	ContactSheet.strings.dialogTitleID = localize( "$$$/WAS/ContactSheet/dtitle2=Select InDesign PDF Preset" );
	ContactSheet.strings.availPresets = localize( "$$$/WAS/ContactSheet/availpresets=Available Presets" );
	ContactSheet.strings.okButton = localize( "$$$/WAS/ContactSheet/presetok=OK" );
	ContactSheet.strings.cancelButton = localize( "$$$/WAS/ContactSheet/presetcancel=Cancel" );

	MdNs = {};

	MdNs.elements = new WasLib.Hashtable();
	MdNs.namespaces = new WasLib.Hashtable();
	MdNs.namespacePrefixes = new WasLib.Hashtable();
	
	MdNs.MdManager = function( thumbnail ) {
		this.thumbnail = thumbnail;
		this.md = thumbnail.metadata;
		this.enumeration = new WasLib.KeyedArrayList();
		this.noValue = new WasLib.KeyedArrayList();
		this.notScriptable = new WasLib.KeyedArrayList();
	}
	MdNs.MdManager.prototype.grab = function() {
		var md = this.thumbnail.metadata;
		var res = new WasLib.KeyedArrayList();
		var elements = MdNs.elements.keyList;
		for ( var i in elements) {
			var el = MdNs.elements.get( elements[ i ] );
			if ( el.scriptAccessible ) {
				try {
					var val = el.getValue( md );
					if ( ( val != undefined )  && ( val.length > 0 ) && ( WasLib.trim( val ) != null ) ) {
						var mdValue = new MdNs.MdValue( el.ns, el, val );
						this.enumeration.putValue( el.ns.common, mdValue );
					} else {
						this.noValue.putValue( el.ns.common, new MdNs.MdValue( el.ns, el, undefined ) );
					}
				} catch ( e ) {
				}
			} else {
				this.notScriptable.putValue( el.ns.common, new MdNs.MdValue( el.ns, el, undefined ) );
			}
		}
	}
	MdNs.loadMetadata = function() {
		// ipaterso: is this now obsolete code?
		var files = WasLib.cullFolders( WasLib.getBridgeThumbnails() );
		for ( var i in files ) {
			if ( isFile( files[ i ] ) ) {
				var md = new MdNs.MdManager( files[ i ] );
				md.enumeration = md.grab();
				files[ i ].mdManager = md;
			}
		}
	}
	MdNs.MdValue = function( ns, element, val ) {
		this.ns = ns;
		this.element = element;
		this.value = val;
	}
	MdNs.MetadataNamespace = function( common, ns, prefix ) {
		this.common = common;
		this.ns = ns;
		this.handle = prefix;
		MdNs.namespaces.putValue( common, this );
		MdNs.namespacePrefixes.putValue( prefix, this );
		this.children = new Array();
	}
	new MdNs.MetadataNamespace( "IPTC Core", "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/", "Iptc4xmpCore" );
	new MdNs.MetadataNamespace( "EXIF", "http://ns.adobe.com/exif/1.0/", "exif");
	new MdNs.MetadataNamespace( "Dublin Core", "http://purl.org/dc/elements/1.1/", "dc" );
	new MdNs.MetadataNamespace( "TIFF", "http://ns.adobe.com/tiff/1.0/", "tiff" );
	new MdNs.MetadataNamespace( "XMP Basic", "http://ns.adobe.com/xap/1.0/", "xmp"  );
	new MdNs.MetadataNamespace( "XMP Media Management", "http://ns.adobe.com/xap/1.0/mm/", "xmpMM" );
	new MdNs.MetadataNamespace( "XMP Rights Management", "http://ns.adobe.com/xap/1.0/rights/", "xmpRights" );
	new MdNs.MetadataNamespace( "XMP Basic Job Ticket", "http://ns.adobe.com/xap/1.0/bj/", "xmpBJ" );
	new MdNs.MetadataNamespace( "XMP Paged-Text", "http://ns.adobe.com/xap/1.0/t/pg/", "xmpTPg" );
	new MdNs.MetadataNamespace( "Photoshop", "http://ns.adobe.com/photoshop/1.0/", "photoshop" );
//	new MdNs.MetadataNamespace( "Stock Photo", "http://ns.adobe.com/StockPhoto/1.0/", "bmsp" );
	new MdNs.MetadataNamespace( "Adobe PDF", "http://ns.adobe.com/pdf/1.3/", "pdf" );
	new MdNs.MetadataNamespace( "Camera Raw Settings", "http://ns.adobe.com/camera-raw-settings/1.0/", "crs" );
//	new MdNs.MetadataNamespace( "PNG", "http://ns.adobe.com/png/1.0/", "png" );
	
	MdNs.MdElement = function( nsCommon, property, gettable, redirectHandle ) {
		this.nsCommon = nsCommon;
		this.scriptAccessible = gettable;
		this.property = property;
		this.ns = MdNs.namespaces.getValue( this.nsCommon );
		this.ns.children.push( this );
		this.handle = this.ns.handle + ":" + this.property;
		MdNs.elements.putValue( this.handle, this );
		this.redirectHandle = redirectHandle;
		this.redirected = false;
		this.redirectElement = undefined;
		if ( this.redirectHandle ) {
			this.redirectElement = MdNs.elements.getValue( this.redirectHandle );
			this.scriptAccessible = this.redirectElement.scriptAccessible;
			this.redirected = true;
		}
	}
	MdNs.MdElement.prototype.getValue = function( md ) {
		if ( !this.scriptAccessible ) {
			throw ( this.nsCommon + ", " + this.property + " " + localize( "$$$/WAS/MD/notscriptable=cannot be accessed via scripting" ) );
		}
		if ( this.redirected ) {
			return this.redirectElement.getValue( md );
		} else {
			md.namespace = this.ns.ns;
			var st = "md." + this.property + ";";
			return eval( st );
		}
	}
	MdNs.MdElement.prototype.toString = function() {
		return "[Object: MdNs.MdElement]";
	}
	new MdNs.MdElement( "Dublin Core", "contributor", true ); // false );
	new MdNs.MdElement( "Dublin Core", "coverage", true );
	new MdNs.MdElement( "Dublin Core", "creator", true ); // false );
	new MdNs.MdElement( "Dublin Core", "date", true ); // false );
	new MdNs.MdElement( "Dublin Core", "description", true );
	new MdNs.MdElement( "Dublin Core", "format", true );
	new MdNs.MdElement( "Dublin Core", "identifier", true );
	new MdNs.MdElement( "Dublin Core", "language", true ); // false );
	new MdNs.MdElement( "Dublin Core", "publisher", true ); // false );
	new MdNs.MdElement( "Dublin Core", "relation", true ); // false );
	new MdNs.MdElement( "Dublin Core", "rights", true );
	new MdNs.MdElement( "Dublin Core", "source", true );
	new MdNs.MdElement( "Dublin Core", "subject", true ); // false );
	new MdNs.MdElement( "Dublin Core", "title", true );
	new MdNs.MdElement( "Dublin Core", "type", true ); // false );
	
	new MdNs.MdElement( "XMP Basic", "Advisory", true ); // false );
	new MdNs.MdElement( "XMP Basic", "BaseURL", true );
	new MdNs.MdElement( "XMP Basic", "CreateDate", true );
	new MdNs.MdElement( "XMP Basic", "Identifier", true ); // false );
	new MdNs.MdElement( "XMP Basic", "MetaDataDate", true );
	new MdNs.MdElement( "XMP Basic", "ModifyDate", true );
	new MdNs.MdElement( "XMP Basic", "Nickname", true );
	new MdNs.MdElement( "XMP Basic", "Thumbnail", true ); // false );
	
	new MdNs.MdElement( "XMP Rights Management", "Certificate", true );
	new MdNs.MdElement( "XMP Rights Management", "Marked", true );
	new MdNs.MdElement( "XMP Rights Management", "Owner", true ); // false );
	new MdNs.MdElement( "XMP Rights Management", "UsageTerms", true );
	new MdNs.MdElement( "XMP Rights Management", "WebStatement", true );

	new MdNs.MdElement( "XMP Media Management", "DerivedFrom", true );
	new MdNs.MdElement( "XMP Media Management", "DocumentID", true );
	new MdNs.MdElement( "XMP Media Management", "History", true ); // false );
	new MdNs.MdElement( "XMP Media Management", "ResourceEvent", true ); // false );
	new MdNs.MdElement( "XMP Media Management", "ManagedFrom", true );
	new MdNs.MdElement( "XMP Media Management", "Manager", true );
	new MdNs.MdElement( "XMP Media Management", "ManageTo", true );
	new MdNs.MdElement( "XMP Media Management", "ManageURI", true );
	new MdNs.MdElement( "XMP Media Management", "ManagerVariant", true );
	new MdNs.MdElement( "XMP Media Management", "RenditionClass", true );
	new MdNs.MdElement( "XMP Media Management", "RenditionParams", true );
	new MdNs.MdElement( "XMP Media Management", "VersionID", true );
	new MdNs.MdElement( "XMP Media Management", "Versions", true ); // false );
	new MdNs.MdElement( "XMP Media Management", "LastURL", true );
	
	new MdNs.MdElement( "XMP Basic Job Ticket", "JobRef", true ); // false );
	
	new MdNs.MdElement( "XMP Paged-Text", "MaxPageSize", true );
	new MdNs.MdElement( "XMP Paged-Text", "NPages", true );
	
	new MdNs.MdElement( "Adobe PDF", "Keywords", true );
	new MdNs.MdElement( "Adobe PDF", "Pdfversion", true );
	new MdNs.MdElement( "Adobe PDF", "AgentName", true );
	
	new MdNs.MdElement( "Photoshop", "AuthorsPosition", true );
	new MdNs.MdElement( "Photoshop", "CaptionWriter", true );
	new MdNs.MdElement( "Photoshop", "Category", true );
	new MdNs.MdElement( "Photoshop", "City", true );
	new MdNs.MdElement( "Photoshop", "Country", true );
	new MdNs.MdElement( "Photoshop", "Credit", true );
	new MdNs.MdElement( "Photoshop", "DateCreated", true );
	new MdNs.MdElement( "Photoshop", "Headline", true );
	new MdNs.MdElement( "Photoshop", "Instructions", true );
	new MdNs.MdElement( "Photoshop", "Source", true );
	new MdNs.MdElement( "Photoshop", "State", true );
	new MdNs.MdElement( "Photoshop", "SupplementalCategories", true );
	new MdNs.MdElement( "Photoshop", "TransmissionReference", true );
	new MdNs.MdElement( "Photoshop", "Urgency", true );
	
	new MdNs.MdElement( "TIFF", "ImageWidth", true );
	new MdNs.MdElement( "TIFF", "ImageLength", true );
	new MdNs.MdElement( "TIFF", "BitsPerSample", true ); // false );
	new MdNs.MdElement( "TIFF", "Compression", true ); //1 = uncompressed 6=jpeg
	new MdNs.MdElement( "TIFF", "PhotometricInterpretation", true ); //2 RGB, 6 YCbCr
	new MdNs.MdElement( "TIFF", "Orientation", true );
	new MdNs.MdElement( "TIFF", "SamplesPerPixel", true );
	new MdNs.MdElement( "TIFF", "PlanarConfiguration", true );
	new MdNs.MdElement( "TIFF", "YCbCrSubSampling", true ); // false );
	new MdNs.MdElement( "TIFF", "YCbCrPositioning", true ); //1 centered 2 co-sited
	new MdNs.MdElement( "TIFF", "XResolution", true );
	new MdNs.MdElement( "TIFF", "YResolution", true );
	new MdNs.MdElement( "TIFF", "ResolutionUnit", true ) //2 inches, 3 centimeters
	new MdNs.MdElement( "TIFF", "TransferFunction", true ); // false );
	new MdNs.MdElement( "TIFF", "WhitePoint", true ); // false );
	new MdNs.MdElement( "TIFF", "PrimaryChromaticities", true ); // false );
	new MdNs.MdElement( "TIFF", "YCbCrCoefficients", true ); // false );
	new MdNs.MdElement( "TIFF", "ReferenceBlackWhite", true ); // false );
	new MdNs.MdElement( "TIFF", "DateTime", true );
	new MdNs.MdElement( "TIFF", "ImageDescription", true );
	new MdNs.MdElement( "TIFF", "Make", true );
	new MdNs.MdElement( "TIFF", "Model", true );
	new MdNs.MdElement( "TIFF", "Software", true );
	new MdNs.MdElement( "TIFF", "Artist", true );
	new MdNs.MdElement( "TIFF", "Copyright", true );
	
	new MdNs.MdElement( "EXIF", "ExifVersion", true );
	new MdNs.MdElement( "EXIF", "FlashpixVersion", true );
	new MdNs.MdElement( "EXIF", "ColorSpace", true ); //1 sRGC -32786 uncalibrated
	new MdNs.MdElement( "EXIF", "ComponentsConfiguration", true ); // false );
	new MdNs.MdElement( "EXIF", "CompressedBitsPerPixel", true );
	new MdNs.MdElement( "EXIF", "PixelXDimension", true );
	new MdNs.MdElement( "EXIF", "PixelYDimension", true );
	new MdNs.MdElement( "EXIF", "MakerNote", true );
	new MdNs.MdElement( "EXIF", "UserComment", true );
	new MdNs.MdElement( "EXIF", "RelatedSoundFile", true );
	new MdNs.MdElement( "EXIF", "DateTimeOriginal", true );
	new MdNs.MdElement( "EXIF", "DateTimeDigitized", true );
	new MdNs.MdElement( "EXIF", "ExposureTime", true );
	new MdNs.MdElement( "EXIF", "FNumber", true );
	new MdNs.MdElement( "EXIF", "ExposureProgram", true ); // 0=not defined, 1=manual 2=normal program 3=aperature priority 4=shutter priority 5=creative program 6=action program  7=portrait mode 8= landscape mode
	new MdNs.MdElement( "EXIF", "SpectralSensitivity", true );
	new MdNs.MdElement( "EXIF", "ISOSpeedRatings", true ); // false );
	new MdNs.MdElement( "EXIF", "OECF", true );
	new MdNs.MdElement( "EXIF", "ShutterSpeedValue", true );
	new MdNs.MdElement( "EXIF", "ApertureValue", true );
	new MdNs.MdElement( "EXIF", "BrightnessValue", true );
	new MdNs.MdElement( "EXIF", "ExposureBiasValue", true );
	new MdNs.MdElement( "EXIF", "MaxApertureValue", true );
	new MdNs.MdElement( "EXIF", "SubjectDistance", true );
	new MdNs.MdElement( "EXIF", "MeteringMode", true ); // 0=unk 1=avg 2=center weighted avg 3=spot 4=multi-spot 5=pattern 6=partial 255=other
	new MdNs.MdElement( "EXIF", "LightSource", true ); // 0-unk 1=daylight 2=flourescent 3=tungsten 17=std light A 18=std light B 19=std light C 20=D55 21=D65 22=D75 255=other
	new MdNs.MdElement( "EXIF", "Flash", true );
	new MdNs.MdElement( "EXIF", "FocalLength", true );
	new MdNs.MdElement( "EXIF", "SubjectArea", true ); // false );
	new MdNs.MdElement( "EXIF", "FlashEnergy", true );
	new MdNs.MdElement( "EXIF", "SpatialResponseFrequency", true );
	new MdNs.MdElement( "EXIF", "FocalPlaneXResolution", true );
	new MdNs.MdElement( "EXIF", "FocalPlaneYResolution", true );
	new MdNs.MdElement( "EXIF", "FocalPlaneResolutionUnit", true ); // 2=inches 3=cent
	new MdNs.MdElement( "EXIF", "SubjectLocation", true ); // false );
	new MdNs.MdElement( "EXIF", "ExposureIndex", true );
	new MdNs.MdElement( "EXIF", "SensingMethod", true ); //1=not def 2=one chip color area sensor 3=two chip 4=three chip 5=color sequential area sensor 7=trilinear sensor 8=color sequential linear sensor
	new MdNs.MdElement( "EXIF", "FileSource", true ); // 3(DSC) only choice
	new MdNs.MdElement( "EXIF", "SceneType", true ); // 1(directly photographed image)
	new MdNs.MdElement( "EXIF", "CFAPattern", true );
	new MdNs.MdElement( "EXIF", "CustomRendered", true ); // 0=normal process 1=custom process
	new MdNs.MdElement( "EXIF", "ExposureMode", true ); // 0=auto 1=manual 2=auto bracket
	new MdNs.MdElement( "EXIF", "WhiteBalance", true );// 0=auto 1=manual
	new MdNs.MdElement( "EXIF", "DigitalZoomRatio", true );
	new MdNs.MdElement( "EXIF", "FocalLengthIn35mmFilm", true );
	new MdNs.MdElement( "EXIF", "SceneCaptureType", true ); // 0=std 1=landscape 2=portrait 3=night scene
	new MdNs.MdElement( "EXIF", "GainControl", true ); // 0=none 1=low gain up 2=hight gain up 3=low gain down 4=high gain down
	new MdNs.MdElement( "EXIF", "Contrast", true ); // 0=normal 1=soft 2=hard
	new MdNs.MdElement( "EXIF", "Saturation", true ); // 0=normal 1=low 2=high
	new MdNs.MdElement( "EXIF", "Sharpness", true ); // 0=normal 1=soft 2=hard
	new MdNs.MdElement( "EXIF", "DeviceSettingsDescription", true );
	new MdNs.MdElement( "EXIF", "SubjectDistanceRange", true );// 0=unk 1=macro 2=close 3=distant
	new MdNs.MdElement( "EXIF", "ImageUniqueID", true );
	new MdNs.MdElement( "EXIF", "GPSVersionID", true );
	new MdNs.MdElement( "EXIF", "GPSLatitude", true );
	new MdNs.MdElement( "EXIF", "GPSLongitude", true );
	new MdNs.MdElement( "EXIF", "GPSAltitudeRef", true ); // 0=above SL 2=below SL
	new MdNs.MdElement( "EXIF", "GPSAltitude", true );
	new MdNs.MdElement( "EXIF", "GPSTimeStamp", true );
	new MdNs.MdElement( "EXIF", "GPSSatellites", true );
	new MdNs.MdElement( "EXIF", "GPSStatus", true ); // A=measurement in progress V=measurement s interoperability
	new MdNs.MdElement( "EXIF", "GPSMeasureMode", true ); // 2=2d measurement 3=3d
	new MdNs.MdElement( "EXIF", "GPSDOP", true );
	new MdNs.MdElement( "EXIF", "GPSSpeedRef", true ); // K=kilometers per hour M=miles per hour N=knots
	new MdNs.MdElement( "EXIF", "GPSSpeed", true );
	new MdNs.MdElement( "EXIF", "GPSTrackRef", true ); // T=true M=Magnetic
	new MdNs.MdElement( "EXIF", "GPSTrack", true );
	new MdNs.MdElement( "EXIF", "GPSImgDirectionRef", true ); // T=true M=mag
	new MdNs.MdElement( "EXIF", "GPSImgDirection", true );
	new MdNs.MdElement( "EXIF", "GPSMapDatum", true );
	new MdNs.MdElement( "EXIF", "GPSDestLatitude", true );
	new MdNs.MdElement( "EXIF", "GPSDestLongitude", true );
	new MdNs.MdElement( "EXIF", "GPSDestBearing", true );
	new MdNs.MdElement( "EXIF", "GPSDestDistanceRef", true ); // K=kilometers M=miles N=knots
	new MdNs.MdElement( "EXIF", "GPSDestDistance", true );
	new MdNs.MdElement( "EXIF", "GPSProcessingMethod", true );
	new MdNs.MdElement( "EXIF", "GPSAreaInformation", true );
	new MdNs.MdElement( "EXIF", "GPSDifferential", true ); // 0=without correction 1=correction applied
	
	new MdNs.MdElement( "IPTC Core", "City", undefined, "photoshop:City" );
	new MdNs.MdElement( "IPTC Core", "CopyrightNotice", undefined, "dc:rights" );
	new MdNs.MdElement( "IPTC Core", "Country", undefined, "photoshop:Country" );
	new MdNs.MdElement( "IPTC Core", "CountryCode", true );
	new MdNs.MdElement( "IPTC Core", "Creator", undefined, "dc:creator" );
	new MdNs.MdElement( "IPTC Core", "ContactInfo", true ); // false );
	new MdNs.MdElement( "IPTC Core", "CreatorJobTitle", undefined, "photoshop:AuthorsPosition" );
	new MdNs.MdElement( "IPTC Core", "DateCreated", undefined, "photoshop:DateCreated" );
	new MdNs.MdElement( "IPTC Core", "Description", undefined, "dc:description" );
	new MdNs.MdElement( "IPTC Core", "DescriptionWriter", undefined, "photoshop:CaptionWriter" );
	new MdNs.MdElement( "IPTC Core", "Headline", undefined, "photoshop:headline" );
	new MdNs.MdElement( "IPTC Core", "Instructions", undefined, "photoshop:instructions" );
	new MdNs.MdElement( "IPTC Core", "IntellectualGenre", true );
	new MdNs.MdElement( "IPTC Core", "JobID", undefined, "photoshop:TransmissionReference" );
	new MdNs.MdElement( "IPTC Core", "Keywords", undefined, "dc:subject" );
	new MdNs.MdElement( "IPTC Core", "Location", true );
	new MdNs.MdElement( "IPTC Core", "Provider", undefined, "photoshop:credit" );
	new MdNs.MdElement( "IPTC Core", "Province-State", undefined, "photoshop:state" );
	new MdNs.MdElement( "IPTC Core", "RightsUsageTerms", undefined, "xmpRights:UsageTerms" );
	new MdNs.MdElement( "IPTC Core", "Scene", true ); // false );
	new MdNs.MdElement( "IPTC Core", "Source", undefined, "photoshop:Source" );
	new MdNs.MdElement( "IPTC Core", "SubjectCode", true ); // false );
	new MdNs.MdElement( "IPTC Core", "Title", undefined, "dc:title" );

	new MdNs.MdElement( "Camera Raw Settings", "Version", true );
	new MdNs.MdElement( "Camera Raw Settings", "WhiteBalance", true );
	new MdNs.MdElement( "Camera Raw Settings", "Temperature", true );
	new MdNs.MdElement( "Camera Raw Settings", "Tint", true );
	new MdNs.MdElement( "Camera Raw Settings", "Exposure", true );
	new MdNs.MdElement( "Camera Raw Settings", "AutoShadows", true );
	new MdNs.MdElement( "Camera Raw Settings", "Shadows", true );
	new MdNs.MdElement( "Camera Raw Settings", "Brightness", true );
	new MdNs.MdElement( "Camera Raw Settings", "Contrast", true );
	new MdNs.MdElement( "Camera Raw Settings", "Saturation", true );
	new MdNs.MdElement( "Camera Raw Settings", "Sharpness", true );
	new MdNs.MdElement( "Camera Raw Settings", "LuminanceSmoothing", true );
	new MdNs.MdElement( "Camera Raw Settings", "ColorNoiseReduction", true );
	new MdNs.MdElement( "Camera Raw Settings", "ChromaticAberrationR", true );
	new MdNs.MdElement( "Camera Raw Settings", "ChromaticAberrationB", true );
	new MdNs.MdElement( "Camera Raw Settings", "VignetteAmount", true );
	new MdNs.MdElement( "Camera Raw Settings", "ShadowTint", true );
	new MdNs.MdElement( "Camera Raw Settings", "RedHue", true );
	new MdNs.MdElement( "Camera Raw Settings", "RedSaturation", true );
	new MdNs.MdElement( "Camera Raw Settings", "GreenHue", true );
	new MdNs.MdElement( "Camera Raw Settings", "GreenSaturation", true );
	new MdNs.MdElement( "Camera Raw Settings", "BlueHue", true );
	new MdNs.MdElement( "Camera Raw Settings", "BlueSaturation", true );
	new MdNs.MdElement( "Camera Raw Settings", "ToneCurveName", true );
	new MdNs.MdElement( "Camera Raw Settings", "CameraProfile", true );
	new MdNs.MdElement( "Camera Raw Settings", "HasSettings", true );
	new MdNs.MdElement( "Camera Raw Settings", "HasCrop", true );
	new MdNs.MdElement( "Camera Raw Settings", "RawFileName", true );


// set up menu
	WasLib.createAppMenus();		
//	createMenu( "command", ContactSheet.strings.contactSheetMenu, "at the end of tools/id", "tools/id/contact", ContactSheet.showDialog, undefined, TYPES.DEFAULT_CONTACTSHEET );
	var menu = WasLib.createMenu( "command", ContactSheet.strings.contactSheetMenu, "at the end of tools/id", "tools/id/contact" );
	menu.onSelect = ContactSheet.showDialog;
}

"ContactSheet_ID_CS3.jsx loaded";

