// Fireworks Css Layer output.
// Version 2.0 25JAN99

var doComments = fw.getPref("HTMLCommentsOn");
// When doComments is set to "true" the WRITE_HTML_COMMENT function
// includes HTML comments in the exported file.
function WRITE_HTML_COMMENT(str) {
	if (doComments) WRITE_HTML("<!--"+str+"-->\n");
}

// Write general comments for copying and pasting Fireworks-generated code into existing HTML documents.
WRITE_HTML_COMMENT("To put this html into an existing HTML document, you must copy the JavaScript and");
WRITE_HTML_COMMENT("paste it in a specific location within the destination HTML document. You must then copy");
WRITE_HTML_COMMENT("and paste the table in a different location.");
if (doComments) WRITE_HTML("\n");


WRITE_HTML("<!-- saved from url=(0014)about:internet -->\n");
WRITE_HTML("<html>\n");
WRITE_HTML("\n")

WRITE_HTML("<head>\n");
WRITE_HTML("\n")

// Use Base Name from export dialog as document title.
WRITE_HTML("<title>", exportDoc.filename, "</title>\n");
WRITE_HTML("\n")

// Write Meta tags.
WRITE_HTML("<meta http-equiv=\"Content-Type\" content=\"text/html;", fw.textOutputEncoding, "\">\n"); 
WRITE_HTML("<meta name=\"description\" content=\"FW MX CSS Layer\">\n");
WRITE_HTML("\n")

// Write HTML target and date created.
var d = new Date();
WRITE_HTML_COMMENT("Fireworks MX CSS Layer.\n    Created ", d);

// Close head tag.
WRITE_HTML("</head>\n");
WRITE_HTML("\n")

// Function LayerName determines the name of the current layer.
function LayerName(str) {
	var newName = str.toString().replace(/_/g, "");
	newName = newName.replace(/ /g, "");
	if (newName == "") newName = "EmptyName";
	if (!newName) newName = "EmptyName";
	if (newName.search(/\d/) == 0) {
		newName = "L"+newName;
	}
	return(newName);
}

// Function CellName determines the name for the image in a particular table cell.
// Cellname is based off of the slice name if one was specified. Otherwise the
// Base file name from the export dialog is used.
function CellName(str, row, col) {
	var cellName = str.toString();
	// remove illegal characters
	cellName = cellName.replace(/\W/g, "");
	// if it starts with a number, add N to the front.
	if (cellName == "") {
		cellName = "N" + exportDoc.imagename + "_" + (row+1) + "_" + (col+1);
		// remove illegal characters
		cellName = cellName.replace(/\W/g, "");
	}
	if (cellName.search(/\d/) == 0) {
		cellName = "N"+cellName;
	}
	return(cellName);
}

// Begin body tag. Set background color to Fireworks document canvas color.
WRITE_HTML("<body bgcolor=\"#", exportDoc.backgroundColor, "\">\n");
WRITE_HTML("\n")

// Write comment for start of code copy/paste section.
WRITE_HTML_COMMENT("------------------------ BEGIN COPYING THE HTML HERE --------------------------");

// Analyze each slice and determine whether or not an image file is exported.
	var curCol;
	var curRow;
	var curSlice;
	var curZ = 1;
	for (curRow = 0; curRow < slices.numRows; curRow++) {
		for (curCol = 0; curCol < slices.numColumns; curCol++) {
			curSlice = slices[curRow][curCol];
			
			if (curSlice.skipCell) continue; 

			if (!curSlice.hasImage) {
				// no image
				continue;
			}

			if (curSlice.isUndefined) {
				continue;
			}

			if (curSlice.hasImage) {

				// Determine the current slice's file name and name the layer accordingly.
				var imageName = curSlice.getFrameFileName(0);
				if (imageName == "") continue;
				var layerName = LayerName(imageName);
				var cellName = CellName(imageName, curRow, curCol);
				
				// 2005 Mar 31 - mthrall
				// Bug 90624 states there is a problem with the div id attribute being the same as the img name attribute
				// In order to make things happier, what we'll do is append img to cellName so they are different
				if (layerName == cellName) {
					cellName += "_img";
				}
				
				// Write the div tag to specify layer. Obtain and enter height, width and 
				// positioning information.
				// Ex: <div id="Layer1" style="position:absolute; left:35px; top:34px; width:115px; height:96px; z-index:1">
				WRITE_HTML("<div id=\"", layerName, "\" style=\"position:absolute; ");
				WRITE_HTML("left:", curSlice.left, "px; top:", curSlice.top, "px;")
				WRITE_HTML("width:", curSlice.width, "px; height:", curSlice.height, "px;");
				WRITE_HTML("z-index:", curZ, "; visibility:visible;\">");
				
				// Place image.
				// Ex: <img name="N_03_02" src="File_03_02.gif" width="79" height="71" border="0"
				WRITE_HTML("<img name=\"", cellName, "\" src=\"",
					slices.imagesDirPath, imageName, curSlice.imageSuffix, "\" width=\"",
					curSlice.width,"\" height=\"", curSlice.height, "\" border=\"0\"");
				
				// Close layer div tag.
				WRITE_HTML("></div>\n");
				curZ++;
			}

		}
	}		

WRITE_HTML("\n");
// Write comment for end of code copy/paste section.
WRITE_HTML_COMMENT("------------------------- STOP COPYING THE HTML HERE -------------------------");

WRITE_HTML("</body>\n")

WRITE_HTML("</html>\n")

var retval = "ok";
retval;

