﻿

function lionskyDockingManager(doc, editor)
{
    this.Document = doc;    
    this.EnableDockingState = false;
    this.Editor = editor;
    this.DragHelperElem = null;
    this.DragHelperTooltip = null;
    this.DragHelperTooltipElem=null; 
    this.DockingZones=new Array(); 
	this.DockableObjects=new Array();
    this.InitializeDragHelper();
}
lionskyDockingManager.prototype.InitializeDragHelper = function()
{
	var div = getElementById(this.Editor.Id + "_DragHelper");
	if(div)
	{
	    if (this.Document.all)
	    {
		    div.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=25)"; 
	    }
	    else 
	    {
		    div.style.setProperty("-moz-opacity","0.25",""); 
	    }
	    this.AttachDockDragProperty(div, false , false , true);  
        this.DragHelperElem = div;    
    }
    var oDiv=getElementById(this.Editor.Id + "_DragHelperTooltip");
    if(oDiv)
    {
	    this.AttachPrototype(oDiv,new lionskyDragHelperTooltipEventHandler(this)); 	
	    this.DragHelperTooltip = oDiv;
	}
}
lionskyDockingManager.prototype.GetDragHelperTooltipObject= function (mouseDownDockableObject)
{
	var dragHelperTooltipElem=mouseDownDockableObject.Controller.DragHelperTooltip; 
	if (!dragHelperTooltipElem)
	{
	    return null; 
	}
	dragHelperTooltipElem.SetzIndex(); 
	return dragHelperTooltipElem; 
} ; 

lionskyDockingManager.prototype.SetParentDockingZone = function(dockableObject)
{	
	if (dockableObject.ParentDockingZone)
	{
	    return; 
	}
	var dockingZone; 
	var dockingzoneAttribute=dockableObject.getAttribute("dockingzone"); 
	if (dockingzoneAttribute)
	{
		dockingZone=getElementById(dockingzoneAttribute); 
	}
	else if (dockableObject.parentNode.getAttribute("DockingMode"))
	{
		dockingZone=dockableObject.parentNode; 
	}
	if (dockingZone&&typeof(dockingZone.InsertBefore) == "function")
	{
		var dockingOrderAttribute=parseInt(dockableObject.getAttribute("dockingorder")); 
		if (isNaN(dockingOrderAttribute))
		{
			dockingOrderAttribute=null; 
		}
		dockingZone.InsertBefore(dockableObject,dockingOrderAttribute); 
	}
	else if (dockableObject.parentNode != document.body)
	{
		if ("complete" == document.readyState)
		{
			dockableObject.parentNode.removeChild(dockableObject); 
			document.body.appendChild(dockableObject); 
		}
		if (dockableObject.InsertBeforeSimulateLayer)
		{
			dockableObject.InsertBeforeSimulateLayer(); 
		}
	}
}
lionskyDockingManager.prototype.ShowDragHelperTooltip= function (e, rect, showFlag)
{
	var dragHelperTooltipElem = this.DragHelperTooltipElem; 
	if (dragHelperTooltipElem)
	{
		if (showFlag)
		{
			dragHelperTooltipElem.SetDragHelperTooltipValue("("+rect.left+","+rect.top+")"); 
		}
		else 
		{
			dragHelperTooltipElem.SetDragHelperTooltipValue("("+rect["width"]+" x "+rect["height"]+")"); 
		}
		var x=e.clientX+5+GetScrollLeft(document); 
		var y=e.clientY+5+GetScrollTop(document); 
		dragHelperTooltipElem.Show(x,y); 
	}
} ; 

lionskyDockingManager.prototype.EnableDocking = function(imageSrc)
{
    if (imageSrc)
	{
		var img=GetImage(); 
		if (img)
		{
			img.src=imageSrc; 
		}
	}
	if (this.EnableDockingState)
	{
	    return; 
	}
	IanFEvent.observe(document,"mousemove",this.OnMouseOverDockingZoneEvent);  
	this.EnableDockingState= true;
}
lionskyDockingManager.prototype.RegisterDockingZone = function(dockableZone,dockingMode)
{
    if (!dockableZone)
    {
        return; 
    } 
	if (!dockingMode)
	{
		dockingMode=dockableZone.getAttribute("DockingMode"); 
	}
	this.AttachPrototype(dockableZone,new lionskyDockingZoneEventHandler(this)); 
	dockableZone.DockingMode=(dockingMode?dockingMode: "Horizontal");
	this.DockingZones.push(dockableZone); 
}
lionskyDockingManager.prototype.AttachPrototype= function (object,baseObject)
{
	for (var index in baseObject)
	{
		object[index]=baseObject[index]; 
	}
} ; 
lionskyDockingManager.prototype.RegisterDockableObject = function(dockableObject,allowShowDragHelper,attachDragHelperProperty,attachDragResizeProperty, effectsUpdateRate, effectsDuration, effectsEnable,allowMove,dockableMode)
{
	if (!dockableObject)
	{
	    return; 
	}
	if (null == allowShowDragHelper)
	{
	    allowShowDragHelper= true; 
	}
	if (null == attachDragHelperProperty)
	{
	    attachDragHelperProperty= true; 
	}
	this.InitializeDockableObject(dockableObject,allowShowDragHelper,attachDragHelperProperty,attachDragResizeProperty, effectsUpdateRate, effectsDuration, effectsEnable,allowMove,dockableMode); 
	this.SetParentDockingZone(dockableObject); 
}
lionskyDockingManager.prototype.InitializeDockableObject = function(dockableObject,allowShowDragHelper,attachDragHelperProperty,attachDragResizeProperty, effectsUpdateRate, effectsDuration, effectsEnable,allowMove,dockableMode)
{
	if (!dockableObject)
	{
	    return; 
	}
	if (dockableObject.DragHandleElemOnClick)
	{
	    return; 
	}
	allowMove=( true == dockableMode); 
	this.AttachDockDragProperty(dockableObject,allowShowDragHelper,attachDragHelperProperty,attachDragResizeProperty, effectsUpdateRate, effectsDuration, effectsEnable,allowMove,dockableMode);  
	dockableObject.Obo=null; 
	dockableObject.DragHandleElemClientOnClick=null; 
	dockableObject.AllowShowDragHelperCopy=dockableObject.AllowShowDragHelper; 
	this.AttachPrototype(dockableObject,new DockableObjectEventHandler(effectsUpdateRate, effectsDuration, effectsEnable)); 	
	dockableObject.ParentDockingZone=null; 
	if (dockableObject.Initialize)
	{
	    dockableObject.Initialize(); 
	}
	this.DockableObjects[this.DockableObjects.length]=dockableObject; 
}
lionskyDockingManager.prototype.SetWindowScroll = function (rect)
{
	var scrollBy_y = 0; 
	var scrollTop = GetScrollTop(document); 
	var scrollBottom = (document.body.clientHeight+scrollTop); 
	if (rect.top<scrollTop)
	{
		scrollBy_y = - ((scrollTop-rect.top) + 1); 
	}
	else if (rect.bottom>scrollBottom)
	{
		scrollBy_y = (rect.bottom-scrollBottom) + 1; 
	}
	var scrollBy_x = 0; 
	var scrollLeft = GetScrollLeft(document); 
	var scrollRight = (document.body.clientWidth+scrollLeft); 
	if (rect.left<scrollLeft)
	{
		scrollBy_x=-((scrollLeft-rect.left)+1); 
	}
	else if (rect.right>scrollRight)
	{
		scrollBy_x=(rect.right-scrollRight)+1; 
	}
	window.scrollBy(scrollBy_x,scrollBy_y); 
} ; 
lionskyDockingManager.prototype.AttachDragResizeProperty = function(dockableObject)
{
	if (!dockableObject)
	{
	    return; 
	}
	this.AttachPrototype(dockableObject,new DragResizeEventHandler(this)); 
	dockableObject.CanDragResize= true; 
	dockableObject.InitResizeArg(); 
}
lionskyDockingManager.prototype.AttachDockDragProperty = function (dockableObject,allowShowDragHelper,attachDragHelperProperty,attachDragResizeProperty, effectsUpdateRate, effectsDuration, effectsEnable,allowMove,dockableMode)
{
	if (!dockableObject)
	{
	    return; 
	}
	if (dockableObject.AccountMoveSize)
	{
	    return; 
	}
	this.AttachPrototype(dockableObject,new DockDragEventHandler(this, effectsUpdateRate, effectsDuration, effectsEnable)); 
	if (attachDragResizeProperty != false)
	{
	   this.AttachDragResizeProperty(dockableObject); 
	}
	dockableObject.OnDragStart=null; 
	dockableObject.OnMouseUpEvent=null; 
	dockableObject.CanMove= true; 
	dockableObject.CanResize= true; 
	if (attachDragHelperProperty != false &&null != document.all)
	{
	    this.AttachDragHelperProperty(dockableObject); 
	}
	dockableObject.AllowShowDragHelper=(allowShowDragHelper != false); 
	dockableObject.AllowMove=( false != allowMove); 
	if ("string" != typeof(dockableMode))
	{
	    dockableMode="";
	}
	dockableMode=dockableMode.toLowerCase(); 
}
lionskyDockingManager.prototype.AttachDragHelperProperty = function(dockableObject)
{	
	this.AttachPrototype(dockableObject,new DragHelperEventHandler()); 
	if ("complete" == document.readyState)
	{
		dockableObject.SetOverlay(); 
	}
	else 
	{
		dockableObject.NoSetOverlay= true;
	}
}
lionskyDockingManager.prototype.OnMouseOverDockingZoneEvent = function(e)
{
    if (!Cache_SelectDockableObject)
	{
	    return; 
	}
	if (Cache_SelectDockableObject.AllowMove)
	{
	    return; 
	}
	if (!e)
	{
		e=window.event; 
	}
	Cache_SelectDockableObject.OnMouseOverEvent(e); 
	if (Cache_SelectDockableObject.IsDragMove())
	{
		if (null == Cache_SelectDockableObject.ParentDockingZone||Cache_SelectDockableObject.AllowShowDragHelperCopy)
		{
			Cache_OnMouseOverDockingZone=null; 
			var dockingZone; 
			for (var i=0; i<Cache_SelectDockableObject.Controller.DockingZones.length; i++)
			{
				dockingZone=Cache_SelectDockableObject.Controller.DockingZones[i]; 
				if (dockingZone.HitTest(Cache_SelectDockableObject,null == Cache_OnMouseOverDockingZone,e))
				{
					if (!Cache_OnMouseOverDockingZone)
					{
						Cache_OnMouseOverDockingZone=dockingZone; 
					}
				}
			}
		}
		else if (!Cache_SelectDockableObject.AllowShowDragHelperCopy)
		{
			Cache_SelectDockableObject.DragHandleElemOnClick(e); 
		}
	}
	return IanFEvent.stop(e); 
}

function lionskyDockingZoneEventHandler(controller)
{
    this.Controller=controller;
    this.CssClass = ";border-color:DarkBlue;border-style:Dashed;border-width:2px;";
}
lionskyDockingZoneEventHandler.prototype.Bounds = function()
{
    return GetObjectBounds(this); 
}
lionskyDockingZoneEventHandler.prototype.SetOnMouseOverDockingStyle = function(obj,cacheOnMouseOverDockingZone)
{
	if (!obj)
	{
	    return; 
	}
	if (cacheOnMouseOverDockingZone&&null == obj.TempCssClass)
	{
		obj.TempCssClass=obj.style.cssText; 
		obj.style.cssText+= this.CssClass; 
	}
	else if (!cacheOnMouseOverDockingZone&&null != obj.TempCssClass)
	{
		obj.style.cssText=obj.TempCssClass; 
		obj.TempCssClass=null; 
	}
}
lionskyDockingZoneEventHandler.prototype.HitTest = function(dockableObject, cacheOnMouseOverDockingZone, e)
{
	if (!dockableObject.CheckDockableModeisDockingMode(this ))
	{
	    return false; 
	}
	if (null == cacheOnMouseOverDockingZone)
	{
	    cacheOnMouseOverDockingZone= true; 
	}
	var dockableObjectRect=dockableObject.Bounds(); 
	var dockingZoneRect=this.Bounds(); 
	var x=e.clientX+GetScrollLeft(document); 
	var y=e.clientY+GetScrollTop(document); 
	var inBounds=this.Bounds().CheckInBounds(x,y); 
	this.OnMouseOverDockableObject=null; 
	var item; 
	for (var i=0; i<this.childNodes.length; i++)
	{
		item=this.childNodes[i]; 
		if (1 != item.nodeType || item.ParentDockingZone || item == dockableObject){continue;}
		if (!this.OnMouseOverDockableObject&&inBounds&&item.Bounds&&item.Bounds().CheckInBounds(x,y))
		{ 
			this.OnMouseOverDockableObject=item; 
		}
		this.SetOnMouseOverDockingStyle(item,cacheOnMouseOverDockingZone&&item == this.OnMouseOverDockableObject); 
	}
	if (!this.OnMouseOverDockableObject)
	{ 
		this.OnMouseOverDockableObject=(inBounds?this :null); 
	} 
	this.SetOnMouseOverDockingStyle(this,cacheOnMouseOverDockingZone&&this == this.OnMouseOverDockableObject); 
	return inBounds; 
}
lionskyDockingZoneEventHandler.prototype.GetDockableObjectByIndex = function(dockingOrderAttribute)
{
    if (0<=dockingOrderAttribute&&dockingOrderAttribute<this.childNodes.length)
    {
		return this.childNodes[dockingOrderAttribute]; 
	}
	return null;
}
lionskyDockingZoneEventHandler.prototype.InsertBefore = function(dockableObject, dockingOrderAttribute)
{
    if (this == dockableObject.ParentDockingZone)
    {
        return; 
    }
	if (null == dockableObject.getAttribute("dockable"))
	{
		alert("Error: You are trying to dock non-dockable object"); 
		return; 
	}
	if (!dockableObject.CheckDockableModeisDockingMode(this ))
	{
		alert("Error: You are not allowed to dock '"+dockableObject.id+"' to '"+this.id+"' docking zone"); 
		return;
	}
	dockableObject.ParentDockingZone=this ; 
	dockableObject.parentNode.removeChild(dockableObject); 
	dockableObject.style.position=""; 
	var insertBeforeObject; 
	
	if (null != dockingOrderAttribute)
	{
		insertBeforeObject=this.GetDockableObjectByIndex(dockingOrderAttribute); 
	}
	else 
	{
		insertBeforeObject=(this.OnMouseOverDockableObject != this ?this.OnMouseOverDockableObject:null); 
	}	
	if (insertBeforeObject)
	{ 
		this.insertBefore(dockableObject,insertBeforeObject); 
	}
	else 
	{ 
		this.appendChild(dockableObject); 
	} 
	this.SetOnMouseOverDockingStyle(this.OnMouseOverDockableObject, false); 
	this.OnMouseOverDockableObject=null; 
	dockableObject.SetDefault(); 
}

function DockableObjectEventHandler(effectsUpdateRate, effectsDuration, effectsEnable)
{
    this.EffectsUpdateRate = effectsUpdateRate; 
    this.EffectsDuration = effectsDuration;
    this.EffectsEnable = effectsEnable;
}

DockableObjectEventHandler.prototype.HaveParentDokingZone = function()
{	
	return (null != this.ParentDockingZone); 
}
DockableObjectEventHandler.prototype.InsertBefore = function()
{	
    if (!this.ParentDockingZoneCopy)
    {
        return;
    }
    this.ParentDockingZoneCopy.InsertBefore(this ); 
}
DockableObjectEventHandler.prototype.DragHandleElemOnClick = function(e)
{
	if (!this.ParentDockingZone)
	{
	    return; 
	}
	this.ParentDockingZone=null; 
	this.CanDragResize= true; 
	this.parentNode.removeChild(this ); 
	this.style.position="absolute"; 
	this.Hide(this.TitleGrip, true); 
	this.Hide(this.DragHandleElem, false); 
	document.body.appendChild(this); 
	this.SetzIndex(); 
	if (this.InsertBeforeSimulateLayer)
	{ 
		this.InsertBeforeSimulateLayer(); 
	}
	if (this.DragHandleElemClientOnClick)
	{ 
	    this.DragHandleElemClientOnClick(); 
	}
}
DockableObjectEventHandler.prototype.InsertBeforeDragHelperFrame = function()
{     
	if (this.InsertBeforeSimulateLayer&&!this.HaveParentDokingZone())
	{ 
		this.InsertBeforeSimulateLayer(); 
	}
} 
var Cache_OnMouseOverDockingZone=null; 
DockableObjectEventHandler.prototype.OnMouseUpEvent = function(e, rect)
{
    if(this.EffectsEnable)
    {
        var obj = this;
        var MotionHanlderList=new Array(); 
        var MoveToObject = new Object();
        MoveToObject.object = this;
        MoveToObject.Left = rect.left;
        MoveToObject.Top = rect.top;
        MoveToObject.NoInitializeEvent = true
        MotionHanlderList[0]=new MotionHanlderMoveTo(MoveToObject); 
        MotionHanlderBatchHanlderObjcet = new Object();
        MotionHanlderBatchHanlderObjcet.EffectsUpdateRate= this.EffectsUpdateRate;
	    MotionHanlderBatchHanlderObjcet.EffectsDuration = this.EffectsDuration;
	    MotionHanlderBatchHanlderObjcet.EffectsEndEvents = function (){if (obj.AllowShowDragHelperCopy){ obj.DragHandleElemOnClick(e); }};
	    MotionHanlderBatchHanlderObjcet.EffectsEndDeferEvents = function (){if (Cache_OnMouseOverDockingZone){Cache_OnMouseOverDockingZone.InsertBefore(obj); Cache_OnMouseOverDockingZone=null;}} ;
	    MotionHanlderBatchHanlderObjcet.MotionHanlderList = MotionHanlderList ;
        new MotionHanlderBatchHanlder(MotionHanlderBatchHanlderObjcet); 
    }	
    else
    {
        this.MoveTo(rect.left, rect.top);
        if (this.AllowShowDragHelperCopy)
        { 
            this.DragHandleElemOnClick(e); 
        }
        if (Cache_OnMouseOverDockingZone)
        {
            Cache_OnMouseOverDockingZone.InsertBefore(this); 
            Cache_OnMouseOverDockingZone=null;
        }
    }
}
DockableObjectEventHandler.prototype.Hide = function(elem,flag)
{
	if (elem&&!elem.IsVisible)
	{
		elem.style.display=flag?"": "none"; 
	}
}

DockableObjectEventHandler.prototype.GetDockableObjectChildNodeByAttribute = function(dockableObject,attribute, flag)
{
	var aray=[]; 
	if (null != dockableObject)
	{
		if (!flag&&null != dockableObject&&null != dockableObject.className&& dockableObject.className == attribute)
		{
			aray.push(dockableObject); 
		}
		for (var i=0; i<dockableObject.childNodes.length; i++)
		{
			aray=aray.concat(this.GetDockableObjectChildNodeByAttribute(dockableObject.childNodes[i],attribute)); 
		}
	}
	return aray; 
}
DockableObjectEventHandler.prototype.Initialize = function()
{
	var array = this.GetDockableObjectChildNodeByAttribute(this,"DragHandleHorizontal", true); 
	if(array.length==0)
	{
	    array = this.GetDockableObjectChildNodeByAttribute(this,"DragHandleVertical", true); 
	}
	if (array.length>0)
	{ 
		this.DragHandleElem=array[0]; 
		this.DragHandleElem.IsVisible=(array[0].getAttribute("Bvisible")?array[0].getAttribute("Bvisible").toLowerCase() == "visible":false); 
	}
	array=this.GetDockableObjectChildNodeByAttribute(this,"WheDockableObjectTitleBar", true);	
	if (array.length>0)
	{ 
		this.TitleGrip=array[0]; 
		var visible=(array[0].getAttribute("Bvisible")?array[0].getAttribute("Bvisible").toLowerCase() == "visible":false); 
		if (this.TitleGrip.tagName == "TD"||this.TitleGrip.tagName == "TH")
		{ 
			this.TitleGrip=this.TitleGrip.parentNode; 
		} 
		
		this.TitleGrip.IsVisible=visible; 
	} 
	this.Hide(this.TitleGrip, true);
	this.Hide(this.DragHandleElem, false); 
	array=this.GetDockableObjectChildNodeByAttribute(this,"WheDockableObjectCommandButton", true);	
	for (var i=0; i<array.length; i++)
	{
		array[i].ParentDockableObject=this ;
		array[i].onclick= function (){this.ParentDockableObject.InsertBefore(); } ; 
	}
}
DockableObjectEventHandler.prototype.AlwayCheckChangeDockingModeEvent = function()
{
    if (null != this.ParentDockingZone&&VerifyIndexOf(this.ParentDockingZone.DockingMode,"Vertical")&&null != this.ChangeVerticalEvent)
	{
		if (this.CurrentDockingModeIsVertical)
		{
		    return; 
		}
		try 
		{
			if (typeof(this.ChangeVerticalEvent) == "function")
			{ 
				this.ChangeVerticalEvent(); 
			}
			else if (typeof(this.ChangeVerticalEvent) == "string")
			{
				eval(this.ChangeVerticalEvent); 
			}
		}
		catch (ex){} 
		this.CurrentDockingModeIsVertical= true; 
	}
	else if (this.CurrentDockingModeIsVertical&&null != this.ChangeHorizontalEvent)
	{
		try 
		{
			if (typeof(this.ChangeHorizontalEvent) == "function")
			{ 
				this.ChangeHorizontalEvent(); 
			}
			else if (typeof(this.ChangeHorizontalEvent) == "string")
			{
				eval(this.ChangeHorizontalEvent); 
			}
		}
		catch (ex){} 
		this.CurrentDockingModeIsVertical= false; 
	}
}
DockableObjectEventHandler.prototype.CheckDockableModeisDockingMode = function(dockingZone)
{
	var dockableAttribute=this.getAttribute("dockable"); 
	if ("string" == typeof(dockableAttribute))
	{
		dockableAttribute=dockableAttribute.toLowerCase(); 
	}
	if ("all" == dockableAttribute)
	{
		return true; 
	}
	else 
	{
		return (dockableAttribute == dockingZone.DockingMode.toLowerCase()); 
	}
}
DockableObjectEventHandler.prototype.SetDefault = function()
{
	this.ParentDockingZoneCopy=this.ParentDockingZone; 
	this.CanDragResize= false; 
	if (document.all&&"none" != this.style.display)
	{ 
		this.style.display="inline"; 
	} 
	if (this.SimulateLayerSetVisible)
	{ 
		this.SimulateLayerSetVisible(); 
	} 
	this.Hide(this.TitleGrip, false); 
	this.Hide(this.DragHandleElem, true); 
	this.AlwayCheckChangeDockingModeEvent(); 
	if (this.Obo)
	{ 
		this.Obo(); 
	}
}
function DockDragEventHandler(controller, effectsUpdateRate, effectsDuration, effectsEnable)
{
    this.Controller = controller;    
    this.EffectsUpdateRate = effectsUpdateRate; 
    this.EffectsDuration = effectsDuration;
    this.EffectsEnable = effectsEnable;
}

DockDragEventHandler.prototype.ShowDragHelperTooltip = function(e)
{
    if (!Cache_SelectDockableObject)
	{
	    return; 
	}
    this.Controller.DragHelperTooltipElem = this.Controller.GetDragHelperTooltipObject(Cache_SelectDockableObject); 
	var rect,dragHelperToolipValue,x,y; 
	if (this.Controller.DragHelperElem)
	{
	    rect=this.Controller.DragHelperElem.Bounds(); 
	}
	else
	{
	    rect=this.Bounds(); 
	}
	this.Controller.SetWindowScroll(rect); 
	switch (this.DragMode)
	{
		case "move":
			this.Controller.ShowDragHelperTooltip(e,rect, true);
			break; 
		case "resize":
			this.Controller.ShowDragHelperTooltip(e,rect, false);
			break; 
		default:
			return; 
	} 		
}
DockDragEventHandler.prototype.InsertBeforeDragHelperFrame = function()
{
   
	if (this.InsertBeforeSimulateLayer)
	{
		this.InsertBeforeSimulateLayer();
	}
}
DockDragEventHandler.prototype.Show = function(rect)
{	
	if (this.IsVisible())
	{
	    return;
	}
	
	this.style.display=this.DisplayState?this.DisplayState: ""; 
	if (null != rect)
	{ 
		this.SetPosition(rect);
	} 
	this.SetzIndex(); 
	if (this.InsertBeforeDragHelperFrame)
	{
		this.InsertBeforeDragHelperFrame();
	}
}

DockDragEventHandler.prototype.WhereOnMouseUp = function(e)
{
	if (!Cache_SelectDockableObject)
	{
	    return; 
	}
	if (!e)
	{
		e=window.event;
	}
	Cache_SelectDockableObject.MouseUpEvent(e);
}

var Cache_SelectDockableObject;
DockDragEventHandler.prototype.WhereOnMouseMove = function(e)
{
	if (!Cache_SelectDockableObject)
	{
	    return; 
	}
	if (!e)
	{
		e=window.event; 
	}
	Cache_SelectDockableObject.OnMouseOverEvent(e); 
	IanFEvent.stop(e); 
}
Cache_SelectDockableObjectRect=null ;
DockDragEventHandler.prototype.SetDocumentDragEvent = function(e)
{
	this.clientX=e.clientX; 
	this.clientY=e.clientY; 
	IanFEvent.observe(document,"mouseup",this.WhereOnMouseUp); 
	if (this.AllowMove)
	{
		IanFEvent.observe(document,"mousemove",this.WhereOnMouseMove); 
	}
	Cache_SelectDockableObject=this ;
	Cache_SelectDockableObjectRect = this.Bounds();
	if (this.AllowShowDragHelper)
	{ 
		this.Controller.DragHelperElem.Show(this.Bounds()); 
	}
	if (this.OnDragStart)
	{ 
		this.OnDragStart(e); 
	}
	ShowScreenCacheImage();	
	this.ShowDragHelperTooltip(e); 
	window.status=""; 
}
DockDragEventHandler.prototype.Clear = function(e)
{
	Cache_SelectDockableObject = null; 
	Cache_SelectDockableObjectRect = null;
	HideScreenCacheImage(); 
	this.Controller.Editor.detachEvent(document,"onmouseup",this.WhereOnMouseUp); 
	if (this.AllowMove)
	{
		this.Controller.Editor.detachEvent(document,"onmousemove",this.WhereOnMouseMove); 
	}
	if (this.Controller.DragHelperElem)
	{ 
		this.Controller.DragHelperElem.Hide(); 
	} 
	this.DragMode=""; 
	window.status=""; 
	if (this.Controller.DragHelperTooltipElem)
	{ 
		this.Controller.DragHelperTooltipElem.Hide(); 
		this.Controller.DragHelperTooltipElem.innerHTML="";
		this.Controller.DragHelperTooltipElem == null;
	}
}
DockDragEventHandler.prototype.OnMouseOverEvent = function(e)
{
	switch (this.DragMode)
	{
		case "move": 
			this.AccountMoveSize(e); 
			break; 
		case "resize": 
			this.OnResizeSize(e); 
			break; 
	} 
	this.clientX=e.clientX; 
	this.clientY=e.clientY; 
	this.ShowDragHelperTooltip(e); 
}
DockDragEventHandler.prototype.IsDragMove = function()
{
	return ("move" == this.DragMode); 
}
DockDragEventHandler.prototype.IsDragResize = function()
{
    return ("resize" == this.DragMode); 
}
DockDragEventHandler.prototype.onmousemove = function(e)
{	
	if (!e)
	{
		e=window.event; 
	}
	if (!this.IsDragResize()&&null != this.GetResizeSize)
	{ 
		this.ResizeSize=this.GetResizeSize(e); 
		this.style.cursor=this.ResizeSize; 
	}
	if (!this.ResizeSize)
	{ 
	    var source=GetSrcElement(e); 
	    switch(source.className)
	    {
	        case "DragHandleVertical":
	        case "DragHandleHorizontal":
	        case "WheDockableObjectTitleBar":
	            this.style.cursor="move";  
	    }	
		
	}
}
DockDragEventHandler.prototype.Bounds = function()
{
	if (this == Cache_SelectDockableObject&&this.Controller.DragHelperElem&&this.Controller.DragHelperElem.IsVisible())
	{
		return GetObjectBounds(this.Controller.DragHelperElem); 
	}
	else 
	{
		return GetObjectBounds(this ); 
	}
}
DockDragEventHandler.prototype.onmousedown = function(e)
{
	if (!e)
	{
		e=window.event; 
	}
	if (document.all&&e.button != 1)
	{
	    return; 
	}
	if (this.SetzIndex)
	{
	    this.SetzIndex(); 
	}
	this.DragMode=""; 
	if (this.CanResize&&this.ResizeSize)
	{ 
		this.DragMode="resize"; 
	}
	else if (this.CanMove)
	{ 
	    var source=GetSrcElement(e); 
	    switch(source.className)
	    {
	        case "DragHandleVertical":
	        case "DragHandleHorizontal":
	        case "WheDockableObjectTitleBar":
	            this.DragMode="move"; 
	    }		
	}
	if ("" != this.DragMode)
	{ 
		this.SetDocumentDragEvent(e); 
	}
	IanFEvent.stop(e); 
	return false; 
}
DockDragEventHandler.prototype.onmouseout = function(e)
{
	if ("" != this.style.cursor)
	{ 
		this.style.cursor=""; 
	}
}
DockDragEventHandler.prototype.IsVisible = function()
{
	return (this.style.display != "none");
}

DockDragEventHandler.prototype.Hide = function()
{
	if (!this.IsVisible())
	{
	    return;
	}
	this.DisplayState=this.style.display; 
	this.style.display="none"; 
	if (this.SimulateLayerSetVisible)
	{ 
		this.SimulateLayerSetVisible();
	}
}
DockDragEventHandler.prototype.SetSize = function(width,height)
{
	width=parseInt(width);
	if (!isNaN(width)&&width>=0)
	{ 
		this.style["width"]=width+"px"; 
		if (this.SimulateLayer)
		{ 
			this.SimulateLayer.style["width"]=width+"px"; 
		}
	}
	height=parseInt(height); 
	if (!isNaN(height)&&height>=0)
	{ 
		this.style["height"]=height+"px"; 
		if (this.SimulateLayer)
		{ 
			this.SimulateLayer.style["height"]=height+"px"; 
		}
	}
}
DockDragEventHandler.prototype.SetPosition = function(rect)
{
	if (rect)
	{ 
		this.MoveTo(rect.left,rect.top); 
		this.SetSize(rect["width"],rect["height"]); 
	}
}
DockDragEventHandler.prototype.AccountMoveSize = function(e)
{
	var x=e.clientX-this.clientX; 
	var y=e.clientY-this.clientY; 
	if (this.Controller.DragHelperElem)
	{ 
		this.Controller.DragHelperElem.MoveBy(x,y); 
	}
	else 
	{ 
		this.MoveBy(x,y); 
	}
}

DockDragEventHandler.prototype.MouseUpEvent = function(e)
{    
	var rect;
	if (this.Controller.DragHelperElem)
	{
		var rect=this.Controller.DragHelperElem.Bounds(); 
    }	
	this.Clear(e); 
	if (this.OnMouseUpEvent)
	{ 
		this.OnMouseUpEvent(e, rect); 
	}
}
DockDragEventHandler.prototype.MoveBy = function(x,y)
{
	if (!this.MoveToX)
	{ 
		this.MoveToX=parseInt(this.style.left); 
	}
	if (!this.MoveToY)
	{ 
		this.MoveToY=parseInt(this.style.top); 
	} 
	this.MoveTo(this.MoveToX+x,this.MoveToY+y); 
}
DockDragEventHandler.prototype.MoveTo = function(x,y)
{ 
	this.MoveToX=x; 
	this.MoveToY=y; 
	this.style.position="absolute";
	this.style.left=this.MoveToX+"px"; 
	this.style.top=this.MoveToY+"px"; 
	if (this.NoSetOverlay)
	{ 
		this.SetOverlay(); 
		this.NoSetOverlay= false; 
	}
	if (this.SimulateLayer)
	{
		this.SimulateLayer.style.top=parseInt(this.style.top)+"px"; 
		this.SimulateLayer.style.left=parseInt(this.style.left)+"px"; 
	}
}
DockDragEventHandler.prototype.SetzIndex = function()
{
	var maxzIndex=0;
	var zIndex=0;
	var childs=this.parentNode.childNodes; 
	var node; 
	for (var i=0; i<childs.length; i++)
	{
		node=childs[i]; 
		if (1 != node.nodeType)
		{
		    continue; 
		 }
		zIndex=parseInt(node.style.zIndex); 
		if (zIndex>maxzIndex)
		{
		    maxzIndex=zIndex; 
		}
	} 
	this.style.zIndex=maxzIndex+1; 
}
function DragHelperEventHandler(){}

DragHelperEventHandler.prototype.SetOverlay = function()
{
	var frm=document.createElement("IFRAME"); 
	frm.src="javascript:false"; 
	frm.frameBorder=0; 
	frm.scrolling="no"; 
	frm.style.overflow="hidden";
	frm.style.display="inline";
	frm.style.position="absolute";
	try 
	{
		var rect=this.Bounds(); 
		frm.style["width"]=parseInt(rect["width"])+"px";
		frm.style["height"]=parseInt(rect["height"])+"px"; 
		frm.style.left=parseInt(rect.left)+"px"; 
		frm.style.top=parseInt(rect.top)+"px"; 
	}
	catch (ex){} 
	this.parentNode.insertBefore(frm,this ); 
	this.SimulateLayer=frm;
}
DragHelperEventHandler.prototype.InsertBeforeSimulateLayer = function()
{
	if (this.SimulateLayer)
	{
		this.parentNode.insertBefore(this.SimulateLayer,this ); 
		this.SimulateLayer.style.display="inline"; 
		this.SimulateLayer.style.position="absolute"; 
		var rect=this.Bounds();
		this.SimulateLayer.style["width"]=parseInt(rect["width"])+"px";
		this.SimulateLayer.style["height"]=parseInt(rect["height"])+"px"; 
		this.SimulateLayer.style.left=parseInt(rect.left)+"px"; 
		this.SimulateLayer.style.top=parseInt(rect.top)+"px"; 
	}
}
DragHelperEventHandler.prototype.SimulateLayerSetVisible = function()
{
	if (null != this.SimulateLayer&&null != this.SimulateLayer.parentNode)
	{ 
		this.SimulateLayer.parentNode.removeChild(this.SimulateLayer); 
		this.SimulateLayer.style.display="none"; 
	}
}
DragHelperEventHandler.prototype.SimulateLayerIsVisible = function()
{
	return (this.SimulateLayer&&this.SimulateLayer.style.display != "none");
}

function DragResizeEventHandler(controller)
{
    this.Controller = controller;
}
DragResizeEventHandler.prototype.GetResizeSize = function(e,MinX,MinY)
{
    if (!this.CanDragResize)
    {
        return ""; 
    }
	if (e.srcElement != this &&e.target != this )
	{
	    return ""; 
	}
	var rect=this.Bounds(); 
	var result=""; 
	if (null == MinX)
	{
	    MinX=5; 
	}
	if (null == MinY)
	{
	    MinY=5; 
	}
	var offsetX,offsetY; 
	if (null != e.offsetY)
	{
		offsetX=e.offsetX; 
		offsetY=e.offsetY; 
	}
	else if (null != e.layerY)
	{
		offsetX=e.layerX; 
		offsetY=e.layerY; 
	}
	if (offsetY<=MinY&&this.ResizeN)
	{
		result+="n"; 
	}
	else if ((rect["height"]-offsetY)<=MinY&&this.ResizeS)
	{
		result+="s"; 
	}
	if (offsetX<=MinX&&this.ResizeW)
	{
		result+="w"; 
	}
	else if ((rect["width"]-offsetX)<=MinX&&this.ResizeE)
	{
		result+="e"; 
	}
	return ("" != result?(result+"-resize"): ""); 
}

DragResizeEventHandler.prototype.OnResizeSize = function(e)
{
	var x=e.clientX-this.clientX; 
	var y=e.clientY-this.clientY; 
	this.style.cursor=this.ResizeSize; 
	switch (this.ResizeSize)
	{
		case "n-resize": 
			this.SetResizeSize(0,y,null,null); 
			break; 
		case "s-resize": 
			this.SetResizeSize(0,0,0,y);
			break; 
		case "w-resize": 
			this.SetResizeSize(x,0,null,null); 
			break; 
		case "e-resize": 
			this.SetResizeSize(0,0,x,0); 
			break; 
		case "ne-resize": 
			this.SetResizeSize(0,y,x,null); 
			break; 
		case "nw-resize": 
			this.SetResizeSize(x,y,null,null); 
			break; 
		case "se-resize": 
			this.SetResizeSize(0,0,x,y); 
			break; 
		case "sw-resize": 
			this.SetResizeSize(x,0,null,y); 
			break; 
		default:
			break; 
	}
}
DragResizeEventHandler.prototype.SetResizeSize = function(offsetLeft,offsetTop,offsetWidth,offsetHeight)
{	
	var rect=this.Bounds(); 
	var top=rect.top+offsetTop; 
	var left=rect.left+offsetLeft; 
	if (top<0)
	{
		offsetTop=-rect.top; 
	}
	if (left<0)
	{
		offsetLeft=-rect.left; 
	}
	top=rect.top+offsetTop; 
	left=rect.left+offsetLeft; 
	if (null == offsetWidth)
	{
	    offsetWidth=-offsetLeft; 
	}
	if (null == offsetHeight)
	{
	    offsetHeight=-offsetTop; 
	}
	var width=rect["width"]+offsetWidth; 
	var height=rect["height"]+offsetHeight; 
	width=Math.max(this.MinWidth,width); 
	width=Math.min(this.MaxWidth,width); 
	height=Math.max(this.MinHeight,height); 
	height=Math.min(this.MaxHeight,height); 
	var dockableObject=(this.Controller.DragHelperElem?this.Controller.DragHelperElem: this ); 
	if (rect["width"] != width)
	{
		dockableObject.MoveBy(offsetLeft,0); 
		dockableObject.SetSize(width,null); 
	}
	if (rect["height"] != height)
	{
		dockableObject.MoveBy(0,offsetTop); 
		dockableObject.SetSize(null,height); 
	}
}
DragResizeEventHandler.prototype.InitResizeArg = function()
{
	var attribute=this.getAttribute("resize"); 
	if ("string" == typeof(attribute))
	{
		attribute=attribute.toLowerCase(); 
	}
	else 
	{
		attribute="nsew"; 
	} 
	this.ResizeN=(-1 != attribute.indexOf("n")); 
	this.ResizeS=(-1 != attribute.indexOf("s")); 
	this.ResizeE=(-1 != attribute.indexOf("e")); 
	this.ResizeW=(-1 != attribute.indexOf("w"));  
	this.MinWidth=GetNumDefaultValue(this.getAttribute("minWidth")); 
	this.MaxWidth=GetNumDefaultValue(this.getAttribute("maxWidth"),0x186A0);
	this.MinHeight=GetNumDefaultValue(this.getAttribute("minHeight")); 
	this.MaxHeight=GetNumDefaultValue(this.getAttribute("maxHeight"),0x186A0); 
}

function lionskyDragHelperTooltipEventHandler(){}

lionskyDragHelperTooltipEventHandler.prototype.SetDragHelperTooltipValue = function (value)
{
	this.innerHTML=""; 
	this.appendChild(document.createTextNode(value)); 
}

lionskyDragHelperTooltipEventHandler.prototype.Show = function (x,y)
{
    this.SetzIndex();
	this.style.display=""; 
	this.style.left=parseInt(x) + "px"; 
	this.style.top=parseInt(y) + "px"; 
}

lionskyDragHelperTooltipEventHandler.prototype.Hide = function ()
{
	this.style.display="none"; 
}
lionskyDragHelperTooltipEventHandler.prototype.SetzIndex = function ()
{
	new DockDragEventHandler().SetzIndex.call(this ); 
}	

function HideScreenCacheImage()
{
    var img=GetImage(); 
    if (img)
    {
        img.parentNode.removeChild(img); 
        img.style.display="none"; 
    }
}
var Cache_DragImage;
function GetImage()
{
	if (!Cache_DragImage)
	{
		var img=document.createElement("IMG");
		img.style.display="none"; 
		img.setAttribute("unselectable","on"); 
		img.onselectstart=CancelSelect; 
		img.ondragstart=CancelSelect; 
		img.onmouseover=CancelSelect; 
		img.onmousemove=CancelSelect; 
		Cache_DragImage=img;
	}
	return Cache_DragImage; 
}
function ShowScreenCacheImage(insertBefore)
{
	var img=GetImage(); 
	if (img)
	{
		document.body.appendChild(img); 
		img.style.position="absolute"; 
		img.style.display=""; 
		img.style.left=img.style.top="0px"; 
		img.style["width"]=(parseInt(window.screen["width"])-1) + "px"; 
		img.style["height"]=(parseInt(window.screen["height"])-1) + "px";
	}
}
Function.prototype.ApplyPropertype = function (object)
{
	var obj=this ; 
	return function (){obj.apply(object,arguments); } ; 
} ; 
MotionHanlder = {} ; 

function MotionBaseHanlder(){} ; 
MotionBaseHanlder.prototype.Initialize = function ()
{
	var HanlderObject=arguments[0]|| {} ; 
	HanlderObject.EffectsUpdateRate=HanlderObject.EffectsUpdateRate||031; 
	HanlderObject.EffectsDuration=HanlderObject.EffectsDuration||1; 
	this.HanlderObject=HanlderObject; 
	if (!HanlderObject.NoInitializeEvent)
	{ 
		this.InitializeEvent(); 
	}
} ; 
MotionBaseHanlder.prototype.InitializeEvent = function ()
{
	var HanlderObject=this.HanlderObject; 
	if (this.Preparation)
	{ 
		this.Preparation(); 
	}
	if (HanlderObject.EffectsEndEvents)
	{
		HanlderObject.EffectsEndEvents(); 
	} 
	this.FrameTime=0; 
	this.StartTime=new Date().getTime(); 
	this.EndTime=this.StartTime+(HanlderObject.EffectsDuration*01750); 
	this.Start(); 
} ; 
MotionBaseHanlder.prototype.Underway= function ()
{ 
	this.IsUnderway= true; 
} ; 
MotionBaseHanlder.prototype.Start= function ()
{
	var HanlderObject=this.HanlderObject; 
	var isUnderway=this.IsUnderway; 
	var time=new Date().getTime(); 
	var frame=Math.round((time-this.StartTime)*HanlderObject.EffectsUpdateRate/01750); 
	
	if (frame>this.FrameTime&&!isUnderway)
	{ 
		this.FrameTime=frame; 
		var flagTime=Math.min((time-this.StartTime)/(this.EndTime-this.StartTime),1); 
		isUnderway=this.Execute(flagTime)||(time>=this.EndTime); 
	}
	
	if (!isUnderway)
	{ 
		setTimeout(this.Start.ApplyPropertype(this ),024); 
	}
	else 
	{ 
		this.OnClientEffectsEndDeferEvents(); 
	}
} ; 
MotionBaseHanlder.prototype.Execute= function ()
{
	return true; 
} ; 
MotionBaseHanlder.prototype.OnClientEffectsEndDeferEvents= function ()
{
	if (this.HanlderObject.EffectsEndDeferEvents)
	{ 
		this.HanlderObject.EffectsEndDeferEvents(); 
	}
} ; 
function MotionHanlderSetSize()
{
	this.Initialize.apply(this,arguments);
};
MotionHanlderSetSize.prototype=new MotionBaseHanlder; ; 
MotionHanlderSetSize.prototype.Preparation= function ()
{
	var HanlderObject=this.HanlderObject; 
	var object=HanlderObject.object; 
	this["width"]=parseInt(HanlderObject.Width||object.clientWidth); 
	this["height"]=parseInt(HanlderObject.Height||object.clientHeight); 
	
	HanlderObject["width"]=parseInt(null != HanlderObject["width"]?HanlderObject["width"]: this["width"]); 
	HanlderObject["height"]=parseInt(null != HanlderObject["height"]?HanlderObject["height"]: this["height"]); 
	if (HanlderObject["width"]<0)
	{
		HanlderObject["width"]=0; 
	}
	if (HanlderObject["height"]<0)
	{
		HanlderObject["height"]=0; 
	} 
	this.ResidualWidth=(HanlderObject["width"]-this["width"]); 
	this.ResidualHeight=(HanlderObject["height"]-this["height"]); 
} ; 
MotionHanlderSetSize.prototype.Execute= function (point)
{
	var HanlderObject=this.HanlderObject; 
	var object = HanlderObject.object; 
	var width = this["width"] + point*this.ResidualWidth; 
	var height = this["height"] + point*this.ResidualHeight; 
	object.style["width"]=Math.floor(width)+"px"; 
	object.style["height"]=Math.floor(height)+"px"; 
	var node; 
	for (var i=0; i<object.childNodes.length; i++)
	{
		node=object.childNodes[i]; 
		if (node.style)
		{
			node.style["width"]=object.style["width"]; 
			node.style["height"]=object.style["height"]; 
		}
	}
} ;
function MotionHanlderBatchHanlder()
{
	this.Initialize.apply(this,arguments);
};
MotionHanlderBatchHanlder.prototype=new MotionBaseHanlder; ; 
MotionHanlderBatchHanlder.prototype.Preparation= function ()
{
	var item=this.HanlderObject.MotionHanlderList; 
	for (var i=0; i<item.length; i++)
	{
		item[i].Preparation(); 
	}
} ; 
MotionHanlderBatchHanlder.prototype.Execute= function (flagTime)
{
	var item=this.HanlderObject.MotionHanlderList; 
	for (var i=0; i<item.length; i++)
	{
		item[i].Execute(flagTime); 
	}
} ; 
function MotionHanlderMoveTo()
{
	this.Initialize.apply(this,arguments);
};
MotionHanlderMoveTo.prototype=new MotionBaseHanlder; 
MotionHanlderMoveTo.prototype.Preparation= function ()
{
	var HanlderObject=this.HanlderObject; 
	this.object=HanlderObject.object; 
	this.object.position="absolute"; 
	var rect=HanlderObject.object.Bounds(); 
	this.CurrentX=rect.left; 
	this.CurrentY=rect.top; 
	this.Left=(null != HanlderObject.Left?HanlderObject.Left:rect.left); 
	this.Top=(null != HanlderObject.Top?HanlderObject.Top:rect.top); 
	this.ResidualX=(this.Left-this.CurrentX); 
	this.ResidualY=(this.Top-this.CurrentY); 
} ; 
MotionHanlderMoveTo.prototype.Execute= function (flagTime)
{
	var HanlderObject=this.HanlderObject; 
	var object=this.object; 
	var x=this.CurrentX+flagTime*this.ResidualX; 
	var y=this.CurrentY+flagTime*this.ResidualY; 
	object.style.left=x+"px"; 
	object.style.top=y+"px"; 
} ; 