﻿if (!EC) var EC = new Object();

EC.DOM = new Object();

EC.DOM.getElement = function(e)
{
   if (e.substring)
      e = document.getElementById(e);

   if (!e)
      return e;

   if (e.ecInitialized)
      return e;

   e.ecInitialized = true;

   e.ecShow = function()   { this.style.display = ''; e._ecPosition(); }
   e.ecHide = function()   { this.style.display = 'none'; }
   e.ecParent = function() { return EC.DOM.getElement(this.parentNode); }

   e.ecFirstChild    = function() { return EC.DOM.getElement(this.firstChild); }
   e.ecFirstTagChild = function() 
   {
      for (var i = 0; i < this.childNodes.length; i++) {
         if (this.childNodes[i].nodeType == '1')
            return EC.DOM.getElement(this.childNodes[i]);
      }

      return null;
   }

   e._ecWidth = 0;
   e._ecHeight = 0;
   e._ecAbsTop = 0;
   e._ecAbsLeft = 0;

   e._ecPosition = function()
   {
      var obj = this;
      var x = y = 0;

      if (obj.offsetParent) {
         x = obj.offsetLeft
         y = obj.offsetTop
         while (obj = obj.offsetParent) {
            x += obj.offsetLeft
            y += obj.offsetTop
         }
      }

      e._ecAbsLeft = x;
      e._ecAbsTop = y;

      e._ecWidth = this.offsetWidth;
      e._ecHeight = this.offsetHeight;
   }

   e.ecWidth = function(width)
   { 
      if (width)
         this.style.width = width + 'px';

      return e._ecWidth;
   }

   e.ecHeight = function(height)
   { 
      if (height)
         this.style.height = height + 'px';

      return e._ecHeight;
   }

   e.ecAbsLeft = function() { return this._ecAbsLeft; }
   e.ecAbsTop  = function() { return this._ecAbsTop; }

   e.ecLeft = function(left)
   { 
      if (left)
         this.style.left = left + 'px';

      if (this.style.left == '') 
         return 0; 
      else 
         return parseInt(this.style.left);
   }

   e.ecTop = function(top)
   { 
      if (top || top == 0)
         this.style.top = top + 'px';

      if (this.style.top == '') 
         return 0; 
      else
         return parseInt(this.style.top);
   }

   e.ecMove = function(left, top)
   {
      this.ecLeft(left);
      this.ecTop(top);
   }

   e.ecCenter = function(left, top, width, height)
   {
      this.ecLeft(left + (width - this.ecWidth()) / 2);
      this.ecTop(top + (height - this.ecHeight()) / 2);
   }

   e.ecSize = function(width, height)
   {
      this.style.width = width + 'px';
      this.style.height = height + 'px';
   }

   e.ecScroll = function(h, v)
   {
      this.ecLeft(this.ecLeft() + h);
      this.ecTop(this.ecTop() + v);
   }

   e.ecScrollVertically = function(v, min, max)
   {
      v = this.ecTop() + v;
      if (v >= min && v <= max)
         this.ecTop(v);
   }

   e.ecCurrentStyle = function(style)
   {
      if (this.currentStyle)
         return this.currentStyle[style];

      if (window.getComputedStyle)
         return document.defaultView.getComputedStyle(this, null).getPropertyValue(style);
   }
   
   e.ecCurrentStyle = function(style)
   {
	   if (this.currentStyle)
		   return this.currentStyle[style];
	
	   if (window.getComputedStyle)
		   return document.defaultView.getComputedStyle(this, null).getPropertyValue(style);

	   return "";
   }

   e.ecClick = function()
   {
      if (this.click)
         this.click();
      else if (this.href)
         window.location = this.href;
   }

   e._ecPosition();

   return e;
}


EC.PageType = function() 
{
}

EC.PageType.prototype =
{
   width:  function()
   { 
      if (document.documentElement.offsetWidth > document.documentElement.scrollWidth)
         return document.documentElement.offsetWidth;
         
      return document.documentElement.scrollWidth;
   },

   height: function()
   { 
      if (document.documentElement.offsetHeight > document.documentElement.scrollHeight)
         return document.documentElement.offsetHeight;

      return document.documentElement.scrollHeight;
   },

   clientWidth:  function()
   { 
      if (self.innerWidth)
	      return self.innerWidth;
      
      if (document.documentElement && document.documentElement.clientWidth)
         return document.documentElement.clientWidth;

      if (document.body)
	      return document.body.clientWidth;
	      
	   return 0;
   },

   clientHeight: function() 
   { 
      if (self.innerHeight)
	      return self.innerHeight;
      
      if (document.documentElement && document.documentElement.clientHeight)
         return document.documentElement.clientHeight;

      if (document.body)
	      return document.body.clientHeight;
	      
	   return 0;
   },

   scrollTop: function()
   {
      if (self.pageYOffset)
         return self.pageYOffset;

      if (document.documentElement && document.documentElement.scrollTop)
         return document.documentElement.scrollTop;

      if (document.body)
         return document.body.scrollTop;
   },

   scrollLeft: function()
   {
      if (self.pageXOffset)
         return self.pageXOffset;

      if (document.documentElement && document.documentElement.scrollLeft)
         return document.documentElement.scrollLeft;

      if (document.body)
         return document.body.scrollLeft;
   }
}

EC.Page = new EC.PageType();
