// PositionBox.js
//
// dynamically set the position of the box div in order to avoid shenanigans with Safari and Firefox scrollbars.

var box = null;
var designedFor = null;
var ad = null;
var phone = null;
var newversion = null;
var boxWidth = 0;
var boxHeight = 0;

function setBoxPosition()
{
  var w = window.outerWidth;
  if (!w) { w = document.body.clientWidth; }
  
  if (box == null) box = document.getElementById("divBox");
  if (designedFor == null) designedFor = document.getElementById("designedFor");
	if (ad == null) ad = document.getElementById("divAd");
	if (newversion == null) newversion = document.getElementById("divNew");
  if (phone == null) phone = document.getElementById("divPhone");
  if (boxWidth <= 0) boxWidth = box.clientWidth;
	if (boxHeight <= 0) boxHeight = box.clientHeight;
  
  var leftOffset = Math.round((w - boxWidth) / 2);
  if (leftOffset < 10) leftOffset = 10;
  
  box.style.left = leftOffset;
  box.style.visibility = 'visible';
  
  designedFor.style.left = leftOffset + boxWidth;
  designedFor.style.visibility = 'visible';
	
	var href = document.location.href;
	var showAd = false;
	if (href.indexOf('screenshots') > -1) showAd = true;
  else if (href.indexOf('purchase') > -1) showAd = true;
	else if (href.indexOf('download') > -1) showAd = true;
	else if (href.indexOf('guide') > -1) showAd = true;
	else if (href.indexOf('credits') > -1) showAd = true;
  else if (href.indexOf('press') > -1) showAd = true;
	
	if (showAd)
	{
    var designedForHeight = Element.getHeight(designedFor);
    designedForHeight += 68;
    
  	ad.style.left = leftOffset + boxWidth;
	  ad.style.top = designedForHeight + 'px'; // boxHeight - ($('divAd').clientHeight + 22);
	  ad.style.visibility = 'visible';
	}
  
  if (phone)
  {
    phone.style.left = 332;
	
	  var phoneTop = (navigator.userAgent.indexOf('MSIE') == -1) ? 100 : 99;
	  phone.style.top = phoneTop;
  	phone.style.visibility = 'visible';
  }
	
	if (newversion)
	{
	  newversion.style.left = 382;
		newversion.style.top = 212;
		newversion.style.visibility = 'visible';
	}
}

window.onresize = setBoxPosition;