var timeAtStartup;
var windowWidth = -1;
var windowHeight = -1;
var outText = '';
var BOTTOM_MARGIN = 10;
var RIGHT_MARGIN = 10;

function el(e) { return document.getElementById(e); }


function resize(flag) {
  var width = 0;
  var height = 0;

  if (!window.innerWidth) {
    if (document.documentElement.clientWidth != 0) {
      width = document.documentElement.clientWidth;
      height = document.documentElement.clientHeight;
    } else {
      width = document.body.clientWidth;
      height = document.body.clientHeight;
    }
  } else {
    width = window.innerWidth;
    height = window.innerHeight;
  }

  windowWidth = width;
  windowHeight = height;

  if(flag == 'all')	{
	stretchToBottom(el('bookArea'));
	//stretchToRight(el('bookArea'));
	stretchToBottom(el('map3d_container'));
	stretchToRight(el('map3d_container'));
  }
  else if(flag == 'vertical')	{
	stretchToBottom(el('bookArea'));	
	stretchToBottom(el('map3d_container'));  
  }
  else if(flag == 'horizontal')	{
	stretchToRight(el('map3d_container'));
  }

}

function getPosition(object) {
  var left = object.offsetLeft;
  var top = object.offsetTop;
  object = object.offsetParent;
  while (object) {    
    left += object.offsetLeft;
    top += object.offsetTop;
    object = object.offsetParent;
  }
  return [left, top];
}

function stretchToBottom(object) {
  var position = getPosition(object);
  var newHeight = windowHeight - position[1] - BOTTOM_MARGIN;
  if (newHeight > 0) {
    object.style.height = newHeight + 'px';
  }
}

function stretchToRight(object) {
  var position = getPosition(object);
  var newWidth = windowWidth - position[0] - RIGHT_MARGIN;
  if (newWidth > 0) {
    object.style.width = newWidth + 'px';
  }
}