Index: src/hg/js/hgTracks.js
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/js/hgTracks.js,v
retrieving revision 1.64
retrieving revision 1.65
diff -b -B -U 4 -r1.64 -r1.65
--- src/hg/js/hgTracks.js	8 Apr 2010 22:31:13 -0000	1.64
+++ src/hg/js/hgTracks.js	9 Apr 2010 07:48:47 -0000	1.65
@@ -134,8 +134,44 @@
     return (selection.event.pageX >= leftX) && (selection.event.pageX < rightX)
         && (selection.event.pageY >= (imgOfs.top - slop)) && (selection.event.pageY < (imgOfs.top + imgHeight + slop));
 }
 
+
+function selectionPixelsToBases(img, selection)
+// Convert selection x1/x2 coordinates to chromStart/chromEnd.
+{
+var insideX = parseInt(document.getElementById("hgt.insideX").value);
+var imgWidth = jQuery(img).width() - insideX;
+var winStart = parseInt(document.getElementById("hgt.winStart").value);
+var winEnd = parseInt(document.getElementById("hgt.winEnd").value);
+var width = winEnd - winStart;
+var mult = width / imgWidth;   // mult is bp/pixel multiplier
+var startDelta;                // startDelta is how many bp's to the right/left
+if(revCmplDisp) {
+    var x1 = Math.min(imgWidth, selection.x1);
+    startDelta = Math.floor(mult * (imgWidth - x1));
+} else {
+    var x1 = Math.max(insideX, selection.x1);
+    startDelta = Math.floor(mult * (x1 - insideX));
+}
+var endDelta;
+if(revCmplDisp) {
+    endDelta = startDelta;
+    var x2 = Math.min(imgWidth, selection.x2);
+    startDelta = Math.floor(mult * (imgWidth - x2));
+} else {
+    var x2 = Math.max(insideX, selection.x2);
+    endDelta = Math.floor(mult * (x2 - insideX));
+}
+var newStart = winStart + startDelta;
+var newEnd = winStart + 1 + endDelta;
+if(newEnd > winEnd) {
+    ewEnd = winEnd;
+}
+return {chromStart : newStart, chromEnd : newEnd};
+}
+
+
 function updatePosition(img, selection, singleClick)
 {
     // singleClick is true when the mouse hasn't moved (or has only moved a small amount).
     var chromName = document.getElementById("hgt.chromName").value;
@@ -321,9 +357,16 @@
 }
 
 function makeItemsEnd(img, selection)
 {
-alert("dragged out x1=" + selection.x1 + " x2=" + selection.x2);
+var image = $(img);
+var imageId = image.attr('id');
+var trackName = imageId.substring('img_data_'.length);
+var chrom = document.getElementById("hgt.chromName").value;
+var pos = selectionPixelsToBases(image, selection);
+var command = document.getElementById('hgt_doJsCommand');
+command.value = "makeItems " + trackName + " " + chrom + " " + pos.chromStart + " " + pos.chromEnd;
+document.TrackHeaderForm.submit();
 return true;
 }
 
 function setUpMakeItemsDrag(trackName)

