so perhaps something like this?
/* second attempt */
// get the document layers array
var layers = document.layers;
// test to make sure layers is returning the document layers array
for (i=0; i<layer.length; i++){
print(layer[i].name);
}
// get the selected items in the document
var selItems = document.getItems({
selected: true
});
// make the item's layer the active layer in the document
selItem.layer.activate()
// while items are selected
while selItems.selected = true {
// cycle through the document layers
for (layer in document.layers) {
// if the item is in the active layer
if (selItem.layer == document.activeLayer){
//if the item is not in the copied layer
if (selItem.layer != layerCopy){
//make a duplicate layer
layerCopy = new Layer();
//copy the original layer name to the duplicate
layerCopy.name = selItem.layer.name + 'COPY';
}
// clone the original layer's children
layerClone = selItem.layer.children.clone();
// append the cloned children to the new layer
layerCopy.children = layerClone.children;
//remove cloned layer
layerClone.remove();
//unselect original layer's items
selItems.selected = false;
}
}
}
var newLayer = layerCopy;
var oldLayer = selItem.layer;
// move the newLayer below the oldlayer
newLayer.moveBelow(oldLayer);
// make the old layer hidden
oldLayer.visible = false;