
// system.js by Oto Valek <oto@email.cz>
// thanks for viewing the source code !

/**************************************************
This JavaScript code uses techniques found at
The Dynamic Duo - http://www.dansteinman.com/dynduo/
**************************************************/

/**************************************************
Some code is (C) 1999 by Mike Hall.
Web address: http://www.brainjar.com
**************************************************/

/* expects global variables set as follows:
 ns  = (document.layers)? true:false
 ie  = (document.all)? true:false
 ie4 = (navigator.appVersion.indexOf('MSIE 4')>0)
*/

 function layerobject(id,parent) {
  if (ns) {
   obj = (parent)? eval("document."+parent+".document."+id) : document.layers[id]
   obj.width = obj.clip.width
   obj.height = obj.clip.height
   obj.obj = obj
  }
  else if (ie) {
   tmp = document.all[id]
   obj = tmp.style
   obj.left = tmp.offsetLeft
   obj.top = tmp.offsetTop
   if (ie4) {
    obj.width = obj.pixelWidth
    obj.height = obj.pixelHeight
   }
   else {
    obj.width = tmp.offsetWidth
    obj.height = tmp.offsetHeight
   }
   obj.obj = tmp
  }
  if (ie || ns) {
   obj.x = parseInt(obj.left)
   obj.y = parseInt(obj.top)
   obj.w = parseInt(obj.width)
   obj.h = parseInt(obj.height)
   return obj
  }
 }

 function existslayer(id) {
  if (ns) {
   if (!document.layers) return false
   if (!document.layers[id]) return false
  }
  else if (ie) {
   if (!document.all[id]) {
    return false
   }
  }
  return true
 }

 function createlayer(id,nestref,left,top,width,height,content,bgColor,visible,zIndex) {
  if (ns) {
   if (nestref) {
    var lyr = eval("document."+nestref+".document."+id+" = new Layer(width, document."+nestref+")")
   }
   else {
    if (!document.layers) return;
    var lyr = document.layers[id] = new Layer(width)
    eval("document."+id+" = lyr")
   }
   lyr.name = id
   lyr.left = left
   lyr.top = top
   if (height!=null) lyr.clip.height = height
   if (bgColor!=null) lyr.bgColor = bgColor
   if (visible!=null) lyr.visibility = (visible)? 'show' : 'hide'
   if (zIndex!=null) lyr.zIndex = zIndex
   if (content) {
    lyr.document.open()
    lyr.document.write(content)
    lyr.document.close()
   }
  }
  else if (ie) {
   var str = '\n<DIV id='+id+' style="position:absolute; left:'+left+'; top:'+top+'; width:'+width
   if (height!=null) {
    str += '; height:'+height
    str += '; clip:rect(0,'+width+','+height+',0)'
   }
   if (bgColor!=null) str += '; background-color:'+bgColor
   if (zIndex!=null) str += '; z-index:'+zIndex
   if (visible!=null) str += '; visibility:'+((visible)? 'visible' : 'hidden')
   str += ';">'+((content)?content:'')+'</DIV>'
   if (nestref) {
    index = nestref.lastIndexOf(".")
    var nestlyr = (index != -1)? nestref.substr(index+1) : nestref
    document.all[nestlyr].insertAdjacentHTML("BeforeEnd",str);
   }
   else {
    document.body.insertAdjacentHTML("BeforeEnd",str)
   }
  }
 }

 function writelayer(id,parent,text) {
  if (ns) {
   var lay = (parent)? eval('document.'+parent+'.document.'+id+'.document') : document.layers[id].document
   lay.open()
   lay.write(text)
   lay.close()
  }
  else if (ie) document.all[id].innerHTML = text
 }

 function moveto(obj,x,y) {
  if (ie || ns) {
   obj.x = x
   obj.y = y
   obj.left = obj.x
   obj.top = obj.y
  }
  if (ie) {
   obj.pixelLeft = obj.x
   obj.pixelTop = obj.y
  }
 }

 function sizeto(obj,w,h) {
  if (!obj) return
  obj.w = w
  obj.h = h
  obj.width = obj.w
  obj.height = obj.h
  obj.clip.right = obj.w
  obj.clip.bottom = obj.h
  if (ie) {
   obj.pixelWidth = obj.w
   obj.pixelHeight = obj.h
   obj.clip = 'rect(0px '+w+'px '+h+'px 0px)'
  }
 }

 function show(obj) {
  if (ns) obj.visibility = "show"
  else if (ie) obj.visibility = "visible"
 }

 function hide(obj) {
  if (ns) obj.visibility = "hide"
  else if (ie) obj.visibility = "hidden"
 }

 function inrect(obj,x,y,feather) {
  feather = feather || 0
  return (x>=obj.x-feather && x<=obj.x+obj.w+feather &&
          y>=obj.y-feather && y<=obj.y+obj.h+feather)
 }

 function makearray()
 {
  this.length = makearray.arguments.length
  for (var i = 0; i < this.length; i++)
   this[i] = makearray.arguments[i]
 }

 function image_left(name) {
  var x, obj, img, i
  if (!document.images) return -1
  img = document.images[name]
  if (!img) return -1
  if (img.container != null)
    if (img.container.pageX) {
      return img.container.pageX + img.x
    }
  else
    return img.x
  x = 0; i = 0
  obj = img
  while (obj.offsetParent != null) {
    x += obj.offsetLeft
    if (obj.offsetLeft && i) x += 1
    i = 1-i
    obj = obj.offsetParent
  }
  x += obj.offsetLeft
  return x
 }

 function image_top(name) {
  var y, obj, img, i
  if (!document.images) return -1
  img = document.images[name]
  if (!img) return -1
  if (img.container != null)
    if (img.container.pageY) {
      return img.container.pageY + img.y
    }
  else
    return img.y
  y = 0; i = 0
  obj = img
  while (obj.offsetParent != null) {
    y += obj.offsetTop
    if (obj.offsetTop && i) y += 1
    i = 1-i
    obj = obj.offsetParent
  }
  y += obj.offsetTop
  return y
 }

 function preload(imgObj,imgSrc) {
  if (document.images) {
   eval(imgObj+' = new Image()')
   eval(imgObj+'.src = "'+imgSrc+'"')
  }
 }
