var a = app.activeDocument.activeLayer;
var w = a.bounds[2]-a.bounds[0];
var h = a.bounds[3]-a.bounds[1];
var maxW = 317, maxH = 317;
var s = 1;
if (w > h) {
s = maxW / w;
w = maxW;
h = h * s;
} else {
s = maxH / h;
h = maxH;
w = w * s;
}
app.activeDocument.resizeImage(new UnitValue(w, "px"), new UnitValue(h, "px"), null, ResampleMethod.BICUBIC);