// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this header
// Upgraded by www.dizzy.hr / Copyright 2005

function newFloatingLayer(inst, name)
{
    eval(inst + ' = new FloatLayer("' + name + '", "' + inst + '");');
}

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

var instset = new Array(0);

function FloatLayer(name, instname)
{
    var tempset = new Array(instname);
    instset = instset.concat(tempset);

    this.ddEnabled = false;
    this.lastPos = false;
    this.isHot=false;
    
    this.whichDog = null;

    this.offsetx = 0;
    this.offsety = 0;
    this.nowX = 0;
    this.nowY = 0;
    
    this.floatingLayerName = name;
    
    this.showFloatingLayer = showFloatingLayer;
    this.hideFloatingLayer = hideFloatingLayer;
    this.toggleFloatingLayer = toggleFloatingLayer;

    document.onmousedown=ddInit;
    document.onmouseup=ddEnd;
}

function showFloatingLayer()
{
    var el = document.getElementById(this.floatingLayerName);
    if (!this.lastPos)
    {
        var myWidth = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            myWidth = window.innerWidth;
          } else if( document.documentElement &&
          ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            myWidth = document.documentElement.clientWidth;
          } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
          }
        el.style.left = (myWidth / 2) - (el.style.width / 2) + 'px';
        this.lastPos = true;        
    }
    el.style.display = 'block';
}

function hideFloatingLayer()
{
    document.getElementById(this.floatingLayerName).style.display = 'none';
}

function toggleFloatingLayer()
{
    //alert(document.getElementById(this.floatingLayerName).style.display);
    if (document.getElementById(this.floatingLayerName).style.display == 'block')
        this.hideFloatingLayer();
    else
        this.showFloatingLayer();
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  for (var i = 0; i < instset.length; i++)
  {
   var instance = eval(instset[i]);
   instance.whichDog=document.getElementById(instance.floatingLayerName);
   instance.whichDog.style.zIndex = 2;
   hotDog=isIE ? event.srcElement : e.target;  
   while (hotDog.id!=instance.floatingLayerName&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
   }
   if (hotDog.id==instance.floatingLayerName){
    instance.whichDog.style.zIndex = 5;
    instance.offsetx=isIE ? event.clientX : e.clientX;
    instance.offsety=isIE ? event.clientY : e.clientY;
    instance.nowX=findPosX(instance.whichDog);
    instance.nowY=findPosY(instance.whichDog);
    instance.ddEnabled=true;
   }
  }
  document.onmousemove=dd;
}

function ddEnd(e){
  for (var i = 0; i < instset.length; i++)
  {
   var instance = eval(instset[i]);
   instance.ddEnabled = false;
  }
  document.onmousemove=null;
  return false;
}

function dd(e){
 for (var i = 0; i < instset.length; i++)
 {
  var instance = eval(instset[i]);
  if (instance.ddEnabled)
  {
    instance.whichDog.style.left=(isIE ? instance.nowX+event.clientX-instance.offsetx : instance.nowX+e.clientX-instance.offsetx) + 'px'; 
    instance.whichDog.style.top=(isIE ? instance.nowY+event.clientY-instance.offsety : instance.nowY+e.clientY-instance.offsety) + 'px';
  }
 }
 return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

