var dom = (document.getElementById)? true:false;	//DOM
var ns = (document.layers)? true:false;				//NS
var ie = (document.all)? true:false;				//IE

var PosStart = -320;
var PosEnd = 280;

function GetNSObject(MyID,MyDocument)
{
	var MyObject= eval('MyDocument.'+MyID);
	if (!(MyObject))
	{
		for(var i=0;i<MyDocument.layers.length;i++)
		{
			MyObject = GetNSObject(MyID,MyDocument.layers[i].document);
			if (MyObject) break;
		}
	}
	return MyObject;
}

function GetObject(MyID)
{
	if (dom) return document.getElementById(MyID);
	if (ie)  return document.all[MyID];
	if (ns)  return GetNSObject(MyID,window.document);
	return 0;
}

function GetCSS(MyObject)
{
	if (dom || ie) return MyObject.style;
	else if (ns) return MyObject;
	else return 0;
}

function GetHeight(MyObject)
{ 
	if (dom || ie) return MyObject.offsetHeight;
	else if (ns) return MyObject.clip.height;
	else return 0;
}
	
function GetWidth(MyObject)
{ 
	if (dom || ie) return MyObject.offsetWidth;
	else if (ns) return MyObject.clip.width;
	else return 0;
}

function GetTop(MyObject)
{ 
	if (dom || ie) return MyObject.offsetTop;
	else if (ns) return MyObject.y;
  	else return 0;
}

function GetLeft(MyObject)
{ 
	if (dom || ie) return MyObject.offsetLeft;
	else if (ns) return MyObject.x;
	else return 0;
}

function PopupStop()
{
	if (this.ProcessId) clearTimeout(this.ProcessId);
	this.ProcessId = null;
}

function PopupMoveDown(mystep)
{
	this.Container.Y += mystep;
	this.Container.CSS.top = this.Container.Y + 'px';
}

function PopupMoveUp(mystep)
{
	this.Container.Y -= mystep;
	this.Container.CSS.top = this.Container.Y + 'px';
}

function PopupStart()
{
	this.stop();
	this.Container.Down(this.Step);
	if (this.Container.Y < this.Destination) this.ProcessId = setTimeout(this.name + '.start()', this.Interval);
}

function PopupFermer()
{
	this.stop();
	this.Container.Up(this.Step);
	if (this.Container.Y > this.StartY) this.ProcessId = setTimeout(this.name + '.close()', this.Interval);
}

function CreateObject(DivId,MyObject)
{
	if (MyObject) this.Object = MyObject;
	else this.Object = GetObject(DivID);
    
    if (this.Object)
    {
		this.CSS = GetCSS(this.Object);
		this.Height = GetHeight(this.Object);
		this.Width = GetWidth(this.Object);
		this.X = GetLeft(this.Object);
		this.Y = GetTop(this.Object);
		this.StartY = GetTop(this.Object);
		this.Up = PopupMoveUp;
		this.Down = PopupMoveDown;
		this.Stop = PopupStop;
    }
	return this;
}

function PopupBox(PopupName, DivId, myStep, myInterv, myDest)
{
	this.name = PopupName;
	this.Step = myStep ? myStep : 1;
	this.Interval = myInterv ? myInterv : 50;
	this.Destination = myDest ? myDest : PosEnd;
	this.ProcessId= null;
	this.Container = new CreateObject(DivId);
	this.StartY = this.Container.Y;
	this.Container.Object.onclick = function() {eval(PopupName + '.close();')};
}

PopupBox.prototype.start = PopupStart;
PopupBox.prototype.close = PopupFermer;
PopupBox.prototype.stop = PopupStop;