var pageLeft
var pageTop

var layerRef
var styleSwitch=".style";
var bgColor

var imagePreloaderCount
var imagePreloaderArray

function StatusOff(){ return onText(""); }
function onText(str){ window.status = str; return true }

function isNetscape(){
  isDOM=(document.getElementById) ? true : false
  isNC=navigator.appName=="Netscape"
  if(isNC && isDOM) return true
  return false
}

function isIE() {
  isDOM=(document.getElementById) ? true : false
  isOpera=window.opera && isDOM
  if(document.all && document.all.item && !isOpera) return true
  return false
}

function isMSIE(){
  return isIE()
}

function isExplorer(){
  return isIE()
}

function getScrollX(){
 if(isNetscape()){
  return window.pageXOffset
 }
 if(isExplorer()){
  return document.body.scrollLeft
 }
}

function getScrollY(){
 if(isNetscape()){
  return window.pageYOffset
 }
 if(isExplorer()){
  return document.body.scrollTop
 }
}

function getDocumentWidth(){
  return window.width
}

function getDocumentHeight(){
  return window.height
}

function getWindowWidth(){
 if(isNetscape()){
  return window.innerWidth
 }
 if(isExplorer()){
  return document.body.clientWidth
 }
}

function getWindowHeight(){
 if(isNetscape()){
  return window.innerHeight
 }
 if(isExplorer()){
  return document.body.clientHeight
 }
}

function findLayer(where, what){
    var i,l
    for(i=0;i<eval(where+".length");i++){
      l=findLayer(where+"["+i+"].document.layers",what)
      if(l!="")return l
    }
    return ""
}

function getLayer(layerName){
  if(isExplorer()){
    if(eval("document.all[\""+layerName+"\"]")) {
		return "document.all[\""+layerName+"\"]"
	}
    return ""
  }
  if(isNetscape()){
    if(document.getElementById(layerName)){
		return "document.getElementById('"+layerName+"')"
	}
    return findLayer("document.layers",layerName)
  }
}

function setLayerProperty(layerName,property,value){
//	alert(getLayer(layerName)+styleSwitch+"."+property+"=\""+value+"\"");
  eval(getLayer(layerName)+styleSwitch+"."+property+"=\""+value+"\"")
}

function getLayerProperty(layerName,property){
  return eval(getLayer(layerName)+styleSwitch+"."+property)
}

function isLayerExists(layerName){
  return getLayer(layerName)!=""
}

function isLayerExist(layerName){
  return isLayerExists(layerName)
}

function getLayerWidth(layerName){
  if(isLayerExists(layerName)){
   if(isNetscape()){
    return eval(getLayer(layerName)+".document.width")
   }
   if(isExplorer()){
    return parseInt(eval(getLayer(layerName)+".scrollWidth"))
   }
  }
}

function getLayerHeight(layerName){
  if(isLayerExists(layerName)){
   if(isNetscape()){
    return eval(getLayer(layerName)+".document.height")
   }
   if(isExplorer()){
    return parseInt(eval(getLayer(layerName)+".scrollHeight"))
   }
  }
}

function getLayerLeft(layerName){
  if(isLayerExists(layerName)){
    return parseInt(getLayerProperty(layerName,"left"))-pageLeft
  }
  return 0
}

function getLayerTop(layerName){
  if(isLayerExists(layerName)){
    return parseInt(getLayerProperty(layerName,"top"))-pageTop
  }
  return 0
}

function getLayerZindex(layerName){
  if(isLayerExists(layerName)){
    return parseInt(getLayerProperty(layerName,".z-index"))
  }
  return 0
}

function getLayerZ(layerName){
  return getLayerZindex(layerName)
}

function isLayerVisible(layerName){
  if(isLayerExists(layerName)){
    if(getLayerProperty(layerName,"visibility").charAt(0)=="h"){
      return false
    }else{
      return true
    }
  }
}

function moveLayer(layerName,newx,newy){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"left",newx+pageLeft)
    setLayerProperty(layerName,"top",newy+pageTop)
  }
}
function moveLayerX(layerName,newx){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"left",newx+pageLeft)
  }
}
function moveLayerY(layerName,newy){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"top",newy+pageTop)
  }
}
function moveLayerZ(layerName,newz){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"zIndex",newz)
  }
}

function showLayer(layerName){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"visibility","visible")
  }
}
function hideLayer(layerName){
  if(isLayerExists(layerName)){
    setLayerProperty(layerName,"visibility","hidden")
  }
}

function clipLayer(layerName, top, right, bottom, left){
  if(isExplorer()){
    setLayerProperty(layerName,"clip","rect("+(top+1)+"px "+right+"px "+bottom+"px "+left+"px)")
  }

  if(isNetscape()){
    setLayerProperty(layerName,"clip.top",top)
    setLayerProperty(layerName,"clip.right",right)
    setLayerProperty(layerName,"clip.bottom",bottom)
    setLayerProperty(layerName,"clip.left",left)
  }
}

function scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){

  if(!isLayerExists(layerName))return
  if(scrollX<0)scrollX=0
  if(scrollY<0)scrollY=0
  if(scrollX>getLayerWidth(layerName)-windowWidth)scrollY=getLayerWidth(layerName)-windowWidth
  if(scrollY>getLayerHeight(layerName)-windowHeight)scrollY=getLayerHeight(layerName)-windowHeight

  var top=0
  var right=windowWidth
  var bottom=windowHeight
  var left=0

  left=left+scrollX
  right=right+scrollX

  top=top+scrollY
  bottom=bottom+scrollY

  moveLayer(layerName, windowLeft-scrollX, windowTop-scrollY)
  clipLayer(layerName, top, right, bottom, left)
}

function scrollLayerOffset(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){
  scrollX=getLayerLeft(layerName)-windowLeft+scrollX
  scrollY=getLayerTop(layerName)-windowTop+scrollY
  scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY)
}

function scrollLayerPercentage(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){
  scrollX=(getLayerWidth(layerName)-windowWidth)*scrollX/100
  scrollY=(getLayerHeight(layerName)-windowHeight)*scrollY/100
  scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY)
}

function getLayerContent(layerName) {
  if(isLayerExists(layerName)){
    if(isNetscape()){
	  return (document.layers[layerName].document);
	}
    if(isExplorer()){
      return (document.all[layerName].innerHTML);
    }
  }
}

function writeToLayer(layerName, str){
  if(isLayerExists(layerName)){
    if(isNetscape()){
      var area=document.layers[layerName].document
      area.open()
      area.write(str)
      area.close()
    }
    if(isExplorer()){
      document.all[layerName].innerHTML=str
    }
  }
}

function addToLayer(layerName, str){
  if(isLayerExists(layerName)){
    if(isNetscape()){
      var area=document.layers[layerName].document
      area.write(str)
    }
    if(isExplorer()){
      document.all[layerName].innerHTML+=str
    }
  }
}

function setImage(layerName,imageName,imageFile){
 if(isLayerExists(layerName)){
  eval(getLayer(layerName)+'.document.images["'+imageName+'"].src="'+imageFile+'"')
 }
}

function setBgColor(layerName,color){
 if(isLayerExists(layerName)){
  setLayerProperty(layerName,bgColor,color)
 }
}

function preloadImage(imageFile){
  imagePreloaderArray[imagePreloaderCount]=new Image()
  imagePreloaderArray[imagePreloaderCount++].src=imageFile
}

function initKLayers(){
  pageLeft=0
  pageTop=0
  imagePreloaderCount=0
  imagePreloaderArray=new Array()

  if(isNetscape()){
    layerRef="document.layers";
    styleSwitch=".style";
    bgColor="bgColor";
  }

  if(isExplorer()){
    layerRef="document.all"
    styleSwitch=".style"
    bgColor="backgroundColor"
  }
}

function getWindowWidth()
{
	if (document.all == null)
		return window.innerWidth;
	else
		return document.body.clientWidth;
}

function initLayers(){
  initKLayers()
}

initKLayers();
