
/// <summary>
/// resizes the content section
/// </summary>
function loadContentSection(){
	var contentsection = document.getElementById("contentsection");
	try{
		if(navigator.userAgent){
			var agentstring = navigator.userAgent;
			if (agentstring.indexOf("iPhone") != -1){
				contentsection.style.height = "";
				document.body.setAttribute("onresize","");
				return true;
			}
		}
	}catch(ex){}
	// get viewport size
	var minheight = 405;
	var size = getViewportSize();
	var elementpos = getElementPosition(contentsection);
	var tmpheight = size[1] - elementpos[1] - 20;
	if(tmpheight < minheight){tmpheight = minheight}
	contentsection.style.height = tmpheight + "px";
}

/// <summary>
/// Gets the position of an element, in
/// This case it refers to the surface
/// element of the viewer
/// </summary>

function getElementPosition(theElement){
	var positionX = 0;
	var positionY = 0;

	while(theElement != null){
		positionX += theElement.offsetLeft;
		positionY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
	return [positionX,positionY];
}

/// <summary>
/// adds a function to the onload event 
/// </summary>

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}

/// <summary>
/// finds out the size of the viewport 
/// </summary>
function getViewportSize()
{
  var size = [0,0];

  if (typeof window.innerWidth != 'undefined')
  {
    size = [
        window.innerWidth,
        window.innerHeight
    ];
  }
  else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth != 'undefined'
      && document.documentElement.clientWidth != 0)
  {
    size = [
        document.documentElement.clientWidth,
        document.documentElement.clientHeight
    ];
  }
  else
  {
    size = [
        document.getElementsByTagName('body')[0].clientWidth,
        document.getElementsByTagName('body')[0].clientHeight
    ];
  }

  return size;
}

loadContentSection();
document.body.setAttribute("onresize","loadContentSection();");