﻿function CScroll(){
    this.frmSrc=$("frmSrc");
    this.frmTgt=$("frmTgt");
}
CScroll.prototype={
  Sync:function(){
	if(this.disabled)return;

    var g=4,t=0,s=0;
    
    var a=Util.GetBody(this.contentWindow.document);
    var f=Util.GetBody(this.frmFollow.contentWindow.document);

    s=f.scrollLeft;
    if(a.scrollWidth==a.offsetWidth)
      t=a.scrollLeft*f.scrollWidth/a.offsetWidth;
    else
      t=a.scrollLeft*(f.scrollWidth-f.offsetWidth)/(a.scrollWidth-a.offsetWidth);
    if(t-s>=g||s-t>=g)f.scrollLeft=t;

    s=f.scrollTop;
    if(a.scrollHeight==a.offsetHeight)
      t=a.scrollTop*f.scrollHeight/a.scrollHeight;
    else
      t=a.scrollTop*(f.scrollHeight-f.offsetHeight)/(a.scrollHeight-a.offsetHeight);
    if(t-s>=g||s-t>=g)f.scrollTop=t;
  },
  FrmSrcLoad:function(){
    Util.AddEvent(this.frmSrc.contentWindow,"scroll",Util.CreateDelegate(this.frmSrc,this.Sync));
    this.frmSrc.frmFollow=this.frmTgt;
  },
  FrmTgtLoad:function(){
	Util.AddEvent(this.frmTgt.contentWindow,"scroll",Util.CreateDelegate(this.frmTgt,this.Sync));
    this.frmTgt.frmFollow=this.frmSrc;
  }
}
