if (!intraxxion)
  intraxxion = {};

/*
 * Usage:
 *
 * window.onload=initpagesize;
 * window.onresize=recalcpagesize;
 *
 * var pagesizer = null;
 *
 * function initpagesize() {
 *   pagesizer = new intraxxion.webpageresizer({'leftheight': -20});
 *   pagesizer.initialize();
 *   pagesizer.setheight();
 * }
 * function recalcpagesize() {
 *   pagesizer.initialize();
 *   pagesizer.setheight();
 * }
 * 
 */

intraxxion.webpagesizer = function(options) {
  this.container = document.getElementById('container');
  this.left = document.getElementById('left');
  this.right = document.getElementById('right');
  this.main = document.getElementById('main');
  this.maincontent = document.getElementById('maincontent');
  this.content = document.getElementById('content');
  this.top = document.getElementById('top');
  this.options = options;
};

intraxxion.webpagesizer.prototype = {
  "initialize":function() {
    this.container.style.height = '100%';
    this.content.style.height = 'auto';
    this.left.style.height = 'auto';
    this.right.style.height = 'auto';
    this.main.style.height = 'auto';
    this.bodyheight = this.container.offsetHeight;
    this.bodycontentheight = this.bodyheight - this.top.offsetHeight;
//    bh = document.getElementsByTagName('body')[0].offsetHeight;
//    hh = document.getElementsByTagName('html')[0].offsetHeight;
  },
  "numericorder": function(a, b) { 
    return a -b;
  },
  "setheight":function() {
    this.setcontainerheight();
    this.setcontentheight();
    this.setmaincontentheight();
    this.setleftheight();
    this.setrightheight();
  },
  "setcontainerheight":function() {
    this.container.style.height = this.maxheight() + 'px';
  },
  "setmaincontentheight":function() {
    if (this.bodycontentheight >= this.maincontent.offsetHeight) {
      this.maincontent.style.height = this.bodycontentheight;
    } else {
			extra = 0
  		try {
    		extra = this.options.maincontentheight;
    	} catch(e) {}
     this.maincontent.style.height = parseInt(this.content.style.height) - extra +'px';
    }                                
    this.main.style.height = this.maincontent.style.height;
  },
  "setcontentheight":function() {
    this.content.style.height = this.bodycontentheight + 'px';
    if (this.main.offsetHeight > this.content.offsetHeight) {
			extra = 0
  		try {
    		extra = this.options.maincontentheight;
    	} catch(e) {}
      this.content.style.height = this.maxheight() + extra + 'px';
    }
  },
  "setleftheight":function() {
  	try {
	    this.left.style.height = this.content.offsetHeight + this.options.leftheight +'px';
    } catch(e) {}
  },
  "setrightheight":function() {
		extra = 0
  	try {
    	extra = this.options.rightheight;
    } catch(e) {}
    this.right.style.height = this.content.offsetHeight + extra +'px';
  },
  "maxheight":function() {
	  my_heights = new Array(this.bodycontentheight,
	                         (this.left.offsetHeight == null) ? 0 : this.left.offsetHeight,
	            		         (this.maincontent.offsetHeight == null) ? 0 : this. maincontent.offsetHeight,
	  		                   (this.right.offsetHeight == null) ? 0 : this.right.offsetHeight);
	  my_heights.sort(this.numericorder);
	  my_heights.reverse();
	  return(my_heights[0]);  
  }
};

