// ColumnScroll.js
// smoothly scrolls three columns (wrapped_menu, wrapped_content+wrapped_trailer, and wrapped_ads) so that they are all proportional to the total window size
// The largest column scrolls normally, the other two proportionally such that all start at the top and and at the bottom.
var new_menu_top=0;
var new_ads_top=0;
var new_content_top=0;
var timeout=null;
function scrolling()
{
  var scrOfY = 0; 
  var menu_height = 0;
  var ads_height = 0;
  var content_height = 0;
  var body_height = 0;
  var window_height=0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    window_height = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    window_height = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    window_height = document.body.clientHeight;
  }
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }

      srcobj=document.getElementById('wrapped_menu');
      if (srcobj.innerHeight)
      {
	   menu_height = srcobj.innerHeight;
	   ads_height = document.getElementById('wrapped_ads').innerHeight;
	   content_height = document.getElementById('wrapped_content').innerHeight + document.getElementById('wrapped_trailer').innerHeight;
	  }
      else
      { 
         if (document.documentElement && document.documentElement.clientHeight)
         {
	      menu_height = srcobj.clientHeight;
	      ads_height = document.getElementById('wrapped_ads').clientHeight;
	      content_height = document.getElementById('wrapped_content').clientHeight + document.getElementById('wrapped_trailer').clientHeight;
         }
         else
         {
            if (document.body)
            {
 	         menu_height = srcobj.clientHeight;
	         ads_height = document.getElementById('wrapped_ads').clientHeight;
	         content_height = document.getElementById('wrapped_content').clientHeight + document.getElementById('wrapped_trailer').clientHeight;
            }
         }
      }
// body_height=100;
 body_height=Math.max(menu_height,ads_height,content_height);
 var percentage = Math.round(100*scrOfY/(body_height - window_height));
 new_menu_top = Math.round(percentage*(body_height - menu_height)/100);
 new_ads_top = Math.round(percentage*(body_height - ads_height)/100);
 new_content_top = Math.round(percentage*(body_height - content_height)/100);
 if (timeout) clearTimeout(timeout); // this code cancels a pending scroll if user wants more
 timeout = setTimeout("timeout=null;smoothscroll();",200); // idea is this becomes a single timeout occuring 200 ms AFTER the last scroll
// document.getElementById('info').innerHTML="Window_height: "+window_height+"<br>scrolled to: "+scrOfY+" ("+percentage+"%)<br>menu_height: "+menu_height+"<br>ads_height: "+ads_height+"<br>content_height: "+content_height+"<br>body_height: "+body_height+"<br>new_menu_top: "+new_menu_top+"<br>new_content_top: "+new_content_top+"<br>new_ads_top: "+new_ads_top;
}
function smoothscroll()
{
 var done=true;
 var menu_adjust=0;
 var ads_adjust=0;
 var content_adjust=0;
 var sf=1; // minimum step size
// alert("menu_top="+document.getElementById('wrapped_menu').style.top+"<br>content_top="+document.getElementById('wrapped_content').style.top+"<br>ads_top="+document.getElementById('wrapped_ads').style.top);
 var menu_top = parseInt(document.getElementById('wrapped_menu').style.top); 
 var ads_top = parseInt(document.getElementById('wrapped_ads').style.top); 
 var content_top = parseInt(document.getElementById('wrapped_content').style.top); 
 menu_adjust = new_menu_top - menu_top; 
 ads_adjust = new_ads_top - ads_top; 
 content_adjust = new_content_top - content_top; 
 // I'll adjust the step size to be the square root of the need adjustment - this will start fast and ramp down. Extra code to handle negatives properly.
 if (menu_adjust > sf) { menu_adjust = Math.round(Math.sqrt(menu_adjust)); done=false; }
 else if (menu_adjust < (-sf)) { menu_adjust = -Math.round(Math.sqrt(-menu_adjust)); done=false; }
 if (content_adjust > sf) { content_adjust = Math.round(Math.sqrt(content_adjust)); done=false; }
 else if (content_adjust < (-sf)) { content_adjust = -Math.round(Math.sqrt(-content_adjust)); done=false; }
 if (ads_adjust > sf) { ads_adjust = Math.round(Math.sqrt(ads_adjust)); done=false; }
 else if (ads_adjust < (-sf)) { ads_adjust = -Math.round(Math.sqrt(-ads_adjust)); done=false; }
// document.getElementById('info').innerHTML="menu_top="+menu_top+" new="+new_menu_top+" adjust="+menu_adjust+"<br>Content_top="+content_top+" new="+new_content_top+" adjust="+content_adjust+"<br>Ads_top="+ads_top+" new="+new_ads_top+" adjust="+ads_adjust;
 document.getElementById('wrapped_menu').style.top = (menu_top + menu_adjust) +"px";
 document.getElementById('wrapped_ads').style.top = (ads_top + ads_adjust)+"px";
 document.getElementById('wrapped_content').style.top = (content_top + content_adjust)+"px";
 document.getElementById('wrapped_trailer').style.top = (content_top + content_adjust)+"px";
 if (!done) setTimeout("smoothscroll()",50); // go one stepfactor every 100 milliseconds
}

document.getElementById('wrapped_menu').style.top = "0px";
document.getElementById('wrapped_ads').style.top = "0px";
document.getElementById('wrapped_content').style.top = "0px";
document.getElementById('wrapped_trailer').style.top = "0px";
window.onscroll=scrolling;

