
function Connect(jsname) {
  this.jsname = jsname;
  this.editFirst = false;
 
  Connect.prototype.send = function(command,container_id,classname,extra_args,success) {
 
   url = "/connect.response.php";
	 
	 
	 	 
   if (extra_args == null) extra_args = "nil=0";
	 if (this.extra != '') extra_args += "&"+this.extra;
   //ajaxEngine.registerAjaxElement(container_id);
   //alert("ajaxEngine.sendRequest( 'listChange','value=" + newval +"','command=" + command +"','container_id=" + container_id +"'"+extra_args +")");  // 'value' has to be renamed
   ////eval("ajaxEngine.sendRequest( 'listChange','value=" + newval +"','command=" + command +"','container_id=" + container_id +"'"+extra_args +")");  // 'value' has to be renamed
   pars = "command=" + command +"&classname="+classname+"&jsname="+this.jsname+"&container_id=" + container_id +"&"+extra_args; //+Filter.getfilters();  // 'value' has to be renamed
   
													 // need to fill the rest of the items send from ARGS
													 // should look like "order=1" ... might need to be encoded
		
	 //successFunc = "";											 
   //alert(pars);
	 if (!success) success = this.successFunc;
	 rerror = this.reportError;
	 var myAjax = new Ajax.Updater( {success: container_id}, url, {method: 'get', parameters: pars,  onComplete:success, onFailure: rerror, evalScripts: true}); 
											 
 }
 
 Connect.prototype.successFunc = function(){
   //alert("ajax success");
 
 }
 
 Connect.prototype.reportError = function() {
   alert("ajax failed");
 }
 
 Connect.prototype.connect = function(connect_string) {
 
    // if (this.editFirst == false) {
	 	 //this.addfilter(fkey,fvalue);
		 
		 	 //alert(fkey+" "+fvalue);
		 //alert(Liszts.length);
		 //for (l=0;l<Liszts.length;l++) {
		   //alert(Liszts[l].listname + "*");
		 //  Liszts[l].refresh();
		 //}
		 
		 // Get container name for Droppable parent that is a list item
		 
		 // Get the Liszt of that parent so that you can send classname.
		 
		 parts = connect_string.split("|");
		 container = parts[4];
		 listname = null;
		 
		 stuff = "connect_string="+connect_string;
		 //alert(stuff);
		
		 if (parts[3] == -1) {
		   //adding item
		   container_parts = container.split("_");
		   listname=container_parts[0];
		   //alert("listname="+listname+"editfirst="+this.editFirst);
		   if (this.editFirst == false) {
		   		//
		       // the add function is where title and order come from.
		       // this is where the social integrations need to pass info
		       
		       
			   eval("var sform=document.getElementById("+listname+".editformname)");
               
               // var sform = document.getElementById(this.editformname);
               var stuff2 = "";
               //for (i=0;i<sform.elements.length;i++) {
               //  stuff += sform.elements[i].name+"="+escape(sform.elements[i].value)+"&";
               
               //}
               stuff2 = Form.serialize(sform);
			   
			   //eval("newId="+listname+".newId");
               newId = container;
		       alert (newId);
               func=null;
			   
			   stuff =stuff+"&"+stuff2;
			} else {
			   newId = container;
			   
			   func=null;
			}
		    //alert(stuff);
		   this.send("save",newId,"",stuff,func);
		 } else {
		   this.send("connect",container,"",stuff); 
		 }
	 //} else {
	 	//this is all wrong. we need to have the socket do whatever addedit does (calls edit)
	 	// or maybe just not call .add above
	 	 //eval(listname+".addedit()");
	 //}
	 
 }
 
 Connect.prototype.setEditFirst = function(ef) {
   this.editFirst = ef;
   //alert (ef);
 }
 
 
 
}






dots = new Array();
 pointing=false;
 
 function revertpoint (element, top_offset, left_offset) {
 			finaly = $(element.identify()+"|orig").cumulativeOffset()[1];
 			finalx = $(element.identify()+"|orig").cumulativeOffset()[0];
 			//$(element.identify()+"|orig").absolutize();
 			//alert($(element.identify()+"|orig").cumulativeOffset());
 			new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: 1,
	        			queue: {scope:'_draggable', position:'end'}
	      		});
			for (mi=0;mi<dots.length;mi++) {

       			new Effect.Move($(dots[mi].id), { x: finalx , 
												  y: finaly, duration: 1,  mode: 'absolute'
       			});
			}
 }
 
 //  parseInt(Element.getStyle($(element.options.origin),'left')), 
 //  parseInt(Element.getStyle($(element.options.origin),'top'))
 
 function endpoint (element) {
 	var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0;
       	new Effect.Opacity(element, {duration:0, from:0.7, to:toOpacity, 
         		queue: {scope:'_draggable', position:'end'},
         		afterFinish: function(){ 
           		Draggable._dragging[element] = false;
				for (mi=0;mi<dots.length;mi++) {
					  $(dots[mi]).hide();
				} 
				pointing=false;
         		}
       	}); 
 }

 function pointer(d) {
   var pos = Position.cumulativeOffset(d.element);
   if (pointing == false) {
     oldx = pos[0]; //d.originalX;
     oldy = pos[1]; //d.originalY;
  	 pointing=true;
	 }
   newx = pos[0];//d.currentLeft();
   newy = pos[1];//d.currentTop();
   
   spacing = 10;
   
   distance = Math.sqrt(Math.abs((newx-oldx)^2)+Math.abs((newy-oldy)^2));
   
   slope = (newy-oldy)/(newx-oldx);
   
   b = oldy - slope*oldx;
	 
	 xdistance = newx-oldx;
	 
	 count = Math.floor(xdistance/spacing);
	 
	 
	 
	
	 first_dot = $('dot');
	 //field = $('field');
	 //$('countbox').innerHTML = count+"|x:"+oldx+"|"+newx+"|y:"+oldy+"|"+newy
	 
	 //hide dots
	 for (i=count;i<dots.length;i++) {
	  $(dots[i]).hide();
	 }
	 
	 
	 //create all dots
	 for (i=0;i<count;i++) {
	    if (!dots[i]) {
  			new_dot = first_dot.cloneNode(true);
  			new_dot.id = "dot"+i;
				//$('x2box').innerHTML = new_dot;
  			first_dot.parentNode.insertBefore(new_dot,first_dot);
  	    dots[i] = $(new_dot.id);
	    }
			else {
        $(dots[i]).show();			
			
			}
	 
	 }
	 
	 // move dots
	 for (i=0;i<count;i++) {
	   dotx = oldx + i*xdistance/count;
		 doty = lineeq(slope,b,dotx);
		 dots[i].style.left = dotx+"px";
		 dots[i].style.top = doty+"px";
		 
		 //if (i=1) {
		   //$('x2box').innerHTML = dotx;
			 //$('y2box').innerHTML = doty;
		 
		 //}
	 
	 
	 }
	 /*
	 if(dots[1]) {
	 $('x2box').innerHTML = dots[1].style.left;
	 $('y2box').innerHTML = dots[1].style.top;
	 }
	 if(dots[2]) {
	 $('x3box').innerHTML = dots[2].style.left;
	 $('y3box').innerHTML = dots[2].style.top;
	 }
	 */
 
 }
 
 function lineeq(slope,b,x) {
   return slope*x+b;
 }
