﻿var DragManager = new Object();

DragManager.DragableObject = function(objToMoveId, moveHandleId, coverObjId)
{
    this.objToMove = document.getElementById(objToMoveId);
    
    if(this.objToMove)
    {
        this.objToMove.browserType = (document.all)?("ie"):("ns");
        this.objToMove.offsetX;
        this.objToMove.offsetY;
        this.objToMove.isDragable = false;
        
        this.objToMove.coverObj = document.getElementById(coverObjId);
        
        this.moveHandle = document.getElementById(moveHandleId);
        
        this.objToMove.dragStart = function(e)
        {   
            var o = (this.parentObject == null)?(this):(this.parentObject);
                    
            document.objToMove = o;
                  
            o.style.opacity = "0.9";
            o.style.filter = "Alpha(Opacity=90)";
            o.offsetX = o.getMouseX(e) - parseInt(o.style.left);
            o.offsetY = o.getMouseY(e) - parseInt(o.style.top); 
            o.isDragable = true;
            
            if(o.coverObj)
                o.coverObj.style.display = "block";
                        
            o.disableHighlighting();
            
            document.onmousemove = o.dragAndDrop;   
            document.onmouseup = o.dragStop;                                  
        }
        
        this.objToMove.dragAndDrop = function(e)
        {                
            if(this.objToMove.browserType == "ns" && this.objToMove.isDragable)
            {              
                this.objToMove.style.left = e.clientX - this.objToMove.offsetX + "px";
                this.objToMove.style.top = e.clientY - this.objToMove.offsetY + "px";              
            }
            else if(this.objToMove.isDragable)
            {
                this.objToMove.style.left = event.clientX - this.objToMove.offsetX + "px";
                this.objToMove.style.top = event.clientY - this.objToMove.offsetY + "px";                            
            }       
        }
                
        this.objToMove.dragStop = function(e)
        {
            this.objToMove.style.opacity = "1.0";
            this.objToMove.style.filter = "Alpha(Opacity=100)";
            
            if(this.objToMove.coverObj)
                this.objToMove.coverObj.style.display = "none";
                
            this.objToMove.isDragable = false; 
            
            this.objToMove.enableHighlighting();                
        }
        
        this.objToMove.disableHighlighting = function()
        {
       
            document.onselectstart = function(){return false;}
            
            if(window.sidebar)
            {
                document.onmousedown = false;
                document.onclick = true;
            } 
                   
        }
        
        this.objToMove.enableHighlighting = function()
        {
        
            document.onselectstart = function(){return true;}
            if(window.sidebar)
            {
                document.onmousedown = true;
                document.onclick = true;
            } 
               
        }
                
        this.objToMove.getMouseX = function(e)
        {
             if(this.browserType == "ns")
                return e.clientX;
            else
                return event.clientX;
        }
                
        this.objToMove.getMouseY = function(e)
        {
             if(this.browserType == "ns")
                return e.clientY;
            else
                return event.clientY;
        }
        
        // Mouse Click Event Attachment
        if(this.moveHandle)
        {
            this.moveHandle.parentObject = this.objToMove;
            this.moveHandle.onmousedown = this.objToMove.dragStart;
        }
        else
        {
            this.objToMove.onmousedown = this.objToMove.dragStart;
        }
    }
}


