//--not for batch--
// DistributeToLayers.jsf
// This command will take multiple objects and move them to indivual layers
// Copyright (c) 2000 Macromedia. All rights reserved.

// Save the current frame in the document
var curFrameNum = fw.getDocumentDOM().currentFrameNum;

// get the total layers minus the web layer
var numLayers = fw.getDocumentDOM().layers.length-1;  // skip the web layer.

var curLayerNum;

// loop through the current number of layers
for (curLayerNum = numLayers-1; curLayerNum >= 0; curLayerNum--) {
	// get the current layer
	var curLayer = fw.getDocumentDOM().layers[curLayerNum];

	// get the elements on the current layer
	var elements = curLayer.frames[curFrameNum].elements;
	//if layer is locked cannot distribute so continue to next layer.
	if(curLayer.frames[curFrameNum].locked == true)
		continue;
	// get the number of elements
	var numElements = elements.length-1;
	var i;

	// loop through the number of elements
	for (i=0; i<numElements; i++) {
		// get the current layer number
		if (i==0) fw.getDocumentDOM().currentLayerNum = curLayerNum;
		// add layers for the number of elements
		fw.getDocumentDOM().addNewLayer(null, false);
	}
	// again loop through the number of elements
	for (i=0; i<numElements; i++) {
		// set the current layer
		curLayer = fw.getDocumentDOM().layers[curLayerNum];
		// get the elements on the current layer
		elements = curLayer.frames[curFrameNum].elements;
		// select none
		fw.getDocumentDOM().selectNone();
		// create a new array that will hold the selection
		var sel = new Array();
		// populate the array
		sel[0] = elements[elements.length-2];
		// select all of the elements of the array in Fireworks
		fw.selection = sel;
		// move the selection to its new layer
		fw.getDocumentDOM().moveSelectionToLayer(curLayerNum+i+1, false, "none", -1);
	}
}
