// -----------------------------------------------------------------------------------------
// code: sebastian kumorowski (algeron) build - 2000.10.01
// -----------------------------------------------------------------------------------------

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function size(argX, argY, argWidth, argHeight) {
  this.x = argX;
  this.y = argY;
  this.width = argWidth;
  this.height = argHeight;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function dynamic(argObj) {
  this.e = (document.all ? true : false);
  this.n = (document.layers ? true : false);

  this.obj = argObj;

  this.put = put;
  this.mov = mov;
  this.data = data;

  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  function put(argX, argY) {
    if (this.e) {
	  this.obj.style.top = argY;
	  this.obj.style.left = argX;
    } else if (this.n) {
	  this.obj.top = argY;
	  this.obj.left = argX;
    };
  }

  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  function mov(argDx, argDy) {
    var s = this.data();
    s.x += argDx;
    s.y += argDy;

    this.put(s.x, s.y);
  }

  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  function data() {
    var x = null, y = null, w = null, h = null;

    if (this.e) {
	  w = this.obj.clientWidth;
	  h = this.obj.clientHeight;
	  x = this.obj.offsetLeft;
	  y = this.obj.offsetTop;
    } else if (this.n) {
	  w = this.obj.document.width;
	  h = this.obj.document.height;
      x = this.obj.left;
	  y = this.obj.top;
    };

    return new size(x, y, w, h);
  }
}

var e = (document.all ? true : false);
var dynObj = null;
var dragOn = false;
var mx = 0, my = 0;
var offsetYCache = null;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function init() {
  dynObj = new dynamic((e ? myDiv : document.layers["myDiv"]));

  if (!e) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
  document.onmousedown = mouseDown;
  document.onmousemove = mouseMove;
  document.onmouseup = mouseUp;

  dynObj.mov(0, (!e ? window.pageYOffset : document.body.scrollTop));
  var yObj = (e ? dynObj.obj.style.pixelTop : dynObj.data().y);
  offsetYCache = yObj - (!e ? window.pageYOffset : document.body.scrollTop);

  engineOffset();
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function mouseDown(argEvt) {
  var x = (!e ? argEvt.pageX : event.x + document.body.scrollLeft);
  var y = (!e ? argEvt.pageY : event.y + document.body.scrollTop);
  var s = dynObj.data();

  if (x >= s.x && x <= (s.x + s.width) && y >= s.y && y <= (s.y + s.height)) {
    dragOn = true;
	return false;
  } else {
    //offsetYCache = dynObj.data().y - (!e ? window.pageYOffset : document.body.scrollTop);
  };

  return true;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function mouseMove(argEvt) {
  var x = (!e ? argEvt.pageX : event.clientX) - mx;
  var y = (!e ? argEvt.pageY : event.clientY) - my;
  var p = dynObj.data();

  mx = (!e ? argEvt.pageX : event.clientX);
  my = (!e ? argEvt.pageY : event.clientY);

  if (dragOn) {
    dynObj.mov(x, y);
	return false;
  };

  return true;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function mouseUp(argEvt) {
  if (dragOn) offsetYCache = dynObj.data().y - (!e ? window.pageYOffset : document.body.scrollTop);

  dragOn = false;
  return true;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function engineOffset() {
  //if (offsetYCache != null) {
  //  return;
  //};

  var offsetY = dynObj.data().y - (!e ? window.pageYOffset : document.body.scrollTop);

  if (!dragOn && offsetY != offsetYCache) {
    var speed = (offsetY - offsetYCache) / -10;
    if (speed < 1 && speed > 0) speed /= speed;
	  else if (speed > -1 && speed < 0) speed /= speed * -1;

    dynObj.mov(0, speed);
  } else
    offsetYCache = offsetY;

  setTimeout("engineOffset()", 10);
}

function UrlFlash(strName) {
	var strHost;
	//strHost=window.location.host+"/dialog.php?strpage="+strName;
	strHost="http://nasmobile/siam-magic.com/www"+"/dialog.php?strpage="+strName;
	//strHost="http://www.siam-magic.com"+"/dialog.php?strpage="+strName;
	
  	window.document.swf_menu.SetVariable("url",strHost);	
}