//\/////
//\ overlibmws_draggable.js - August 21, 2003 - Plug-in for overlibmws.js support of the
//\ DRAGGABLE feature. The Change History and Command Reference for overlibmws.js can
//\ be accessed via:
//\
//\	http://www.macridesweb.com/oltest/	-- Foteos Macrides
//\
//\/////
//\ Copyright and license agreement for the standard overLIB apply.  Access license via
//\ the overLIB homepage: http://www.bosrup.com/web/overlib/
//\/////

// PRE-INIT
OLloaded=0;
registerCommands('draggable');

/////////
// DEFAULT CONFIGURATION
if(typeof ol_draggable=='undefined')var ol_draggable=0;
// END CONFIGURATION
/////////

// INIT
var o3_draggable=0;
var o3_dragging=0;

// For setting runtime variables to default values.
function setDraggableVar(){
o3_draggable=ol_draggable;
}

// For commandline parser.
function parseDraggableExtras(pf,i,ar){
var k=i;
if(k<ar.length){
if(ar[i]==DRAGGABLE){eval(pf+'draggable=('+pf+'draggable==0)?1:0');return k;}
}
return -1;
}

/////////
// DRAGGABLE SUPPORT FUNCTIONS
/////////
function initDrag(){
oMMv=capExtent.onmousemove;
if(OLns4){
document.captureEvents(Event.MOUSEDOWN|Event.CLICK);
document.onmousedown=grabEl;
document.onclick=function(e){return routeEvent(e);}
}else{
over.onmousedown=grabEl;
if(OLie4&&over.onselectstart!='undefined')over.onselectstart=function(){return false;}
over.style.cursor="move";
}
o3_dragging=1;
return true;
}

function grabEl(e){
var e=(e)?e:event;
var cKy=(OLns4?e.modifiers&Event.ALT_MASK:(!OLop7)?e.altKey:e.ctrlKey);
if(cKy){
if(OLie4&&over.onselectstart!='undefined')over.onselectstart=null;
if(!OLns4)over.style.cursor="auto";
document.onmouseup=function(){
if(!OLns4){
if(OLie4&&over.onselectstart!='undefined') over.onselectstart=function(){return false;}
if(!OLns4)over.style.cursor="move";
}
}
return(OLns4?routeEvent(e):true);
}
oMMv(e);
if(OLns4){
cX=e.pageX;
cY=e.pageY;
}else{
cX=o3_x-(parseInt(over.style.left));
cY=o3_y-(parseInt(over.style.top));
if((OLshadowPI)&&bkdrop&&o3_shadow){
cbX=o3_x-(parseInt(bkdrop.style.left));
cbY=o3_y-(parseInt(bkdrop.style.top));
}
}
if(OLns4)document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
capExtent.onmousemove=moveEl;
document.onmouseup=function(){capExtent.onmousemove=oMMv;document.onmouseup=null;}
return (OLns4?routeEvent(e):false);
}

function moveEl(e){
oMMv(e);
if(OLns4){
newX=e.pageX;newY=e.pageY;
over.moveBy(newX-cX,newY-cY);
if((OLshadowPI)&&bkdrop&&o3_shadow)bkdrop.moveBy(newX-cX,newY-cY);
cX=newX;cY=newY;
}else{
repositionTo(over,o3_x-cX,o3_y-cY);
if((OLshadowPI)&&bkdrop&&o3_shadow)repositionTo(bkdrop,o3_x-cbX,o3_y-cbY);
}
return false;
}

function clearDrag(){
if(OLns4){
document.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP|Event.CLICK);
document.onmousedown=document.onmouseup=document.onclick=null;
}else if(OLie4||OLns6){
over.onmousedown=null;
if(OLie4&&over.onselectstart!='undefined')over.onselectstart=null;
over.style.cursor="auto";
}
o3_dragging=0;
}

////////
// PLUGIN REGISTRATIONS
////////
registerRunTimeFunction(setDraggableVar);
registerCmdLineFunction(parseDraggableExtras);

OLdraggablePI=1;
OLloaded=1;
