
function initUI(){
  isDOM = (document.getElementById) ? true : false;
  isOpera = isOpera5 = window.opera && isDOM;
  isOpera6 = isOpera && window.print;
  isOpera7 = isOpera && navigator.userAgent.indexOf("Opera 7") > 0 || navigator.userAgent.indexOf("Opera/7") >= 0;
  isMSIE = isIE = document.all && document.all.item && !isOpera;
  isIE4 = isIE && !isDOM;
  isNC = navigator.appName == "Netscape";
  isNC4 = isNC && !isDOM;
  isNC6 = isMozilla = isNC && isDOM;

  if(!isDOM && !isNC && !isMSIE && !isOpera){
    flUI = false;
    return false;
  }

  pageLeft = 0;
  pageTop = 0;

  UI_imagePreloaderCount = 0;
  UI_imagePreloaderArray = new Array();

  UI_imageRef = "document.images[\"";
  UI_imagePostfix = "\"]";
  UI_styleSwitch = ".style";
  UI_layerPostfix = "\"]";

  if(isNC4){
    UI_layerRef = "document.layers[\"";
    UI_styleSwitch = "";
  }

  if(isMSIE){
    UI_layerRef = "document.all[\"";
  }

  if(isDOM){
    UI_layerRef = "document.getElementById(\"";
    UI_layerPostfix = "\")";
  }

  flUI = true;
  return true;
}

initUI();

function getWindowLeft(wnd) {
  if(!wnd) wnd = self;
  if(isMSIE || isOpera7) return wnd.screenLeft;
  if(isNC || isOpera) return wnd.screenX;
}

function getWindowTop(wnd) {
  if(!wnd) wnd = self;
  if(isMSIE || isOpera7) return wnd.screenTop;
  if(isNC || isOpera) return wnd.screenY;
}

function getWindowWidth(wnd) {
  if(!wnd) wnd = self;
  if(isMSIE) return wnd.document.body.clientWidth;
  if(isNC || isOpera) return wnd.innerWidth;
}

function getWindowHeight(wnd) {
  if(!wnd) wnd = self;
  if(isMSIE) return wnd.document.documentElement.clientHeight;
  if(isNC || isOpera) return wnd.innerHeight;
}

function getDocumentWidth(wnd) {
  if(!wnd) wnd = self;
  var doc = wnd.document;
  if(isMSIE || isOpera7) return doc.documentElement.scrollWidth;
  if(isNC) return doc.width;
  if(isOpera5) return doc.body.style.pixelWidth;
}

function getDocumentHeight(wnd) {
  if(!wnd) wnd = self;
  var doc = wnd.document;
  if(isMSIE || isOpera7) return doc.body.scrollHeight;
  if(isNC) return doc.height;
  if(isOpera5) return doc.body.style.pixelHeight;
}

function getScrollX(wnd) {
  if(!wnd) wnd = self;
  if(isMSIE || isOpera7) return wnd.document.body.scrollLeft;
  if(isNC || isOpera5) return wnd.pageXOffset;
}

function getScrollY(wnd) {
  if(!wnd) wnd= self;
  if(isMSIE || isOpera7) return wnd.document.documentElement.scrollTop;
  if(isNC || isOpera5) return wnd.pageYOffset;
}

function preloadImage(imageFile){
  UI_imagePreloaderArray[UI_imagePreloaderCount] = new Image();
  UI_imagePreloaderArray[UI_imagePreloaderCount++].src = imageFile;
}

var UI_LAYER = 0;
var UI_IMAGE = 1;

function UI_findObject(what,where,type) {
  var i, j, l, s;
  var len = eval(where+".length");
  for(j = 0; j < len; j++) {
    s = where + "[" + j + "].document.layers";
    if(type == UI_LAYER) {
      l = s + "[\"" + what + "\"]";
    }
    if(type == UI_IMAGE) {
      i = where + "[" + j + "].document.images";
      l = i + "[\"" + what + "\"]";
    }
    if(eval(l)) return l;
    l = UI_findObject(what, s, type);
    if(l != "null") return l;
  }
  return "null";
}

function UI_getObjectPath(name, parent, type) {
  var l = ((parent && isNC4) ? (parent + ".") : ("")) + ((type == UI_LAYER) ? UI_layerRef : UI_imageRef) + name + ((type == UI_LAYER) ? UI_layerPostfix : UI_imagePostfix);
  if(eval(l)) return l;
  if(!isNC4) {
    return l;
  }
	else {
    return UI_findObject(name, "document.layers", type);
  }
}

function layer(name) {
  return new objUI(name, null);
}

function layerFrom(name, parent) {
  if(parent.indexOf("document.") < 0) parent = layer(parent).path;
  return new objUI(name, parent);
}

function image(name) {
  return new imgUI(name, null);
}

function imageFrom(name, parent) {
  if(parent.indexOf("document.") < 0) parent = layer(parent).path;
  return new imgUI(name, parent);
}

function objUI(name, parent) {
  this.path = UI_getObjectPath(name,parent,UI_LAYER);
  this.object = eval(this.path);
  if(!this.object) return;
  this.style = this.css = eval(this.path + UI_styleSwitch);
}

OUI = objUI.prototype;

OUI.isExist = OUI.exists = function() {
  return (this.object) ? true : false;
}

function UI_getPageOffset(o){ 
  var UI_left = 0;
  var UI_top = 0;
  do {
    UI_left += o.offsetLeft;
    UI_top += o.offsetTop;
  } while(o = o.offsetParent);
  return [UI_left, UI_top];
}

OUI.getLeft = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera) return o.offsetLeft - pageLeft;
  if(isNC4) return o.x - pageLeft;
}

OUI.getTop = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera) return o.offsetTop - pageTop;
  if(isNC4) return o.y - pageTop;
}

OUI.getAbsoluteLeft = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera) return UI_getPageOffset(o)[0] - pageLeft;
  if(isNC4) return o.pageX - pageLeft;
}

OUI.getAbsoluteTop = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera) return UI_getPageOffset(o)[1] - pageTop;
  if(isNC4) return o.pageY - pageTop;
}

OUI.getWidth = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera7) return o.offsetWidth;
  if(isOpera5) return this.css.pixelWidth;
  if(isNC4) return o.document.width;
}

OUI.getHeight = function() {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera7) return o.offsetHeight;
  if(isOpera5) return this.css.pixelHeight;
  if(isNC4) return o.document.height;
}

OUI.getZIndex = function() {
  return this.css.zIndex;
}

OUI.setLeft = OUI.moveX = function(x) {
  x += pageLeft;
  if(isOpera) {
    this.css.pixelLeft = x;
  }
	else if(isNC4) {
    this.object.x = x;
  }
	else {
    this.css.left = x;
  }
}

OUI.setTop = OUI.moveY = function(y) {
  y += pageTop;
  if(isOpera) {
    this.css.pixelTop = y;
  }
	else if(isNC4) {
    this.object.y = y;
  }
	else {
    this.css.top = y;
  }
}

OUI.moveTo = OUI.move = function(x, y) {
  this.setLeft(x);
  this.setTop(y);
}

OUI.moveBy = function(x, y) {
  this.moveTo(this.getLeft() + x, this.getTop() + y)
}

OUI.setZIndex = OUI.moveZ = function(z) {
  this.css.zIndex = z;
}

OUI.setVisibility = function(v) {
  this.css.visibility = (v) ? (isNC4 ? "show" : "visible") : (isNC4 ? "hide" : "hidden");
}

OUI.show = function() {
  this.setVisibility(true);
}

OUI.hide = function() {
  this.setVisibility(false);
}

OUI.isVisible = OUI.getVisibility = function() {
  return (this.css.visibility.toLowerCase().charAt(0) == 'h') ? false : true;
}

OUI.setBgColor = function(c) {
  if(isMSIE || isNC6 || isOpera7) {
    this.css.backgroundColor = c;
  }
	else if(isOpera5) {
    this.css.background = c;
  }
	else if(isNC4) {
    this.css.bgColor = c;
  }
}

OUI.setBgImage = function(url) {
  if(isMSIE || isNC6 || isOpera6) {
    this.css.backgroundImage = "url(" + url + ")";
  }
	else if(isNC4) {
    this.css.background.src = url;
  }
}

OUI.setClip = OUI.clip = function(top, right, bottom, left) {
  if(isMSIE || isNC6 || isOpera7) {
    this.css.clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";
  }
	else if(isNC4) {
    var c = this.css.clip;
    c.top = top;
    c.right = right;
    c.bottom = bottom;
    c.left = left;
  }
}

OUI.scrollTo = OUI.scroll = function(windowLeft, windowTop, windowWidth, windowHeight, scrollX, scrollY) {
  if(scrollX > this.getWidth() - windowWidth) scrollX = this.getWidth() - windowWidth;
  if(scrollY > this.getHeight() - windowHeight) scrollY = this.getHeight() - windowHeight;
  if(scrollX < 0) scrollX = 0;
  if(scrollY < 0) scrollY = 0;
  var top = 0;
  var right = windowWidth;
  var bottom = windowHeight;
  var left = 0;
  left = left + scrollX;
  right = right + scrollX;
  top = top + scrollY;
  bottom = bottom + scrollY;
  this.moveTo(windowLeft - scrollX, windowTop - scrollY);
  this.setClip(top, right, bottom, left);
}

OUI.scrollBy = OUI.scrollByOffset = function(windowLeft, windowTop, windowWidth, windowHeight, scrollX, scrollY) {
  var X=-parseInt(this.css.left) + windowLeft + scrollX;
  var Y=-parseInt(this.css.top) + windowTop + scrollY;
  this.scroll(windowLeft, windowTop, windowWidth, windowHeight, X, Y);
}

OUI.scrollByPercentage = function(windowLeft, windowTop, windowWidth, windowHeight, scrollX, scrollY) {
  var X = (this.getWidth() - windowWidth) * scrollX / 100;
  var Y = (this.getHeight() - windowHeight) * scrollY / 100;
  this.scroll(windowLeft, windowTop, windowWidth, windowHeight, X, Y);
}

OUI.write = function(str) {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera7) {
    o.innerHTML = str;
  }
	else if(isNC4) {
    var d = o.document;
    d.open();
    d.write(str);
    d.close();
  }
}

OUI.add = function(str) {
  var o = this.object;
  if(isMSIE || isNC6 || isOpera7) {
    o.innerHTML += str;
  }
	else if(isNC4) {
    var d = o.document;
    d.write(str);
  }
}

IUI = imgUI.prototype;

function imgUI(name) {
  this.path = UI_getObjectPath(name, false, UI_IMAGE);
  this.object = eval(this.path);
}

IUI.isExist = IUI.exists = function() {
  return (this.object) ? true : false;
}

IUI.getSrc = IUI.src = function() {
  return this.object.src;
}

IUI.setSrc = IUI.load = function(url) {
  this.object.src = url;
}