var defLeft = 0;
var defTop = 0;

function WM_checkIn(WM_id) { 

/*
WM_checkIn()
Takes the ID of a positioned HTML element and returns an object reference.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Taylor
Author Email: taylor@wired.com
Author URL: http://www.taylor.org/

Usage: WM_checkIn('id')
*/

  // First we initialize all the variables.
  var theObj,ss,sr,i,j,WM_layers=new Array();
  // This chunk handles the IE portion of the checkIn code.
  if (document.all) {
    // This checks to see if the inline style declaration has 
    // a position property associated with it. If not, it will 
    // scan the global stylesheets for the ID.
    if((document.all[WM_id].style.position != 'absolute') && (document.all[WM_id].style.position != 'relative')){
      // This little loop I'm very proud of, because it's kinda 
      // slick and I wrote it all myself. It loops through all 
      // global stylesheets and all the rules in each stylesheet, 
      // tests for the selected ID, then returns that as the object.
      for (ss=0 ; ss < document.styleSheets.length; ss++) {
        for (sr=0 ; sr < document.styleSheets(ss).rules.length; sr++) { 
          if (document.styleSheets(ss).rules(sr).selectorText == '#' + WM_id) {
            theObj = document.styleSheets(ss).rules(sr).style;
            break;
          }
        }
      }
    } else {
      // This works the same as in the light version, so you can 
      // use inline styles.
      theObj = document.all[WM_id].style;
    }
  } else if(document.layers) {
    // Now we're in Netscapeland. The main problem here 
    // is finding the object in a maze of hierarchy.
    // I wish I could say that I'm proud of this code, 
    // because it's really slick. Unfortunately, I ripped 
    // it off from Macromedia Dreamweaver's drag layer code 
    // (with permission, of course :-) 
    // Dreamweaver/Configuration/Behaviors/Actions/Drag Layer.htm 
    // It works wonderfully and solves the problem.
    WM_layers = new Array();
    with (document) {
      for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
        for (i=0; i<WM_layers.length; i++) {
          if (WM_layers[i].document && WM_layers[i].document.layers) {
            for (j=0; j<WM_layers[i].document.layers.length; j++) {
              WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
            }
            if(WM_layers[i].name == WM_id){
              // So if the code matches the name of the layer, 
              // return the reference. 
              theObj = WM_layers[i];
            }
          }
        }
      }
    }
  } else {
     // Netscape 6 and up
        theObj = document.getElementById(WM_id).style;
  }
  
  return theObj;
}

/*
function getDIVLeft(divID)
{
  div = WM_checkIn(divID);
  return parseInt(div.left);
}

function getDIVTop(divID)
{
  div = WM_checkIn(divID);
  return parseInt(div.top);
}

function getDIVWidth(divID)
{
  div = WM_checkIn(divID);
  return parseInt(div.width);
}

function getDIVHeight(divID)
{
  div = WM_checkIn(divID);
  return parseInt(div.height);
}
*/

function getDIVLeft(divID)
{
  obj = MM_findObj(divID);
   var left;
   if (obj && (obj.style)) 
       left = obj.style.left;
	else
	    left = obj.left;

   //alert(obj);
   
  return parseInt(left);
}

function getDIVTop(divID)
{
  obj = MM_findObj(divID);
   var top;
   if (obj && (obj.style)) 
       top = obj.style.top;
	else
	    top = obj.top;

   //alert(obj);
   
  return parseInt(top);
}


function getDIVWidth(divID)
{
  obj = MM_findObj(divID);
   var width;
   if (obj && (obj.style)) 
       width = obj.style.width;
	else {
	     if (obj.clip)
	       width = obj.clip.width;
		 else
	       width = obj.width;
     }

   //alert(obj);
   
  return parseInt(width);
}

function getDIVHeight(divID)
{
  obj = MM_findObj(divID);
   var height;
   if (obj && (obj.style)) 
       height = obj.style.height;
	else {
	     if (obj.clip)
	       height = obj.clip.height;
		 else
	       height = obj.height;
     }
		
  return parseInt(height);
}


function setDIVLeft(divID, left)
{
  obj = MM_findObj(divID);
   if (obj && (obj.style)) 
       obj.style.left = left;
	else
	    obj.left = left;
}

function setDIVTop(divID, top)
{
  obj = MM_findObj(divID);
   if (obj && (obj.style)) 
       obj.style.top = top;
	else
	    obj.top = top;
}

function setDIVVisibility(divID, state)
{
  obj = MM_findObj(divID);
   if (obj && (obj.style)) 
       obj.style.visibility = state;
	else
	    obj.visibility = state;
}

function moveDIV(divID,leftOffset,topOffset)
{
  div = WM_checkIn(divID);
  if (div.left != "")
      div.left = parseInt(div.left) + leftOffset;
  else
      div.left = leftOffset;
  if (div.top != "")
      div.top = parseInt(div.top) + topOffset;
  else
      div.top = topOffset;
}

function resizeDIV(divID,width,height)
{
  div = WM_checkIn(divID);
  div.width = width;
  div.height = height;
}

function positionDIV(divID,left,top)
{
  div = WM_checkIn(divID);
  div.left = left;
  div.top = top;
}

function centerDIVs()
{
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    var screenWidth;
    var screenHeight;

  if (!ns) {
    screenWidth = document.body.offsetWidth;
    screenHeight = document.body.offsetHeight;
  } else if (ns4) {
    screenWidth = window.innerWidth;
    screenHeight = window.innerHeight;
  } else if (ns5) {
    screenWidth = window.innerWidth;
    screenHeight = window.innerHeight;
  }
  
  //alert("width: " + screenWidth + " height: " + screenHeight);
  
  leftOffset = 0;
  topOffset = 0;
  if (screenWidth > 760) {
      leftOffset = Math.round((screenWidth - 760) / 2);
  }
  if (screenHeight > 420) {
      topOffset = Math.round((screenHeight - 420) / 2);
  }

  moveDIV("background",leftOffset-defLeft,topOffset-defTop);
  
  defLeft = leftOffset;
  defTop = topOffset;
}

