
  /////////////////////////////
  // 
  //  This code was written as an example code, modify it your needs !
  //  This code is explained in the tutorials over at [http://www.kirupa.com] look for the 'scripting' tutorials
  //  Written by mlk over at www.kirupaforum.com, post over there for help !
  //
  //  [mlkdesign@online.fr]
  //  july 2004
  //

displayDialogs = DialogModes.NO;

var defaultRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if ((documents.length > 0) && (activeDocument.saved)){

	var AD = activeDocument;
	var initialFolder = activeDocument.path;

	AD.flatten();
	var docWidth = AD.width;
	var docHeight = AD.height;
	var docRes = AD.resolution;
   
// Save options: you can change STANDARDBASELINE to OPTIMIZEDBASELINE 
// or PROGRESSIVE (in which case you must add jpgSaveOptions.SCANS = (equal 3, 4 or 5)

	var jpgOptns = new JPEGSaveOptions();
	jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
	jpgOptns.embedColorProfile = true;
	jpgOptns.matte = MatteType.NONE;
	jpgOptns = new JPEGSaveOptions;


for(a=0;a<=12;a++){

	jpgSaveFile = new File(initialFolder+"/scriptTemp"+ a+".jpg");
	jpgOptns.quality = a;
	AD.saveAs (jpgSaveFile ,jpgOptns , true, Extension.LOWERCASE);
}

for(a=0;a<=12;a++){
		
	var fileRef = new File(initialFolder + "/scriptTemp"+a+".jpg");
	open (fileRef);
	var openedFile = activeDocument;
	openedFile.selectAll;
	openedFile.layers[0].copy();
	
	activeDocument = AD
	AD.paste()
	openedFile.close(SaveOptions.DONOTSAVECHANGES); 
	AD.layers[0].name = "approx. "+Math.round(fileRef.length/100)/10 +" kb"
	fileRef.remove();
	fileRef = null;
}

AD.layers[AD.layers.length-1].remove();

if(docWidth>docHeight){
	var multipW=1;
	var multipH=13;
}else{
	var multipW=13;
	var multipH=1;
	}

AD.resizeCanvas((docWidth+1)*multipW,(docHeight+1)*multipH,AnchorPosition.TOPLEFT)

	for(a=13;a>=1;a--){
	
		if(multipW==1){
			AD.layers[a-1].translate(0,(13-a)*(docHeight+1))
		}else{
			AD.layers[a-1].translate((13-a)*(docWidth+1),0)
		}		
	}	
	









	   // Close the new document.
	//	   docRef2.close(SaveOptions.DONOTSAVECHANGES); 

  
      

    }else{

     alert("Either you have no document open or you haven't saved your work anywhere prior to the script \nSave your document first !");

    }
    

preferences.rulerUnits = defaultRulerUnits
