// since we have multiple uses for trapping onmouseXXX events for different elements,
// we can either test the target and dispatch the event to control-specific handlers, or
// we can simply save, set, and re-set the onmouseXXX handlers on an as-needed basis.
// for example, rater.js kicks in first; if we need to pop up the select photo dialog,
// save the onmouseXXX handlers, assign new ones, and then reset when the dialog is closed.
		img = document.getElementById("selectphotogrip");
		var anchorx;
		var anchory;
		var sizing = false;

		function mouseX(ev)
		{
			if (ev.pageX)
				return ev.pageX;
			else
				return ev.clientX + document.body.scrollLeft - document.body.clientLeft;
		}

		function mouseY(ev)
		{
			if (ev.pageY)
				return ev.pageY;
			else
				return ev.clientY + document.body.scrollTop - document.body.clientTop;
		}

		//img.onmousedown = function(ev)
		selectaphoto_onmousedown = function(ev)
		{
			if ( !ev ) var ev = window.event;
	            sizing = true;
    		    anchorx = mouseX(ev); //ev.clientX;
            	anchory = mouseY(ev); //ev.clientY;
            	//global_set_cursor_style("move");
            	return false;

			/*ev.returnValue = false;
			ev.cancelBubble = true;
			if ( ev.stopPropagation ) ev.stopPropagation();
            */

			if (ev.target)
			  {
			  targ=ev.target;
			  }
			else if (ev.srcElement)
			  {
			  targ=ev.srcElement;
			  }
			if (targ.nodeType==3) // defeat Safari bug
			  {
			  targ = targ.parentNode;
			  }


			if ( targ.id == "selectphotogrip" )
			{
	            sizing = true;
    		    anchorx = mouseX(ev); //ev.clientX;
            	anchory = mouseY(ev); //ev.clientY;
          	}

			return false;
		}

		//img.onmouseup = function(ev)
		selectaphoto_onmouseup = function(ev)
		{
			if ( img.style.cursor != "default" )
				img.style.cursor = "default";

			if ( !ev ) var ev = window.event;
            sizing = false;
			return false;
		}

		//img.onmousemove = function(ev)
		selectaphoto_onmousemove = function(ev)
		{
			if ( !ev ) var ev = window.event;

			if ( sizing )
			{
				if ( img.style.cursor != "move" )
					img.style.cursor = "move";

				dialogobj = document.getElementById("selectphotodialog" );
				dialogleft = getabsleft( "selectphotodialog");
				dialogtop = getabstop( "selectphotodialog");

				curx = mouseX(ev);
				cury = mouseY(ev);

				dialogwidth = curx - dialogleft + 6;	// +6 to offset the mouse pointer into the center of the grip
				dialogheight = cury - dialogtop + 6;

				if ( dialogwidth < 320 ) dialogwidth = 320;
				if ( dialogheight < 200 ) dialogheight = 200;

				dialogobj.style.width = dialogwidth + "px";
				dialogobj.style.height = dialogheight + "px";

				photoholderobj = document.getElementById("selectphotoholder" );
				photoholderobj.style.width = (dialogwidth-8) + "px";
				photoholderobj.style.height = (dialogheight-80) + "px";

			}
			return false;
		}



		function clickthumbcallback( pfn )
		{
			//alert( pfn );
			sendchatmsg( send_photo_to_target, '', "INLINEPHOTO:" + pfn + ":");
			overlay_click();
			/*e = document.getElementById("selectedthumbs");
			if ( !e )
				alert( "oops" );
			str = "<img src=\"/photos/" + pfn + "\" height=\"48\">&nbsp;";
			//alert( str );
			if ( push_attachment(pfn) )
			{
				e.innerHTML += str;
			}*/

		}


		function onmemberclick()
		{
		}

