/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Written by Terry Friesen,  tfriesen@mts.net  copyright 1998-2001
http://www.mts.net/~tfriesen/

last updated: April 8, 2001

This script may be used freely on non-commercial web pages
It is not to be sold or profit made from it without the consent of the author
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function clipMethods(lay){
lay.clipTo=clipTo;
lay.setClip=setClip;
lay.clipTop=clipTop;
lay.clipRight=clipRight;
lay.clipBottom=clipBottom;
lay.clipLeft=clipLeft;
lay.clip_Str=clip_Str;
lay.clipHeight=clipHeight;
lay.clipWidth=clipWidth;
lay.scrollTo=scroll_To;
lay.scrollBy=scroll_By;
lay.clipEvent=new Object();
lay.clipEvent.type="clipend";
lay.onclipend=doNothing;
}

var lastClipLayer=null;

function setClip(t,r,b,l){
var ct=!isNaN(t+'')?t:this.clipTop();
var cr=!isNaN(r+'')?r:this.clipRight();
var cb=!isNaN(b+'')?b:this.clipBottom();
var cl=!isNaN(l+'')?l:this.clipLeft();
if(Client.ns4){
with(this.clip){top=ct;right=cr;bottom=cb;left=cl}
}
else{this.style.clip="rect("+ct+"px,"+cr+"px,"+cb+"px,"+cl+"px)"}
return lastClipLayer=this;
}

function clipTop(){
if(Client.ns4){return this.clip.top}
return parseInt(this.clip_Str()[0].substr(5))||0;
}
function clipRight(){
if(Client.ns4){return this.clip.right}
return parseInt(this.clip_Str()[1])||this.pxWidth();
}
function clipBottom(){
if(Client.ns4){return this.clip.bottom}
return parseInt(this.clip_Str()[2])||this.pxHeight();
}
function clipLeft(){
if(Client.ns4){return this.clip.left}
return parseInt(this.clip_Str()[3])||0;
}

function clip_Str(){return (this.style.clip||"0 ").split(" ")}
function clipHeight(){return this.clipBottom()-this.clipTop()}
function clipWidth(){return this.clipRight()-this.clipLeft()}

function scroll_By(a1,a2,a3){
this.moveBy(-a1,-a2);
this.setClip(this.clipTop()+a2,this.clipRight()+a1,this.clipBottom()+a2,this.clipLeft()+a1);
return this;
}
function scroll_To(a1,a2){
var cw=this.clipWidth(),ch=this.clipHeight();
this.moveTo(this.pxLeft()+this.clipLeft()-a1,this.pxTop()+this.clipTop()-a2);
this.setClip(a2,cw+a1,ch+a2,a1);
return this;
}

function clipTo(a1,a2,a3,a4,a5,a6){
if(!this.onclipend){this.onclipend=doNothing;}
var clipAction=a6||'run';
if((a5)&&(isNaN(a5))){
var clipSpeed=a5.split(",");
}
else{
var clipSpeed=new Array();
clipSpeed[0]=clipSpeed[1]=clipSpeed[2]=clipSpeed[3]=a5||1;
}
var clipT=this.clipTop();
var clipR=this.clipRight();
var clipB=this.clipBottom();
var clipL=this.clipLeft();
if((clipAction =='add')&&(this.clipLength)){
clipT=Number(this.dyn_ClipT[this.clipRunCount-1]);
clipR=Number(this.dyn_ClipR[this.clipRunCount-1]);
clipB=Number(this.dyn_ClipB[this.clipRunCount-1]);
clipL=Number(this.dyn_ClipL[this.clipRunCount-1]);
}
else{
this.dyn_ClipT=new Array();
this.dyn_ClipR=new Array();
this.dyn_ClipB=new Array();
this.dyn_ClipL=new Array();
this.clipRunCount=0;
}
var targetT=(! isNaN(a1+''))?a1+'':clipT;
var targetR=(! isNaN(a2+''))?a2+'':clipR;
var targetB=(! isNaN(a3+''))?a3+'':clipB;
var targetL=(! isNaN(a4+''))?a4+'':clipL;
var clipTPlus=(targetT>clipT);
var clipRPlus=(targetR>clipR);
var clipBPlus=(targetB>clipB);
var clipLPlus=(targetL>clipL);
var clipTLength=Math.abs(targetT-clipT);
var clipRLength=Math.abs(targetR-clipR);
var clipBLength=Math.abs(targetB-clipB);
var clipLLength=Math.abs(targetL-clipL);
var max1=Math.max(clipTLength/(clipSpeed[0]||1),clipRLength/(clipSpeed[1]||1));
var max2=Math.max(clipBLength/(clipSpeed[2]||1),clipLLength/(clipSpeed[3]||1));
this.clipLength=Math.ceil(Math.max(max1,max2))+this.clipRunCount;

for(i=this.clipRunCount;i<=this.clipLength;i++){
var speed=(i-this.clipRunCount);
var tspeed=speed*clipSpeed[0];
var rspeed=speed*clipSpeed[1];
var bspeed=speed*clipSpeed[2];
var lspeed=speed*clipSpeed[3];
if(clipTLength>=tspeed){
if(clipTPlus){this.dyn_ClipT[i]=clipT+tspeed;}
else{this.dyn_ClipT[i]=clipT-tspeed;}
}
else{
this.dyn_ClipT[i]=targetT;
}

if(clipRLength>=rspeed){
if(clipRPlus){this.dyn_ClipR[i]=clipR+rspeed;}
else{this.dyn_ClipR[i]=clipR-rspeed;}
}
else{
this.dyn_ClipR[i]=targetR;
}

if(clipBLength>=bspeed){
if(clipBPlus){this.dyn_ClipB[i]=clipB+bspeed;}
else{this.dyn_ClipB[i]=clipB-bspeed;}
}
else{
this.dyn_ClipB[i]=targetB;
}

if(clipLLength>=lspeed){
if(clipLPlus){this.dyn_ClipL[i]=clipL+lspeed;}
else{this.dyn_ClipL[i]=clipL-lspeed;}
}
else{
this.dyn_ClipL[i]=targetL;
}
}
this.clipRunCount=i;
this.hasClipPath=true;
this.reverseClip=reverseClip;
this.runClip=runClip;
this.stopClip=stopClip;
this.clip_Count=0;
this.clipIntervalSpeed=this.clipIntervalSpeed||25;
if((clipAction =='run')&&(!this.clipRunning)){this.runClip();}
return this;
}

function runClip(){
this.clipRunning=true;
this.setClip(this.dyn_ClipT[this.clip_Count],this.dyn_ClipR[this.clip_Count],this.dyn_ClipB[this.clip_Count],this.dyn_ClipL[this.clip_Count]);
if((this.clipLength>this.clip_Count++)&&(! this.clip_Stop)){
setTimeout("allLayers."+this.layerName+".runClip()",this.clipIntervalSpeed);
}
else{
this.clipRunning=false;
if(!this.clip_Stop){this.onclipend(this.clipEvent)}
}
return this;
}

function reverseClip(a1){
if(this.clipReversed){this.clipReversed=false;}
else{this.clipReversed=true;}
this.dyn_ClipT.reverse();
this.dyn_ClipR.reverse();
this.dyn_ClipB.reverse();
this.dyn_ClipL.reverse();
this.clip_Count=this.clipLength-this.clip_Count;
if((!a1)&&(!this.clipRunning)){this.runClip();}
return this;
}

function stopClip(a1){
this.clip_Stop=true;
setTimeout("allLayers."+this.layerName+".clip_Stop=false",this.clipIntervalSpeed);
if(a1){this.onclipend(this.clipEvent)}
return this;
}