
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2008 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
* $DateTime: 2008/04/10 13:35:00 $
*
* Adobe Output Module 2.0
*
* MediaGallery Originally Written by Quality Process Incorporated, Enhanced by
* Adobe System China. Contact Sheet written by Adobe System China.
* 
*
**************************************************************************/


AOM.ZStringHtmlDialogTitle = AOM.AMG.localize("$$$/MediaGallery/JavaScript/HtmlGallery/CreateGallery=Create Gallery");



AOM.AmgHtmlGalleryCreator = function (images, destinationFolder, taskManager, document, createMode, jpegQuality)
{
	try
	{
	    /* Store the current document in order to distinguish between multiple
	     * Bridge windows. */
	    AOM.AmgHtmlGalleryCreator.currentDocument = document;
	    
		var galleryFolder = AOM.AmgHtmlGalleryCreator.initializeHtmlGalleryFolder(destinationFolder);
		var imageMaximumSize = AOM.AmgHtmlGalleryCreator.initializeSizesList();
		var imagesFolder = galleryFolder + "content/bin/";
		var xmlFile = new File(galleryFolder + "html.xml");
		var outputFile= new File(galleryFolder + "html.out");
		var xsltFile = new File(AOM.AMG.Paths.app + "resources/htmlGallery/transformer.xslt");
		var copyright = AOM.AmgHtmlGalleryCreator.get("copyrightInfo");
		
        AOM.AmgHtmlGalleryCreator.currentDocument = undefined;
		
		var callback = function () 
		{
		    /* Store the current document in order to distinguish between multiple
	         * Bridge windows. */
	        AOM.AmgHtmlGalleryCreator.currentDocument = document;
			AOM.AmgHtmlGalleryCreator.replaceList = {};
			AOM.AmgHtmlGalleryCreator.makeXml(images, xmlFile, galleryFolder);
			AOM.AmgHtmlGalleryCreator.transform(xmlFile, xsltFile, outputFile);
			AOM.AmgHtmlGalleryCreator.ripFiles(outputFile, galleryFolder);
			AOM.AmgHtmlGalleryCreator.replaceNames(galleryFolder);
			
            AOM.AmgHtmlGalleryCreator.currentDocument = undefined;
			//xmlFile.remove();
			//outputFile.remove();
		}
		AOM.AmgGalleryCreator.processImages(
			images, AOM.AmgHtmlGalleryCreator.sizesList, imageMaximumSize,
			imagesFolder, copyright, taskManager, createMode,
			{
				action:callback,
				title: AOM.ZStringHtmlDialogTitle,
				description: AOM.AMG.localize("$$$/MediaGallery/JavaScript/HtmlGallery/GenerateHtml=Generate html...")
			},
			jpegQuality
		);
	}
	catch(e)
	{
	    taskManager.showProgressOnStop = false;
	    taskManager.stop({
            title: AOM.ZStringHtmlDialogTitle,
            description: AOM.AMG.localize("$$$/MediaGallery/JavaScript/HtmlGallery/AccessDenied=Error creating gallery. Access denied."),
            button: AOM.AMG.localize("$$$/MediaGallery/JavaScript/HtmlGallery/OK=OK") });
	    AOM.AMG.Log.writeError("AOM.AmgHtmlGalleryCreator caught - " + e);
	}
	return 0;
}
// TODO - can this be consolidated with same function in flashGallery.jsx?
AOM.AmgHtmlGalleryCreator.initializeSizesList = function ()
{
	// ignore the image sizes supplied via gallerymaker.xml
	// and use the JeffT approved dimensions
	var imageSizes = AOM.AmgGalleryMaker.imageSizes;
	var get = AOM.AmgHtmlGalleryCreator.get;
	var preview = get("previewSize");
	if (preview == undefined)
		AOM.AMG.Log.writeError("AOM.AmgHtmlGalleryCreator.sizesList - missing previewSize");
	
	AOM.AmgHtmlGalleryCreator.sizesList = {};	
	var sizesList = AOM.AmgHtmlGalleryCreator.sizesList;
	sizesList.large = {}
    sizesList.large.width = preview;
	sizesList.large.height = preview;
    
	sizesList.large.size = "large";
	sizesList.thumbnail = {}
	sizesList.thumbnail.width = 129;
	sizesList.thumbnail.height = 129;
	sizesList.thumbnail.size = "thumb";
	return Math.max(sizesList.large.width, sizesList.large.height);
}
AOM.AmgHtmlGalleryCreator.processSpecialChars = function( filename, needEscape, noURL )
{
	if( filename == undefined )
		return "";
	
	if( needEscape )
	{
		filename = filename.replace(/&/g, "&amp;").replace(/\'/g, "&apos;");
		filename = filename.replace(/</g, "&lt;").replace(/>/g, "&gt;");
		if (!noURL)
			filename = filename.replace(/#/g, "%23");
	}
	else
	{
		filename = filename.replace(/&amp;/g, "&").replace(/&apos;/g, "\'");
		filename = filename.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
		if (!noURL)
			filename = filename.replace(/%23/g, "#");
	}
	return filename;
}
AOM.AmgHtmlGalleryCreator.makeXml = function (images, file, galleryFolder)
{
	var log = false;
	if (file instanceof File == false)
		return AOM.AMG.Log.writeError("AOM.AmgHtmlGalleryCreator.makeXml - file is not File");
	var imageCount = 0;
	for (var i = 0; i < images.length; i++)
	{
		if (!images[i].amgSkip()) 
			imageCount++;
	}
	
	var imgXml = function (image, id, indent)
	{
		if (AOM.AMG.verbose || log) AOM.AMG.Log.writeLine("imgXml - " + image.name);
		if (image.amg.sizes == undefined)
			AOM.AMG.Log.writeError("itemXml - image.amg.sizes is undefined ("+image.name+")");

		var metadata = image.metadata;
		if (metadata != undefined)
			metadata.namespace = "http://purl.org/dc/elements/1.1/";
		var title = (metadata != undefined && metadata.title != undefined) ? metadata.title : "";
		title = AOM.AmgHtmlGalleryCreator.processSpecialChars(title.toString(), true, true);
		var description = (metadata != undefined && metadata.description != undefined) ? metadata.description : "";
		description = AOM.AmgHtmlGalleryCreator.processSpecialChars(description.toString(), true, true);
		
		var text = "";
		id += "_"+(new Date()).getTime(); // how can we get an honest to goodness guid? for now use the number of milliseconds since Jan 1, 1970
		var subName = AOM.AmgFlashGalleryCreator.escapeSpecialChars(image.name, true);
		var displayName = AOM.PDFGenerator.combineDiacriticMarks(subName);
		var alteredName = AOM.AmgGalleryCreator.removeImageExtension(image.amg.alteredName);
		alteredName = AOM.AmgHtmlGalleryCreator.processSpecialChars(alteredName, true);
		var numName = "%_tempFileName" + alteredName + "%";
		if (AOM.AmgHtmlGalleryCreator.replaceList[numName] == undefined)
			AOM.AmgHtmlGalleryCreator.replaceList[numName] = AOM.AmgGalleryCreator.removeImageExtension(displayName);
		var userInput = AOM.AMG.userInput(AOM.AmgHtmlGalleryCreator.currentDocument);
		var showFileNames = userInput.get("showFileNames");
		var showExtensions = userInput.get("showExtensions");
		if(showExtensions != "true")
			displayName = AOM.AmgGalleryCreator.removeImageExtension(displayName);
		text += indent + "<img orientation=\"BC\" imageID=\""+ id +"\" filename=\""+ alteredName +"\" tipname=\"" + numName + "\" >\n";
		text += indent + "	<text>\n";
		text += indent + "		<title>"+title+"</title>\n";
		text += indent + "		<description>"+description+"</description>\n";
		text += indent + "	</text>\n";
		var sizesList = AOM.AmgHtmlGalleryCreator.sizesList;
		var get = AOM.AmgHtmlGalleryCreator.get;
		var largeMax = Math.max(sizesList.large.width, sizesList.large.height);
		previewFullWidth = Math.max(largeMax + 30, Math.ceil(160.5 * get("numCols")));
		if (showFileNames == "true") {
			text += indent + "    <hasfilename>true</hasfilename>\n";
			text += indent + "    <displayname>" + displayName + "</displayname>\n";
			text += indent + "    <displaywidth>" + previewFullWidth + "</displaywidth>\n";
		}
		for (var i in image.amg.sizes)
		{
			var size = image.amg.sizes[i];
			var relativePath = size.imagePath.substr(galleryFolder.length);
			relativePath = AOM.AmgHtmlGalleryCreator.processSpecialChars(relativePath, true);
			text += indent + "	<rendition path=\""+ relativePath +"\" height=\""+ size.height +"\" width=\""+ size.width +"\" size=\""+ size.size +"\"></rendition>\n";
		}
		text += indent + "</img>";
		return text;
	}
	file.encoding = "UTF8";
	file.lineFeed = "unix";
	if (file.open("w", "TEXT", "????"))
	{
		file.write("\uFEFF");
		file.writeln("<?xml version='1.0' encoding='UTF-8'?>");
		file.writeln("<photoCollection mode=\"publish\">");
		file.writeln("	<display>");
		file.writeln(		AOM.AmgHtmlGalleryCreator.displayStyleText("		"));
		file.writeln(		AOM.AmgHtmlGalleryCreator.displayMetadataText("		"));
		file.writeln(		AOM.AmgHtmlGalleryCreator.displayLocalizationText("		"));
		file.writeln("	</display>");
		file.writeln(	AOM.AmgHtmlGalleryCreator.headText("	"));
		// Note - at this point the image count may include images that
		// prove to not be renderable but are not marked to skip...
		// If we need to be really accurate we should do something
		// like write the <img> text first and then concatenate with
		// the text that needs to proceed it - really just this one
		// line with the <samples> element... 
		file.writeln("	<samples totalGallerySize=\"" + imageCount + "\" firstSampleIndex=\"1\">");
		for (var i = 0; i < images.length; i++)
		{
			// write the xml and create tasks for the image processing
			if (!images[i].amgSkip())
			{
				var s = imgXml(images[i], i, "	");
				if (s != undefined)
					file.writeln(s);
			}
		}
		file.writeln("	</samples>");
		file.writeln(	AOM.AmgHtmlGalleryCreator.siteParamsText(1, imageCount, "	"));	
		file.writeln("</photoCollection>");
		file.close();
	}
	else
	{
		AOM.AMG.Log.writeError(AOM.AMG.localize("$$$/MediaGallery/htmlGallery/couldntOpen=Could not open ") + file.fsName);
		throw({title:AOM.ZStringHtmlDialogTitle, description:AOM.AMG.localize("$$$/MediaGallery/htmlGallery/couldntOpen=Could not open ") + file.fsName});
	}
}
AOM.AmgHtmlGalleryCreator.initializeHtmlGalleryFolder = function (destinationFolder)
{
	// create the directory structure
	var subFolders = new Array();
	subFolders.push("/content");
	subFolders.push("/content/bin");
	subFolders.push("/content/bin/images");
	subFolders.push("/content/bin/images/large");
	subFolders.push("/content/bin/images/thumb");
	subFolders.push("/resources");
	subFolders.push("/resources/css");
	subFolders.push("/resources/js");
	
	// create a list of source and destination files
	var source;
	var sourcePath = AOM.AMG.Paths.app + "/resources/htmlgallery/";
	var filePath;
	var file;
	var sourceDestinationList = new Array();
	
	file = "master.css";
	filePath = destinationFolder + "/resources/css/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});
	
	file = "ie6.css";
	filePath = destinationFolder + "/resources/css/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});

	file = "ie7.css";
	filePath = destinationFolder + "/resources/css/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});

	file = "liveUpdate.js";	
	filePath = destinationFolder + "/resources/js/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});
		
	file = "pngFix.js";
	filePath = destinationFolder + "/resources/js/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});
	
	file = "cutName.js";	
	filePath = destinationFolder + "/resources/js/" + file;
	sourceDestinationList.push({'source' : sourcePath + file, 'destination' : filePath});
	
	AOM.AMG.createFolderContents(destinationFolder, subFolders, sourceDestinationList);
	
	return destinationFolder + "/";
}

AOM.AmgHtmlGalleryCreator.ripFiles = function (source, path)
{
	var log = false;
	
	var destination = undefined;
	source.encoding = "UTF-8";
	source.lineFeed = "unix";
	if (source.open("r", "TEXT", "????"))
	{
		// read a line at a time looking for <file> and </file>
		while (source.eof == false)
		{
			var line = source.readln();
			if (line.indexOf("<file ") != -1)
			{
				// we found the start of a file - get the file name
				var search = "name=\"";
				var start = line.indexOf(search);
				var end = line.indexOf("\"", start + search.length);
				var fileName = line.substr(start + 6, end - start - search.length);
				
				// change escaped chars contains in filename to original chars.
				fileName = AOM.AmgHtmlGalleryCreator.processSpecialChars(fileName, false);
				// destination shouldn't be open but just in casee...				
				if (destination != undefined)
					destination.close();
					
				destination = new File(path + fileName);
				if (AOM.AMG.verbose || log) AOM.AMG.Log.writeLine("ripFiles - destination is " + destination);
				destination.encoding = "UTF-8";
				destination.lineFeed = "unix";
				destination.open("w", "TEXT", "????");
				if (destination != undefined)
				{
					destination.write("\uFEFF");
					if (fileName.substr(fileName.length-4) == ".xml")
					{
						destination.writeln("<?xml version=\"1.0\"?>\n");
						destination.writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n");
						destination.writeln("\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n\n");
					}
				}
				// it turns out we can't expect the <file> and </file> delimiters to be on their own
				// lines. for now we'll check for </file> in this line and, if there, write the contents.
				// ultimately this routine should be re-written...
				if (destination != undefined)
				{
					if (line.indexOf("</file>") != -1)
					{
						var content = line.split(/<[^>]*>/)[1];
						if (content != undefined)
							destination.writeln(content);
						destination.close();
						destination = undefined;
					}
				}
				// it also turns out that some transforms will have content on the line in
				// which the starting <file> tag appears:
				//
				// <file name='theFileName'>Here's stuff that should be in the file.
				//
				// See the css xml code for a hack that keeps it from happening there. 
				// eventually this routine should have the smarts to deal with it...
				continue;
			}
			if (line.indexOf("</file>") != -1)
			{
				if (destination != undefined)
				{
					destination.close();
					destination = undefined;
				}
				continue;
			}
			// escape "'" in content of a href when the content is enclosed by ' '
			var re = /(href=\')(.+?\'.+?)(\.html\')/g;
			if( line.match( re ) ) {		
				var newContent = RegExp.$2.replace(/\'/g,"\\'");
        		line = line.replace( re, "$1"+newContent+"$3" );
      		}
			if (line.indexOf("<displayname>") != -1 || line.indexOf("id=\"tempDiv\"") != -1 
				|| line.indexOf("id=\"largeName\"") != -1 || line.indexOf("str = ") != -1) {
				for (var i=0; i< line.length; i++) {
					destination.write(line[i]);
				}
				destination.write("\n");
				continue;
			}
			if (destination != undefined)
				destination.writeln(line);
		}
		source.close();
		if (destination != undefined)
			destination.close();
	}
}

AOM.AmgHtmlGalleryCreator.transform = function (xml, xslt, out)
{
	if (!AOM.AMG.Xslt.transform(xml, xslt, out))
		return AOM.AMG.Log.writeError("AOM.AmgHtmlGalleryCreator.transform - AOM.AMG.Xslt.transform failed");
}

AOM.AmgHtmlGalleryCreator.siteParamsText = function (firstImage, lastImage, indent)
{
	var text = "";
	text += indent + "<siteParams>\n";
	text += indent + "	<firstImage index=\""+ firstImage +"\"></firstImage>\n";
	text += indent + "	<lastImage index=\""+ lastImage +"\"></lastImage>\n";
	text += indent + "	<mode value=\"all\"></mode>\n";
/*
	if (gallery.siteParams.mode == "detail")
	{
		text += indent + "	<mode value=\"detail\"></mode>\n";
		text += indent + "	<progressName hatOne=\"1\" text=\"$$$/AgWPG/Templates/DefaultHTML/Progress/DetailPagesProgress=Detail pages ^1-^2\" hatTwo=\"8\"></progressName>\n";
	}
	if (gallery.siteParams.mode == "mainIndex")
	{
		text += indent + "	<mode value=\"mainIndex\"></mode>\n";
		text += indent + "	<progressName hatOne=\"1\" text=\"$$$/AgWPG/Templates/DefaultHTML/Progress/MainIndexProgress=Main Grid pages ^1-^2\" hatTwo=\"1\"></progressName>\n";
	}
*/
	text += indent + "</siteParams>";
	return text;
} 

AOM.AmgHtmlGalleryCreator.headText = function (indent)
{
	var sizesList = AOM.AmgHtmlGalleryCreator.sizesList;
	var get = AOM.AmgHtmlGalleryCreator.get;
	var text = "";
	text += indent + "<head>\n";
	text += indent + "	<siteTitle></siteTitle>\n";
	text += indent + "	<collectionName></collectionName>\n";
	text += indent + "	<collectionTitle></collectionTitle>\n";
	text += indent + "	<collectionDescription></collectionDescription>\n";
	text += indent + "	<contactInfo></contactInfo>\n";
	text += indent + "	<slideDuration></slideDuration>\n";
	text += indent + "	<sizes>\n";
	text += indent + "		<size name=\"large\" height=\""+sizesList.large.height+"\" width=\""+sizesList.large.width+"\"></size>\n";
	//text += indent + "		<size name=\"small\" height=\""+get("smallHeight")+"\" width=\""+get("smallWidth")+"\"></size>\n";
	text += indent + "		<size name=\"thumb\" height=\""+sizesList.thumbnail.height+"\" width=\""+sizesList.thumbnail.width+"\"></size>\n";
	text += indent + "	</sizes>\n";
	text += indent + "</head>";
	return text;

}

AOM.AmgHtmlGalleryCreator.displayLocalizationText = function (indent)
{
	var text = "";
	text += indent + "<localization>\n";
    text += indent + "	<item id=\"AdobeLightroomWebSite\" localized=\"http://labs.adobe.com/technologies/lightroom/\"></item>\n";
    text += indent + "	<item id=\"AdobeLightroomBeta\" localized=\"Adobe Lightroom Beta\"></item>\n";
	text += indent + "	<item id=\"Fullsize\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/Fullsize=Fullsize")+"\"></item>\n";
	text += indent + "	<item id=\"Next\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/Next=Next")+"\"></item>\n";
	text += indent + "	<item id=\"Previous\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/Previous=Previous")+"\"></item>\n";
	text += indent + "	<item id=\"EmptyGallery\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/EmptyGalleryMessage=There are no images in this gallery.")+"\"></item>\n";
	text += indent + "	<item id=\"more\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/more=more")+"\"></item>\n";
	text += indent + "	<item id=\"Index\" localized=\""+AOM.AMG.localize("$$$/AgWPG/Templates/HTML/output/Index=Index")+"\"></item>\n";
	text += indent + "</localization>";
	return text;
}
AOM.AmgHtmlGalleryCreator.displayMetadataText = function (indent)
{
	var get = AOM.AmgHtmlGalleryCreator.get;
	var contactInfoName = get("contactInfoName");
	var contactInfoLink = get("contactInfoEmail");
	if (contactInfoName.amgIsEmpty() && !contactInfoLink.amgIsEmpty())
		contactInfoName = contactInfoLink;
	if (!contactInfoLink.amgIsEmpty())
		contactInfoLink = "mailto:" + contactInfoLink;

	var text = "";
	text += indent + "<metadata>\n";
	text += indent + "	<creationDate formatted=\""+Date()+"\"></creationDate>\n";
	text += indent + "	<groupTitle value=\""+ get("groupInfoTitle") +"\"></groupTitle>\n";
	text += indent + "	<contactInfo value=\""+ contactInfoName +"\" link=\""+ contactInfoLink +"\"></contactInfo>\n";
	text += indent + "	<siteTitle value=\""+ get("siteInfoTitle") +"\"></siteTitle>\n";
	text += indent + "	<groupDescription value=\""+ get("groupInfoDescription") +"\"></groupDescription>\n";
	text += indent + "</metadata>";
	return text;
}
AOM.AmgHtmlGalleryCreator.displayStyleText = function (indent)
{
	var sizesList = AOM.AmgHtmlGalleryCreator.sizesList;
	var get = AOM.AmgHtmlGalleryCreator.get;
	var largeMax = Math.max(sizesList.large.width, sizesList.large.height);
	previewFullWidth = Math.max(largeMax + 30, Math.ceil(160.5 * get("numCols")));
	wrapper2Width = Math.ceil(161.25 * get("numCols"));
	stageWrapperWidth = Math.max(largeMax + 30, wrapper2Width); // DWR - strange constants abound
	previewFullHeight = largeMax;
	/*Workaround, to kill cache issue in Safari*/
	var cssVersion = AOM.AMG.getRandString();
	
	var text = "";
	text += indent + "<style ";
	text += "cellBorderColor=\"#"+get("gridLines")+"\" ";
	text += "cellRolloverColor=\"#"+get("rollover")+"\" ";
	text += "cssVersion=\""+cssVersion+"\" ";
	text += "idplateEnabled=\"false\" ";
	text += indent + "	" + "css=\"\n"; // Note - without this linefeed the Win transform will miss 
	text += indent + "		" + "#previewFull {background-color: #"+get("detailMatte")+" !important; width: "+ previewFullWidth +"px !important; color: inherit}\n";
	text += indent + "		" + "#liveUpdateContactInfo {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + ".borderRightDotted {border-right: 1px dotted #"+get("gridLines")+" !important;}\n";
	text += indent + "		" + ".logo {display: none !important;}\n";
	text += indent + "		" + "#liveUpdateCollectionDescription {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + ".detailNav, .detailLinks, #detailCaption, #detailTitle {color: #"+get("detailText")+" !important; background-color: inherit;}\n";
	text += indent + "		" + ".emptyThumbnail {background-color: #"+get("cells")+" !important; color: inherit;}\n";
	text += indent + "		" + ".thumbnail {background-color: #"+get("cells")+" !important; color: inherit;}\n";
	text += indent + "		" + ".previewFullImage {height: "+previewFullHeight+"px !important; width: "+previewFullWidth+"px !important;}\n"; // static width and height?
	text += indent + "		" + "#stage2 {width: "+stageWrapperWidth+"px !important;}\n"; // static width?
	text += indent + "		" + ".itemNumber {display: "+(get("showNumbers") != "false" ? "inherit" : "none")+" !important; color: #"+get("numbers")+" !important; background-color: inherit;}\n";
	text += indent + "		" + "#content {background-color: #"+get("background")+" !important; color: inherit;}\n";
	text += indent + "		" + ".borderTopLeft {border-top: 1px solid #"+get("gridLines")+" !important; border-left: 1px solid #"+get("gridLines")+" !important;}\n";
	text += indent + "		" + "#stage {width: "+wrapper2Width+"px !important;}\n"; // static width?
	text += indent + "		" + ".caption {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + "#wrapper2 {width: "+stageWrapperWidth+"px !important;}\n";
	text += indent + "		" + ".borderBottomRight {border-right: 1px solid #"+get("gridLines")+" !important; border-bottom: 1px solid #"+get("gridLines")+" !important;}\n";
	text += indent + "		" + "#wrapper {width: "+wrapper2Width+"px !important;}\n"; // static width?
	text += indent + "		" + "#liveUpdateCollectionTitle {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + ".paginationLinks, .pagination, #liveUpdatePagination {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + ".selectedThumbnail, .thumbnail:hover {background-color: #"+get("rollover")+" !important; color: inherit;}\n"; // static color?
	text += indent + "		" + "#liveUpdateSiteTitle {color: #"+get("text")+" !important; background-color: inherit;}\n";
	text += indent + "		" + "#thumbnailName {color: #"+get("detailText")+" !important; background-color: inherit;}\n";
	text += indent + "		" + "#largeName {color: #"+get("detailText")+" !important; background-color: inherit; margin-top: 10px; margin-left: 7px; margin-right: 7px;}\n";
	text += indent + "		" + ".borderBottom {border-bottom: 1px solid #"+get("gridLines")+" !important;}\n";
	text += indent + "		" + ".borderRight {border-right: 1px solid #"+get("gridLines")+" !important;}\n";
	text += indent + "		" + "body {background-color: #"+get("background")+" !important; color: inherit;}\n";
	text += indent + "	" + "\"\n";
	text += indent + "identityPlateAbsolutePath=\"\" \n";
	text += "numCols=\""+get("numCols")+"\" \n";
	text += "numRows=\""+get("numRows")+"\" \n";
	text += "homePage=\"index.html\" \n";
	text += "imageBase=\"content\" \n";
	text += "cellColor=\"#"+get("cells")+"\">\n";
	text += indent + "</style>";
	return text;
}

// The fieldIds property crosswalks the values
// required to create xml files to the user inpu
// data store.
AOM.AmgHtmlGalleryCreator.fieldIds = {};
AOM.AmgHtmlGalleryCreator.fieldIds.contactInfoName = "contactName";
AOM.AmgHtmlGalleryCreator.fieldIds.contactInfoEmail = "contactEmail";
AOM.AmgHtmlGalleryCreator.fieldIds.copyrightInfo = "copyrightView";
AOM.AmgHtmlGalleryCreator.fieldIds.groupInfoDescription = "groupDescription";
AOM.AmgHtmlGalleryCreator.fieldIds.groupInfoTitle = "groupTitle";
AOM.AmgHtmlGalleryCreator.fieldIds.numCols = "gridSizeNumCols";
AOM.AmgHtmlGalleryCreator.fieldIds.numRows = "gridSizeNumRows";
AOM.AmgHtmlGalleryCreator.fieldIds.showNumbers = "showCellNumbers";
AOM.AmgHtmlGalleryCreator.fieldIds.siteInfoTitle = "siteTitle";
AOM.AmgHtmlGalleryCreator.fieldIds.previewSize = "io_html_preview";

AOM.AmgHtmlGalleryCreator.fieldIds.text = "foregroundColor";
AOM.AmgHtmlGalleryCreator.fieldIds.detailText = "detailTextColor";
AOM.AmgHtmlGalleryCreator.fieldIds.background = "backgroundColor";
AOM.AmgHtmlGalleryCreator.fieldIds.detailMatte = "detailMatteColor";
AOM.AmgHtmlGalleryCreator.fieldIds.cells = "cellColor";
AOM.AmgHtmlGalleryCreator.fieldIds.rollover = "cellRolloverColor";
AOM.AmgHtmlGalleryCreator.fieldIds.gridLines = "cellBorderColor";
AOM.AmgHtmlGalleryCreator.fieldIds.numbers = "itemNumberColor";

/*
AOM.AmgHtmlGalleryCreator.fieldIds.thumbHeight = "io_thumbHeight";
AOM.AmgHtmlGalleryCreator.fieldIds.thumbWidth = "io_thumbWidth";
AOM.AmgHtmlGalleryCreator.fieldIds.largeHeight = "io_largeHeight";
AOM.AmgHtmlGalleryCreator.fieldIds.largeWidth = "io_largeWidth";
*/
//AOM.AmgHtmlGalleryCreator.fieldIds.xyz = "copyrightView";
//AOM.AmgHtmlGalleryCreator.fieldIds.xyz = "detailTextColor";


AOM.AmgHtmlGalleryCreator.get = function(field)
{
	var id = AOM.AmgHtmlGalleryCreator.fieldIds[field];
	if (id == undefined)
	{
		AOM.AMG.Log.writeError("HtmlGalleryCreator.get - unknown field (" + field + ")");
		return "field_" + field;
	}
	var value = AOM.AMG.userInput(AOM.AmgHtmlGalleryCreator.currentDocument).get(id);
	if (value == undefined)
	{
		//AOM.AMG.Log.writeError("HtmlGalleryCreator.get - unknown id (" + id + ")");
		return "";
	}

	if (AOM.AMG.Tests.isNumber(value)) {
		return value;
	} else {
		return AOM.AmgUserInput.htmlEncoding(value);
	}
}

AOM.AmgHtmlGalleryCreator.replaceNames = function (galleryFolder)
{
	var regex = /%_tempFileName_[^%\s]*?%/;
	AOM.AmgFlashGalleryCreator.searchReplaceFile(new File(galleryFolder + "index.html"), regex, AOM.AmgHtmlGalleryCreator.replaceList);
	var folder = new Folder (galleryFolder + "content/");
	var files = folder.getFiles();
	for (var i=0; i<files.length; i++) {
		var filename = files[i].name;
		if (filename.length > 5 && (filename.substr(filename.length-5, 5) == ".html"))
			AOM.AmgFlashGalleryCreator.searchReplaceFile(files[i], regex, AOM.AmgHtmlGalleryCreator.replaceList);
	}
}


/* end html gallery code */
