
/*
returns browser width / height
usage: 
  var brow = new BrowserWindowSize;
  alert('width=' + brow.Width + '\nheight=' + brow.Height);
*/
function BrowserWindowSize(){
  this.Width = 0;
  this.Height = 0;
  //not-ie
  if( typeof(window.innerWidth ) == 'number' ) {
    this.Width = window.innerWidth;
    this.Height = window.innerHeight;
  //ie 6+ in (standards compliant mode)
  }else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)){
    this.Width = document.documentElement.clientWidth;
    this.Height = document.documentElement.clientHeight;
  //ie 4
  }else if(document.body && ( document.body.clientWidth || document.body.clientHeight)){
    this.Width = document.body.clientWidth;
    this.Height = document.body.clientHeight;
  }
}

/*
returns width / height within confines of the browser size, also supports a margin
usage: 
  var brow = new MaxWindowSize(200, 300, 20);
  alert('width=' + brow.Width + '\nheight=' + brow.Height);
*/
function MaxWindowSize(maxWidth, maxHeight, margin){
  var brow = new BrowserWindowSize;
  if(margin==null){margin = 20;}
  if(maxHeight==null){maxHeight = brow.Height;}
  if(maxWidth==null){maxWidth = brow.Width;}
  this.Width = (brow.Width < maxWidth ? brow.Width : maxWidth);
  this.Height = (brow.Height < maxHeight ? brow.Height : maxHeight);
  //adjust for margins
  if((+(this.Height) + (margin*2)) > brow.Height){
    this.Height = (+(brow.Height) - (margin*2));
  }
  if((+(this.Width) + (margin*2)) > brow.Width){
    this.Width = (+(brow.Width) - (margin*2));
  }

}