window.FloatCorretor = new function()
{
	this.TargetX = 0;
	this.TargetY = 0;
	this.Count = 0;
	
	this.Move = function()
	{
		this.Menu.style.left = this.NextX + 'px';
		this.Menu.style.top  = this.NextY + 'px';
	}
	this.Freeze = function()
	{
		if(!this.IsRunning) return;
		this.NextX = 0;
		this.NextY = 0;
		this.Move();
		this.Move = function(){};
		this.Frozen = 1;
		this.BtnFreeze.style.display = 'none';

		document.cookie = 'cook_freeze=1';
	}
	this.GetCookie = function()
	{
		if (document.cookie.length > 0)
		{
			c_start = document.cookie.indexOf('cook_freeze=');

			if (c_start != -1)
			{
				return true;
			}
		}
		return false;
	}
	this.ComputeShifts = function()
	{
		var de = document.documentElement;
		this.ShiftX = this.HasInner ? pageXOffset : (this.HasElement ? de.scrollLeft : document.body.scrollLeft);

		if (this.TargetX < 0)
			this.ShiftX += this.HasElement ? de.clientWidth : this.HasInner ? window.innerWidth : document.body.clientWidth;

		this.ShiftY = this.HasInner ? pageYOffset : this.HasElement ? de.scrollTop : document.body.scrollTop;
		if (this.TargetY < 0)
			this.ShiftY += this.HasElement ? document.documentElement.clientHeight : this.HasInner ? window.innerHeight : document.body.clientHeight;
	}
	this.DoFloat = function()
	{
		var stepX, stepY;

		this.ComputeShifts();

		stepX = (this.ShiftX + this.TargetX - this.NextX) * .07;
		if (Math.abs(stepX) < .5)
			stepX = this.ShiftX + this.TargetX - this.NextX;

		stepY = (this.ShiftY + this.TargetY - this.NextY) * .07;
		if (Math.abs(stepY) < .5)
			stepY = this.ShiftY + this.TargetY - this.NextY;

		if (Math.abs(stepX) > 0 || Math.abs(stepY) > 0)
		{
			//this.NextX += stepX;
			this.NextY += stepY;
			this.Move();
		}
		setTimeout('FloatCorretor.DoFloat()', 20);
	}

	this.Init = function()
	{
		this.BtnFreeze  = document.getElementById('hea_freeze');
		this.Menu		= document.getElementById('hea_floater');
		this.HasInner	= typeof(window.innerWidth) == 'number';
		this.HasElement = document.documentElement && document.documentElement.clientWidth;
		this.IsRunning  = 1;
		
		this.ComputeShifts();
		this.NextX = this.ShiftX + this.TargetX;
		this.NextY = this.ShiftY + this.TargetY;

		if(!this.GetCookie())
		{
			this.Move();
			this.DoFloat();
		}
	}
	
	this.ClearTimer = function()
	{
		if(!this.IsRunning) return;
		if( this.Frozen ) return;

		clearTimeout(this.Timer)
	}
	this.SetTimer = function()
	{
		if(!this.IsRunning) return;
		if(this.Frozen) return;
	}
	this.ShowFreezeButton = function()
	{
		if( this.Frozen || this.GetCookie() ) return;
		
		this.BtnFreeze.style.display = '';
		this.ClearTimer()
	}
}
