﻿//
// Pos class
//
var Pos = Class.create();

Pos.prototype = 
{
    initialize: function(x, y)
    {
        this.x = x;
        this.y = y;
    }
}

Element.addMethods({

    // Returns the absolute position of the element
    getPosition: function(element)
    {
        if (element.style.position == 'absolute') return new Pos(element.style.left.substring(0, element.style.left.length - 2), element.style.top.substring(0, element.style.top.length - 2));

        var x = 0;
        var y = 0;
        if (element.offsetParent) {
            x = element.offsetLeft;
            y = element.offsetTop;
            while (element = element.offsetParent) {
                if (element.style.position == 'absolute')
                {
                    x += parseInt(element.style.left.substring(0, element.style.left.length - 2));
                    y += parseInt(element.style.top.substring(0, element.style.top.length - 2));
                    break;
                }
                else
                {
                    x += element.offsetLeft;
                    y += element.offsetTop;
                }
            }
        }
        return new Pos(x, y);
    },
    
    // Sets the absolute position of the element
    setPosition: function(element, pos)
    {
        element.style.position = 'absolute';
        element.style.left = pos.x + 'px';
        element.style.top = pos.y + 'px';
        return element;
    },
    
    // returns the position for the element in the center of the window
    getCenterPosition: function(element)
    {
        var dim = element.getDimensions();
        return new Pos((document.body.offsetWidth - dim.width) / 2, (document.body.offsetHeight - dim.height) / 2);
    }

});



function GetWindowSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return {width: myWidth, height: myHeight};
}
