function correctPosition(oElement,oPos,oWhich) {
  while( oElement.offsetParent ) {
    oPos -= oElement['offset'+oWhich];
    oElement = oElement.offsetParent;
  }
  oPos += document.documentElement['scroll'+oWhich] ? document.documentElement['scroll'+oWhich] : document.body['scroll'+oWhich];
  return oPos;
}
function getViewportSize() {
  var viewportwidth;
  var viewportheight;
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerWidth != 'undefined')
  {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth !=
  'undefined' && document.documentElement.clientWidth != 0)
  {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
  }
  // older versions of IE
  else
  {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
  }
  return [viewportwidth, viewportheight];
}
function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}
function findDiv () {
  var myObj = document.getElementById("maincontent");
  var myArr = findPos(myObj);
  var x = myArr[0];
  var y = myArr[1];
  alert(x);
  alert(y);
}
function getOffsetLeft() {
  var imageWidth = 0;
  
  if ( screen.width > 800)
  	imageWidth = 350;
  else
  	imageWidth = 200;
  	
  var myoffsetWidth = document.getElementById("maincontent").offsetWidth;
  var myoffsetLeft = document.getElementById("maincontent").offsetLeft;
  var myWholeOffset = myoffsetLeft + (myoffsetWidth - imageWidth)/2;
  return Math.floor(myWholeOffset);
}
function getOffsetTop() {
  var imageHeight = 0;
  
  if ( screen.width > 800)
  	imageHeight = 350;
  else
  	imageHeight = 200;
  	
  var myObj = document.getElementById("maincontent");
  var myArr = findPos(myObj);
  var x = myArr[0];
  var y = myArr[1];
  var finalOffset = window.screenTop + (screen.height - window.screenTop - 265 - imageHeight);
  //var finalOffset = 160;
  return Math.floor(finalOffset);
}
function writeNewBackground (){
	
  
  document.writeln( '<style type="text\/css">' );
  
  document.writeln( "#maincontent { ");
  
  if ( screen.width > 800)
  	document.writeln( "background-image: url(images/logo_background_350.gif);" );
  else
  	document.writeln( "background-image: url(images/logo_background_200.gif);" );
  
  
  document.writeln( "background-repeat: no-repeat;");
  
  var screenSize = getViewportSize();
  var width = screenSize[0];
  var height = screenSize[1];
  //var contentWidth = width - 500;
  var contentWidth = document.getElementById("maincontent").offsetWidth;
  var contentHeight = height - 145;
  
  
  var divLeft = 250
  var divTop = 150;
  var imageWidth = 0;
  
  if ( screen.width > 800)
  	imageWidth = 350;
  else
  	imageWidth = 200;
  	
  var newLeft = Math.floor(divLeft + (contentWidth - imageWidth)/2);
  var newTop = Math.floor(divTop + (contentHeight - imageWidth)/2);
  
  
  document.writeln( "background-position: " + newLeft + "px " + newTop + "px;");
  document.writeln( " }");
  
  document.writeln( '<\/style>' );
}
