if (!_sZIndex)
var _sZIndex = 0;
if (!_sID)
var _sID = 0;
var _inPrototype = false;

function sExtend(fConstr, fSuperConstr, sName){	
  _inPrototype = true;
  var p = fConstr.prototype = new fSuperConstr;	
  if (sName){
    p.oName = sName;	
  }	
  p.constructor = fConstr;	
  _inPrototype = false;	
  return p;
}

function clearElement(element){
  if (element)
    element.parentNode.removeChild(element);
}
function sWindows(){}

sWindows.scrollLeft = function(){
  return (sBrowser.ie) ? document.body.scrollLeft : window.pageXOffset;
}
sWindows.scrollTop = function(){
  return (sBrowser.ie) ? document.body.scrollTop : window.pageYOffset;
}
sWindows.scrollWidth = function(){
  return document.body.scrollWidth;
}
sWindows.scrollHeight = function(){
  return document.body.scrollWidth;
}

sWindows.innerWidth = function(){
  return document.body.clientWidth;
}
sWindows.innerHeight = function(){
  return document.body.clientHeight;
}

sWindows.width = function(){
  return screen.width;
}
sWindows.height = function(){
  return screen.height;
}
function sBrowser(){
  var ua = navigator.userAgent;	
  var _ie = /msie/i.test( ua );	
  var _moz = navigator.product == "Gecko";	
  var _platform = navigator.platform;	
  var _version = "";	
  var _hta = "";	
  if ( _moz ){
    /rv\:([^\);]+)(\)|;)/.test( ua );		
    _version = RegExp.$1;
    _hta = false;	
  }	else{		
    /MSIE\s+([^\);]+)(\)|;)/.test( ua );		
    _version = RegExp.$1;		
    _hta = !window.external;	
  }	;	
  
  this.getIE = function(){
    return _ie;
  }
  this.getMoz = function(){
    return _moz;
  }
  this.getHta = function(){
    return _hta;
  }
  this.getVer = function(){
    return _version;
  }
}

var sb = new sBrowser;

sBrowser.ie = sb.getIE();
sBrowser.moz = sb.getMoz();
sBrowser.ver = sb.getVer();
sBrowser.hta = sb.getHta();

function SElement(p){
  this._DOC = document;
  this._top = 0;
  this._left = 0;
  this._bottom = 0;
  this._right = 0;
  this._position = p ? p : "absolute";
  this._childs = new Array();
  this._parent = false;
  this._displayed = false;
  this.create();
  this.setPosition(this._position);
  this.setId(this.oName+"-"+_sID++);
  this._width = this._element.offsetWidth;
  this._height = this._element.offsetHeight;
  this._opacity = 100;
}

_p = SElement.prototype;
_p.__this = function(){ return this; }
_p.toString = function(){ 
  return "[object "+this.oName+"]"; 
}
_p.tagName = "div";
_p.oType = function (){ return "sooltObject" }
_p.sooltObject = true;
_p.addForDoc = function(){ 
  this._DOC.body.appendChild(this._element); 
  this._displayed = true;
  this.doEvent("displayed"); 
}
_p._dispalyed = function(){}
_p.getDisplayed = function(){ 
  return this._displayed; 
}
_p.removeForDoc = function(){ 
  if(this._element.parentNode)
    this._element.parentNode.removeChild(this._element);
  this._displayed = false; 
}
_p.create = function(){
  this._element = this._DOC.createElement(this.tagName);
  this._event = new sEvent(this._element);
}
_p.setAttribute = function(attr, v){
  this._element.setAttribute(attr, v);
}
_p.getAttribute = function(v){ 
  return this._element.getAttribute(v);
}
_p.setId = function(id){ 
  this.setAttribute("id", id); 
}
_p.getId = function(){ 
  return this.getAttribute("id"); 
}
_p.setTitle = function(v){ 
  this.setAttribute("title", v); 
}
_p.getTitle = function(){ 
  return this.getAttribute("title"); 
}
_p.setTop = function(t){
  this._element.style.top = t+"px";
  this._top = t;
}
_p.setBottom = function(t){
  this._element.style.bottom = t+"px";
  this._bottom = t;
}
_p.setLeft = function(l){
  this._element.style.left = l+"px";
  this._left = l;
}
_p.setRight = function(l){
  this._element.style.right = l+"px";
  this._right = l;
}
_p.setWidth = function(w){
  this._element.style.width = w+"px";
  this._width = w;
}
_p.setHeight = function(h){
  this._element.style.height = h+"px";
  this._height = h;
}
_p.setMaxHeight = function(h){
  if (sBrowser.ie){
    this.setDisplay("block");
    this.setHeight(h);
  }
  else{
    this._element.style.minHeight = h+"px";
    this._height = h;
  }
}
_p.setMinHeight = function(h){
  if (sBrowser.ie){
    this.setDisplay("block");
    this.setHeight(h);
  }else{
    this._element.style.minHeight = h+"px";
    this._height = h;
  }
}
_p.getTop = function(){ 
  return parseInt(this._element.style.top); 
}

_p.getBottom = function(){ 
  return parseInt(this._element.style.bottom); 
}

_p.getLeft = function(){  
  return parseInt(this._element.style.left); 
}

_p.getRight = function(){ 
  return parseInt(this._element.style.right);
}

_p.getWidth = function(){ 
  return parseInt(this._element.style.width) || this._element.offsetWidth; 
}

_p.getHeight = function(){ 
  return parseInt(this._element.style.height) || this._element.clientHeight; 
}

_p.setCssFloat = function(v){
  if (typeof this._element.style.cssFloat == "string" )
    this._element.style.cssFloat = v;
  else this._element.style.styleFloat = v;
}

_p.setBounds = function(width, height, top, left){
  this.setWidth(width);
  this.setHeight(height);
  this.setTop(top);
  this.setLeft(left);
}
_p.getBounds = function(){
  return {
    width: this.getWidth(), 
    height: this.getHeight(),
    top: this.getTop(), 
    left: this.getLeft()
  };
}
_p.setSize = function(w, h){ 
  this.setWidth(w); 
  this.setHeight(h); 
}

_p.setPos = function(t, l){
  this.setTop(t);
  this.setLeft(l);
}

_p.setZIndex = function(zInd){ 
  this._element.style.zIndex = zInd; 
}
_p.getZIndex = function(){ 
  return this._element.style.zIndex; 
}
_p.setPosition = function(pos){
  if ( (pos == "static") || (pos == "relative") || (pos == "absolute") || (pos == "fixed") )
    this._element.style.position = pos;
  else this._element.style.position = "static";
}
_p.setPadding = function(v){ 
  this._element.style.padding = v; 
}
_p.setVisible = function(v){ 
  this._element.style.visibility = v ? "visible" : "hidden";
  this._event.doEvent (this._element.style.visibility);
}
_p.setDisplay = function( v ){ 
  this._element.style.display = v; 
}
_p.getDisplay = function( v ){ return this._element.style.display; }
_p.setCursor = function( v ){ this._element.style.cursor = v; }
_p.getCursor = function( v ){ return this._element.style.cursor; }

_p.setOverflow = function(v){
  if ( (v == "visible") || (v == "hidden") || (v == "scroll") || (v == "auto") )
    this._element.style.overflow = v;
  else this._element.style.overflow = "auto";
}
_p.setCssClassName = function(v){ this._element.className = v; }  
_p.getCssClassName = function(){ return this._element.className; }
_p.setVerticalAlign = function(v){ this._element.style.verticalAlign = v; }
_p.setAlign = function(v){ this._element.style.textAlign = v; }
_p.getAlign = function(v){ return this._element.style.textAlign; }
_p.setBackgroundColor = function(v){ this._element.style.backgroundColor = v;}
_p.getBackGroundColor = function(){ return this._element.style.backgroundColor;}
_p.setBackground = function(v){ this._element.style.background = v; }
_p.getBackground = function(){ return this._element.style.background; }
_p.setBorder = function(v){ this._element.style.border = v; }
_p.getBorder = function(v){ return this._element.style.border; }
_p.setPaddingTop = function(v){ this._element.style.paddingTop = v; }
_p.setPaddingBottom = function(v){ this._element.style.paddingBottom = v; }
_p.setPaddingLeft = function(v){ this._element.style.paddingLeft = v; }
_p.setPaddingRight = function(v){ this._element.style.paddingRight = v; }
_p.setMargin = function(v){ this._element.style.margin = v; }
_p.setMarginTop = function(v){ this._element.style.marginTop = v; }
_p.setMarginBottom = function(v){ this._element.style.marginBottom = v; }
_p.setMarginLeft = function(v){ this._element.style.marginLeft = v; }
_p.setMarginRight = function(v){ this._element.style.marginRight = v; }
_p.setLeftBorder = function(v){ this._element.style.borderLeft = v; }
_p.setRightBorder = function(v){ this._element.style.borderRight = v; }
_p.setTopBorder = function(v){ this._element.style.borderTop = v; }
_p.setBorderBottom = function(v){ this._element.style.borderBottom = v; }
_p.getLeftBorder = function(){ return this._element.style.borderLeft; }
_p.getRightBorder = function(){ return this._element.style.borderRight; }
_p.getTopBorder = function(){ return this._element.style.borderTop; }
_p.getBorderBottom = function(){ return this._element.style.borderBottom; }
_p.setColor = function(v){ this._element.style.color = v;}
_p.getColor = function(v){ return this._element.style.color;}

_p.setOpacity = function(o){
  this._opacity = o;
  if (sBrowser.moz)
    this._element.style.opacity = (o/100);
  else if (sBrowser.ie)
    this._element.style.filter = "alpha(opacity="+o+");";
}
_p.getOpacity = function(){ return this._opacity }

_p.inheritLayout = function(){
  this._element.style.top = "0px";
  this._element.style.left = "0px";
  this.setWidth(this._element.parentNode.offsetWidth);
  this.setHeight(this._element.parentNode.clientHeight);
  if (this._element.parentNode.scrollWidth > this._element.parentNode.offsetWidth){
    this.setWidth(this._element.parentNode.scrollWidth);
  }
  if (this._element.parentNode.scrollHeight > this._element.parentNode.offsetHeight){
    this.setHeight(this._element.parentNode.scrollHeight);
  }
}
_p.setSizeForWindow = function(){ 
  this.inheritLayout(); 
}
_p.setInheritPosition = function(h, v){
    switch (h){
      case "left":
        this.setLeft(0);
        break;
      case "center":
        if (this._width < this._element.parentNode.offsetWidth){
          this.setLeft((this._element.parentNode.offsetWidth/2)-(this._width/2)+this._element.parentNode.scrollLeft);
        }
        else this.setLeft(0);
        break;
      case "right":
        this.setRight(0);
        break;
    }
    switch (v){
      case "top":
        this.setTop(0);
        break;
      case "center":
        //alert(this._element.parentNode.clientHeight);
        if (this._height < this._element.parentNode.clientHeight)
          this.setTop( (this._element.parentNode.clientHeight/2)-(this._height/2)+this._element.parentNode.scrollTop);
        else this.setTop(0);
        break;
      case "bottom":
        this.setBottom(0);
        break;
    }
}

_p.dispose = function(){
  _p = null;
}

_p.getElement = function(){ 
  return this._element; 
}
_p.addEvent = function ( action, onEvent ){ this._event.addEvent(action, onEvent); }
_p.doEvent = function(action){ this._event.doEvent(action); }
_p.removeEvent = function(action, onEvent){ this._event.removeEvent(action, onEvent); }
_p.clearEvent = function(action){ this._event.clearEvent(action); }

function sComponent(p){
  SElement.call(this);
  
  if (p) this.setPosition(p);
}

_c = sExtend(sComponent, SElement, "sComponent");
_c.tagName = "div";
_c.getPane = function(){
  return this._element
} ;

_c.add = function(obj){
  if (obj._element){
    this.getPane().appendChild( obj.getElement() );
    obj._parent = this;
    obj._displayed = true;
    obj.doEvent("displayed");
    this._childs[this._childs.length] = obj;
  }
}

_c._add = function(obj){
  if (obj._element){
    this.getElement().appendChild( obj.getElement() );
    obj._parent = this;
    obj._displayed = true;
    obj.doEvent("displayed");
    this._childs[this._childs.length] = obj;
  }
}

_c.removeChild = function(obj){
  var restChild = new Array();
  var remChild = false;
  if (this._childs.length)
    for (var i=0; i<this._childs.length; i++){
      if (this._childs[i] == obj){
        this._childs[i].removeForDoc();
        remChild = true;
      }
      else
        restChild[restChild.length] = this._childs[i];
    }this._childs = new Array;
  
  this._childs = restChild;
  return remChild;
}
_c.removeAll = function(){
  var remChild = false;
  if (this._childs.length)
    for (var i=0; i<this._childs.length; i++){
      this._childs[i].removeForDoc();
    }
  this._childs = new Array();
}
_c.addHtmlObject = function(obj){
  this._element.appendChild( obj );
  this._childs[this._childs.length] = obj;
}
_c.getParent = function(){ return this._parent }
_c.getChildren = function(){ return this._childs; }
_c.setContent = function(c){ this._element.innerHTML = c; }
_c.getContent = function(c){ return this._element.innerHTML; }
_c.deleteContent = function(){ this._element.innerHTML = ""; }
_c.setScrollLeft = function(v){ this._element.scrollLeft += v; };
_c.getScrollLeft = function(){ return this._element.scrollLeft; };
_c.setScrollTop = function(v){ this._element.scrollTop += v; };
_c.getScrollTop = function(){ return this._element.scrollTop; };

function createSElement(oElement){
  var _element = false;
  
  if (oElement.sooltObject)
    _element = oElement;
  else {
    if (typeof oElement == "string")
      if (document.getElementById(oElement))
        var oE = document.getElementById(oElement);
      else return false;
      
    _element = new sComponent();
    _element.getElement() = oE;
  }
  
  return _element;
}
