/*
* Déclaration de l'objet DragNDropManager
permettant le glisser déplacer dans une page
* @author abe 19/04/06
*/

function DragNDropManager(ext)
{
   this.isDragging = false;
   this.objectToDrag;
   this.obj;
   this.ecartX;
   this.ecartY;
   this.curX;
   this.curY;
   /*
    * 
    * voir avec TD pour stockage qui plante
    * 
    * 
   	*/
   this.cacheElementToDrag=new Array();
   return this;
}
/*
* Initilaisation des valeurs x,y,className
*/
DragNDropManager.prototype.positionne = function (p_id, p_posX, p_posY,className)
{  
   if(document.getElementById(p_id).innerHTML=="") document.getElementById(p_id).style.display="none";
   this.changeStyle(document.getElementById(p_id),className);
	document.getElementById(p_id).style.left = this.getElementToDrag(p_id,p_posX,"X");
	document.getElementById(p_id).style.top =this.getElementToDrag(p_id,p_posY, "Y");

}

/*
* récupère en caches session la valeur du paramètre param pour un type (x ou y)
*/
DragNDropManager.prototype.getElementToDrag = function (p_id, param,Type)
{
   var ret;
   if(this.cacheElementToDrag[p_id])
   {
   var m_cache=this.cacheElementToDrag[p_id];
      if(m_cache[Type])   
         {
         ret=m_cache[Type];
         return ret;  
         }
      else
         {
          this.setElementToDrag(p_id, param,Type);
         return param;
         }
   }
   else
   {
      this.setElementToDrag(p_id, param,Type);
      return param;
   }
}

/*
* place en session l'élément param pour un Type donné (x ou y)
*/
DragNDropManager.prototype.setElementToDrag = function (p_id, param,Type)
{

   if(!this.cacheElementToDrag[p_id])
   {
      var m_cache=new Array();
      m_cache[Type]=param;
      this.cacheElementToDrag[p_id]=m_cache;
   }
   else this.cacheElementToDrag[p_id][Type]=param;
   sysSetAttribute("cacheElementToDrag", this.cacheElementToDrag);
}

/*
* postion courante du curseur avec sysMouse
*/
DragNDropManager.prototype.getPositionCurseur = function (e)
{
		this.curX = sysMouseX;
		this.curY = sysMouseY;
}

/*
* commence le déplacer intialise X et Y
*/
DragNDropManager.prototype.beginDrag= function (p_obj,e,className)
{
	this.isDragging = true;
	objectToDrag = p_obj;
	this.getPositionCurseur(e);
	this.ecartX = this.curX - parseInt(objectToDrag.style.left);
	this.ecartY = this.curY - parseInt(objectToDrag.style.top);
   this.changeStyle(p_obj,className);
}

/*
* pendant le déplacement : intialise X et Y
*/
DragNDropManager.prototype.drag= function (e)
{
	var newPosX;
	var newPosY;
	if(this.isDragging == true){
		
		this.getPositionCurseur(e);
		newPosX = this.curX - this.ecartX;
		newPosY = this.curY - this.ecartY;

		objectToDrag.style.left = newPosX + 'px';
		objectToDrag.style.top = newPosY + 'px';
		
	}
}
/*
* fin du déplacement , initalise X etg Y en session
*/
DragNDropManager.prototype.endDrag= function (p_obj,className)
{
	this.isDragging = false;
   this.changeStyle(p_obj,className);
   this.setElementToDrag(p_obj.id,p_obj.style.left,"X");
	this.setElementToDrag(p_obj.id,p_obj.style.top, "Y");
   this.setElementToDrag(p_obj.id,p_obj.style.display, "display");
}

/*
* changement de style 
*/
DragNDropManager.prototype.changeStyle= function (p_obj,className)
{
   if (document.all) 
   {
      p_obj.setAttribute("className",className);
   }
   else
   {
      p_obj.setAttribute("class",className);
   }
}




SliderManager.prototype = new DragNDropManager() ;

function SliderManager() {
   this.parent = DragNDropManager;
   this.isDragging = false;
   this.objectToDrag;
   this.obj;
   this.ecartX;
   this.ecartY;
   this.curX;
   this.curY;
      this.leftBorn;
   this.rightBorn;
 /*  if(sysGetAttribute("cacheElementToDrag")) this.cacheElementToDrag=sysGetAttribute("cacheElementToDrag");
   else this.cacheElementToDrag=new Array();*/
   return this;
}

/*
* Initilaisation des valeurs x,y,className
*/
SliderManager.prototype.positionne = function (p_id, p_posX, p_posY,className, LeftBorn, RightBorn)
{  
   this.changeStyle(document.getElementById(p_id),className);
   document.getElementById(p_id).style.marginLeft =p_posX;
   this.leftBorn=LeftBorn;
   this.rightBorn=RightBorn;
}

SliderManager.prototype.beginDrag= function (p_obj,e,className)
{
	this.isDragging = true;
	objectToDrag = p_obj;
	this.getPositionCurseur(e);   
	this.ecartX = this.curX - parseInt(objectToDrag.style.marginLeft);
	//this.ecartY = this.curY - parseInt(objectToDrag.style.top);
   this.changeStyle(p_obj,className);
}

/*
* pendant le déplacement : intialise X et Y
*/
SliderManager.prototype.drag= function (e)
{
	var newPosX;
	var newPosY;
	if(this.isDragging == true){
		this.getPositionCurseur(e);
		newPosX = this.curX - this.ecartX;
     if(newPosX<=this.rightBorn && newPosX>this.leftBorn) objectToDrag.style.marginLeft = newPosX+ 'px';
		
	}
}

