Index: /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate-main.js
===================================================================
--- /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate-main.js	(revision 30456)
+++ /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate-main.js	(revision 30456)
@@ -0,0 +1,275 @@
+
+var mouseX = 0;
+var mouseY = 0;
+
+function trackMouse(e)
+{
+
+    //0,0 point is the top left corner of the container,
+    //minus its padding:
+    var containerX = YAHOO.util.Dom.getX("thispage");
+    var containerY = YAHOO.util.Dom.getY("thispage");
+    var clickX = YAHOO.util.Event.getPageX(e);
+    var clickY = YAHOO.util.Event.getPageY(e);
+
+    mouseX = clickX;
+    mouseY = clickY;
+
+    var coord_div  = getElement("coord");
+    coord_div.innerHTML = mouseX + ", " + mouseY;
+
+
+     //get container padding using Dom's getStyle():
+    var containerPaddingX = parseInt(YAHOO.util.Dom.getStyle("thispage","padding-left"), 10);
+    var containerPaddingY = parseInt(YAHOO.util.Dom.getStyle("thispage","padding-top"), 10);
+    var newWidth = clickX - containerX - containerPaddingX;
+    var newHeight = clickY - containerY - containerPaddingY;
+
+
+   if (annotateMoveElem != null) {
+       annotateMoveElem.style.left = (mouseX - moveXOffset) + "px";
+       annotateMoveElem.style.top  = (mouseY - moveYOffset) + "px";
+   }
+
+
+   if (annotateResizeElem != null) {
+       var ax_org = parseInt(annotateResizeElem.style.left);
+       var ay_org = parseInt(annotateResizeElem.style.top);
+       var ax_dim = mouseX - ax_org +1;
+       var ay_dim = mouseY - ay_org +1;
+
+       if ((ax_dim>16) && (ay_dim>16)) {
+           annotateResizeElem.style.width  = ax_dim + "px";
+           annotateResizeElem.style.height = ay_dim + "px";
+       }
+   }
+
+
+}
+
+
+function closeAnnotation(elem,evt)
+{
+    // 'elem' not currently used, but passed in to be similar to other event handlers
+    // 'elem' could be used to simplify working 'closeElem' ??
+    
+    evt = evt || window.event;
+
+    var mousePos = getMouseCoords(evt);
+
+    var closeElem = de.cursor.getNonCursorNodeAtXY(mousePos.x, mousePos.y);
+
+    var currElem = closeElem.parentNode;
+    var prevElem = closeElem;
+
+    while (currElem!=null) {
+        prevElem = currElem;
+        currElem = currElem.parentNode;
+
+        if (prevElem.getAttribute("class") == "annotationNote") {
+	    break;
+	}
+    }
+        
+    var annotateCanvas = currElem;
+    var annotateDiv   = prevElem;
+
+    var editableElems = getElementsByClass("editable-",annotateDiv);
+    var editableElem = editableElems[0];
+
+    var removeMetapos = editableElem.getAttribute("metapos");
+    console.log("closeAnnotation: metapos = " + removeMetapos);
+
+    annotate.removeAnnotation(annotateCanvas,removeMetapos);
+
+    return false;
+}
+
+
+var annotateResize = false;
+var annotateResizeElem = null;
+
+function startResizeAnnotation(elem,event)
+{
+    event = event || window.event;
+
+    var rightclick = false;
+    if (event.which) rightclick = (event.which == 3);
+    else if (event.button) rightclick = (event.button == 2);
+    // stop things early (allow for right-click to close annotation, on mouseup)
+    if (rightclick) return false; 
+
+    annotateResize = true;
+    annotateResizeElem = elem.parentNode.parentNode.parentNode.parentNode;
+
+    console.log("*** clearing selection and setting cursor to null!");
+    de.selection.clear(); // clear selection
+    de.cursor.setCursor(null); // clear focus
+
+    return false; // stop drag and drop of image
+}
+
+function stopResizeAnnotation(elem,event)
+{
+    event = event || window.event;
+
+    var rightclick = false;
+    if (event.which) rightclick = (event.which == 3);
+    else if (event.button) rightclick = (event.button == 2);
+    // stop things early (allow for right-click to close annotation, on mouseup)
+    if (rightclick) return closeAnnotation(elem,event);
+
+    annotateResize = false;
+    annotateResizeElem = null;
+
+    return true;
+
+}
+
+
+var annotateMove = false;
+var annotateMoveElem = null;
+
+var moveXOffset = 0;
+var moveYOffset = 0;
+
+function annotateMouseDown(elem,event)
+{
+    event = event || window.event;
+
+    annotateMove = true;
+    annotateMoveElem = elem.parentNode.parentNode.parentNode;
+
+    moveXOffset = mouseX - parseInt(annotateMoveElem.style.left);
+    moveYOffset = mouseY - parseInt(annotateMoveElem.style.top);
+
+    return false; // stop selection of page Image
+}
+
+function annotateMouseUp(elem,event)
+{
+      event = event || window.event;
+
+      annotateMove = false;
+      annotateMoveElem = null;
+
+      return true;
+}
+
+
+function setCursorAtXY(x,y)
+{
+    // Filter out non editable node first... so that can
+    // quickely avoid searching
+    var cInfo;
+    var targetEl = de.getElementAtXY(x, y);
+
+    if (targetEl) {
+        if (de.doc.isNodeEditable(targetEl)) {
+            //cInfo = de.cursor.getCursorInfoAtXY(x, y, targetEl);
+	    cInfo = de.cursor.getCursorDescAtXY(x,y,targetEl);
+	}
+    }
+
+    de.cursor.setCursor(cInfo);
+}
+
+function annotateLoseFocus(elem)
+{
+    //de.cursor.setCursorAtXY(mouseX,mouseY);
+    setCursorAtXY(mouseX,mouseY);
+}
+
+
+function annotateGainFocus(elem)
+{
+    //de.cursor.setCursorAtXY(mouseX,mouseY);
+    setCursorAtXY(mouseX,mouseY);
+}
+
+
+var annotate_width = 0;
+var max_annotate_width = 9;
+var annotate_height = 1;
+
+
+
+
+function keyPress(e)
+{
+    if (e.keyID == "Escape") { 
+       musicStand.cancelPageAnim();
+    }
+
+    //var cursorInfo = de.cursor.getCurrentCursorInfo();
+    var cursorInfo = de.cursor.getCurrentCursorDesc();
+
+    var newAnnotation = false;
+
+    if (cursorInfo==null) {
+        newAnnotation = true;
+    }
+    else if (expeditee) {
+        var overTextElem = de.cursor.getNonCursorNodeAtXY(mouseX,mouseY);
+        var overElem = de.doc.getEditableRootNode(overTextElem);
+
+        if (overElem==null) {
+	    // mouse in white space, but missed an onmouseout event
+            de.cursor.setCursor(null);
+
+	    newAnnotation = true;
+        }
+	else {
+	    var editableElem = de.doc.getEditableRootNode(cursorInfo.textNode);
+
+	    if (editableElem.getAttribute("id") != overElem.getAttribute("id")) {
+ 	        // cursor is over another editable element (but must have
+	        // missed onmouseover event)
+	        // => need to switch cursor location
+                var startCursor = de.cursor.createCursor(overElem.firstChild,0,false);
+                de.cursor.setCursor(startCursor);
+	    }
+	}
+
+    }
+
+    if (newAnnotation) {
+      // control/shift being down marks beginning key accelerators such 
+      // as ctrl-r or similar
+      // => ignore here, but let it bubble up further
+
+	var isAccelDown = de.events.Keyboard.isAcceleratorDown(e);
+	var isShiftDown = e.shiftKey;
+	console.log("**** is accel down: " + isAccelDown);
+	console.log("**** is shift down: " + isShiftDown);
+	//if (e.isAccelDown() || e.isShiftDown()) { return true; }
+	if (isAccelDown || isShiftDown) { return true; }
+
+      if (e.keyID == "Escape") { 
+          // deactivate cursor !!!???????
+          de.cursor.setCursor(null);
+          return true; 
+      }
+
+      console.log("*** mouse: ("+mouseX+","+mouseY+")");
+	
+      var newAI = annotate.createAnnotation(mouseX-8,mouseY-14,null,"20","&nbsp;");
+
+      var annotateCanvasElem = document.getElementById("annotateCanvas");
+      annotateCanvasElem.appendChild(newAI);
+
+      var editableElems = getElementsByClass("editable-",newAI);
+      var editableElem = editableElems[0];
+
+      //var startCursor = de.cursor.createCursor(editableElem.firstChild,0,false);
+      var startCursor = de.cursor.createCursorDesc(editableElem.firstChild,0,false);
+      de.cursor.setCursor(startCursor);
+
+    }
+     
+
+}
+
+
+
+
Index: /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate.js
===================================================================
--- /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate.js	(revision 30455)
+++ /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate.js	(revision 30456)
@@ -92,4 +92,6 @@
       editableElem.setAttribute("metapos",numAnnotations);
 
+      //editableElem.setAttribute("style", "cursor:text;");
+      
       editableElem.style.position     = "relative";
 
@@ -101,8 +103,11 @@
       tdTextElem.setAttribute("onmousedown","javascript:return annotateMouseDown(this,event);");
       tdTextElem.setAttribute("onmouseup",  "javascript:return annotateMouseUp(this,event);");
-
+      tdTextElem.setAttribute("style", "cursor:text;");
+      
       var closeElem = document.createElement("div");
-      closeElem.onmouseup=closeAnnotation;
-
+      //closeElem.onmouseup=closeAnnotation;
+      closeElem.setAttribute("onmouseup","javascript:return closeAnnotation(this,event);");
+      closeElem.setAttribute("style", "cursor:default;");
+      
       closeElem.style.position = "absolute";
       closeElem.style.top      = "0px";
@@ -115,4 +120,6 @@
       resizeElem.setAttribute("onmouseup",  "javascript:return stopResizeAnnotation(this,event);");
 
+      resizeElem.setAttribute("style", "cursor:default;");
+      
       resizeElem.style.position = "absolute";
       resizeElem.style.bottom   = "0px";
Index: /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/musicstand-main.js
===================================================================
--- /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/musicstand-main.js	(revision 30455)
+++ /main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/musicstand-main.js	(revision 30456)
@@ -6,4 +6,12 @@
 else {
     cgiGotoPage = 1;
+}
+
+var expeditee; 
+if (gs.cgiParams["expeditee"]) {
+    expeditee = true;
+}
+else {
+    expeditee = false;
 }
 
@@ -15,9 +23,26 @@
 		     gs.cgiParams["scaleFactor"]);
 
-musicStand.setStyleColors("_postitbgcol_","_postitselcol_");
+musicStand.setStyleColors(gs.variables["postitBgCol"],gs.variables["postitSelCol"]);
 
 musicStand.setPagePrefix(gs.cgiParams["pagePrefix"]);
 musicStand.setPageSuffix(gs.cgiParams["pageSuffix"]);
 
+var annotate = new Annotate(gs.variables.httpCollectionImages);
+
+if (gs.userInformation && gs.userInformation.username) {
+  musicStand.setUsername(gs.username);
+  annotate.setUsername(gs.username);
+}
+
+//  de.events.addLoadHandler(function()
+
+$(window).load(function(){
+      try {
+	  bodyLoaded();                       
+      } 
+      catch(err) {
+	  alert("Failed to initialise: " + err.message);
+      }
+});
 
 
@@ -120,14 +145,17 @@
   var thispage = document.getElementById("thispage");
 
-  ////YAHOO.util.Event.addListener("thispage", 'mouseover', trackMouse);
-  //// YAHOO.util.Event.addListener(document, 'mousemove', trackMouse);
-
-  //de.events.addMouseMoveHandler(trackMouse);
-
-  //// de.events.prependMouseUpHandler(musicStand.pageMenu);
-
-  ////YAHOO.util.Event.addListener(document, 'keydown', keyPress);
-
-  //de.events.prependKeyPressHandler(keyPress);
+  //YAHOO.util.Event.addListener("thispage", 'mouseover', trackMouse);
+  // YAHOO.util.Event.addListener(document, 'mousemove', trackMouse);
+
+    //de.events.addMouseMoveHandler(trackMouse);
+    de.events.addHandler(document,"mousemove",trackMouse);
+
+  // de.events.prependMouseUpHandler(musicStand.pageMenu);
+
+  //YAHOO.util.Event.addListener(document, 'keydown', keyPress);
+
+    //de.events.prependKeyPressHandler(keyPress);
+    //de.events.addHandler(document,"keypress",keyPress);
+    de.events.addHandler(document,"keystroke",keyPress);
 }
 
