var getNextHighestZindex = function (obj){
var highestIndex = 0;
var currentIndex = 0;
var elArray = Array();
if(obj){ elArray = obj.getElementsByTagName("*"); }else{ elArray = document.getElementsByTagName("*"); }
for(var i=0; i < elArray.length; i++){
if (elArray[i].currentStyle){
currentIndex = parseFloat(elArray[i].currentStyle["zIndex"]);
}else if(window.getComputedStyle){
currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue("z-index"));
}
if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
}
return(highestIndex+1);
}
Это максимум +1