var width=120;
var adHeight=600;
var ad_left = 610 ;

// how far from the top of the page to start the ad
var startHeightFromTop=242;

function placeStickyAd()
{
// skyscraper width and height

// for Netscape only
if (document.layers)
{
  startWidth = window.innerWidth;
  startHeight = window.innerHeight;

  var temp_w=window.innerWidth; // the width of the window in Netscape
  var temp = temp_w-ad_left;
  var w = temp_w-temp;
}



// for IE
if (document.all)
{
  // the following are used to determine position for the sticky ad
  // for the blown out right rail scenario
  document.all.topcurve.style.visibility = "visible";
  document.all.topcurve.style.position = "relative";
  setAd();
}

} // end placeStickyAd function

// for IE 
function setAd()
{
  // this sets the initial place of the ad (width). This is only called once.
  // it is determined by the placement of the top_curve_j image
  var offsetWidth = 10;
  var findAdWidth = document.getElementById("topcurve").offsetLeft;
  
  //document.all.stickyad.style.left = document.body.scrollLeft + findAdWidth + offsetWidth;
  document.all.stickyad.style.left = ad_left;
  
  
  // the amount of pixels from the left of the screen
  //document.all.stickyad.style.left = document.body.scrollLeft + w;

  // the amount of pixels the ad starts from the top
  document.all.stickyad.style.top = document.body.scrollTop + startHeightFromTop;

  document.all.stickyad.style.visibility = "visible";
  
  // calls the scrollAd function
  window.onscroll=scrollAd
  
  // this just reloads the page if the user resizes the window
  window.onresize=new Function("window.location.reload()");
}


// for IE
function scrollAd(){
  
  // this sets the initial place of the ad (width). This is only called once.
  // it is determined by the placement of the top_curve_j image
  var offsetWidth = 10;
  var findAdWidth = document.getElementById("topcurve").offsetLeft;
  
  
  //document.all.stickyad.style.left = document.body.scrollLeft + findAdWidth + offsetWidth;
  document.all.stickyad.style.left = ad_left ;
  
  
  // set variables:  
  
  // ClientHeight - height of the browsing area
  var ch = document.body.clientHeight;
  
  // ScrollTop - how much the user has scrolled down the page
  var st = document.body.scrollTop;
  
  // adTop - where the ad is positioned on the page
  var at = parseInt(document.all.stickyad.style.top);
  
  // ad bottom = adTop + adHeight
  var ab = at + adHeight;
  
  // offset gives the ad a little room
  var offset = 50;
  
  if ( (st > at) && (st < ab) ) // ad on page, straddling top
  { }
  else if ( ((st+ch) > at) && ((st+ch) < ab) ) // ad on page, straddling bottom
  { }
  else if ( (st < at) && ((st+ch) > ab) ) // ad fully on page
  { }
  else if ( (st > at) && (st > ab) ) // ad off page, above user 
  {
    // move ad to scrollTop plus some offset
    document.all.stickyad.style.top = st + offset; // might want some offset here
  }
  else if ( ((st+ch) < at) && ((st+ch) < ab) ) // ad off page, below user
  {
    // bottom of the ad to be scroll top + client height
    // make sure the ad doesn't scroll up past original starting point on page
    if ( (st + ch - adHeight - offset) < startHeightFromTop )
    {
      document.all.stickyad.style.top = startHeightFromTop;
    } 
    else
    {
      document.all.stickyad.style.top = st + ch - adHeight - offset; // should be > startHeightFromTop 
    }
  }
  else { 
  //alert("st " + st + " at " + at + " ab " + ab + " ch " + ch); 
  }

  // the amount of pixels from the left of the screen
  //document.all.stickyad.style.left = document.body.scrollLeft + w;

}


