/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Written by Terry Friesen,  tfriesen@mts.net  copyright 1998-2002
http://www.mts.net/~tfriesen/

last updated: July 8, 2002

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 make3d(a1,a2,a3,a4){
if(!this.has3d){
if(!this.Index()){this.Index(1)}
if(Client.kon2){this.Index(this.isNested?getParent(this).Index()+4:4)}
var fdiv=this._3dLayer=getParent(this).insertElement(null,null,null,true);
fdiv.div3d3=fdiv.insertElement(null,null,null,true);
fdiv.div3d2=fdiv.insertElement(null,null,null,true);
fdiv.div3d1=fdiv.insertElement(null,null,null,true);
this.getBgColor=getBgColor;
this.has3d=true;
this.show3d=show3d;
this.reset3d=reset3d;
this._3dLeft=this.pxLeft;
this._3dTop=this.pxTop;
this.pxLeft=left_3d;
this.pxTop=top_3d;
this._3dWidth=this.pxWidth;
this._3dHeight=this.pxHeight;
this.pxWidth=width_3d;
this.pxHeight=height_3d;
this._3dIndex=this.Index;
this.Index=index_3d;
this._3dVis=this.Visibility;
this.Visibility=vis_3d;
this.remove3dLip=remove3dLip;
this.setup_3d=setup_3d;
this.buttonDown=buttonDown;
this.buttonUp=buttonUp;
this.buttonOut=buttonOut;
this.setEventHandler("mousedown",buttonDown,"cb");
this.setEventHandler("mouseup",buttonUp,"cb");
this.setEventHandler("mouseout",buttonOut,"cb");
}
else{var fdiv=this._3dLayer}
var cp=this.clipTo;
this.height_3d=cp?this.clipHeight():this.pxHeight();
this.width_3d=cp?this.clipWidth():this.pxWidth();
this.index_3d=this.Index();
this.is3dButton=!!a1;
this.isButtonDown=false;
var bcolor=this.reset3d.bcolor=a2||this.getBgColor()||document.bgColor;
var bcolor2=this.reset3d.bcolor2=a3||"black";
var ecolor=this.reset3d.ecolor=a4||"white";
fdiv.Visibility(this.Visibility()||"inherit");
this.setup_3d(fdiv,4,4,this.pxLeft()+(cp?this.clipLeft():0)-2,this.pxTop()+(cp?this.clipTop():0)-2,bcolor2,this.index_3d-1);
this.setup_3d(fdiv.div3d3,3,3,0,0,bcolor,1);
this.setup_3d(fdiv.div3d2,2,2,1,1,bcolor2,2);
this.setup_3d(fdiv.div3d1,1,1,1,1,ecolor,3);
return this;
}

function setup_3d(lay,w,h,l,t,c,i){
lay.resizeTo(this.width_3d+w,this.height_3d+h);
lay.moveTo(l,t);
lay.setBgColor(c);
if(lay != this._3dLayer){lay.Visibility("inherit");}
lay.Index(i);
lay.is3d_bg=true;
}

function buttonDown(e){
if(this.is3dButton){
var fdiv=this._3dLayer;
fdiv.div3d1.moveTo(2,2);
fdiv.div3d2.moveTo(0,0);
fdiv.div3d2.resizeTo(this.width_3d+3,this.height_3d+3);
this.isButtonDown=true;
}
return this;
}

function buttonUp(e){
if(this.is3dButton){
var fdiv=this._3dLayer;
fdiv.div3d1.moveTo(1,1);
fdiv.div3d2.moveTo(1,1);
fdiv.div3d2.resizeTo(this.width_3d+2,this.height_3d+2);
this.isButtonDown=false;
}
return this;
}

function buttonOut(e){
if(this.is3dButton){
if(this.isButtonDown&&!this.holds(e.relatedElement)){this.reset3d()}
}
return this;
}

function show3d(a1,a2){
var showit=a1?'visible':'hidden';
this._3dLayer.Visibility(showit);
if(a2){this.Visibility(showit)}
return this;
}

function reset3d(){
var r=this.reset3d;
this.make3d(this.is3dButton,r.bcolor,r.bcolor2,r.ecolor);
this.remove3dLip(this.no3dLip);
return this;
}

function index_3d(a1){
this._3dLayer.Index(a1-1);
return this._3dIndex(a1)
}

function vis_3d(a1,a2){
if(!a2){this._3dLayer.Visibility(a1)}
return this._3dVis(a1)
}

function top_3d(a1,a2){
var s=a2||0;
this._3dLayer.pxTop(a1,s-2);
return this._3dTop(a1,s)
}
function left_3d(a1,a2){
var s=a2||0;
this._3dLayer.pxLeft(a1,s-2);
return this._3dLeft(a1,s)
}

function width_3d(a1,a2){
var s=a2||0;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
this.width_3d=a1;
var fdiv=this._3dLayer;
fdiv.pxWidth(a1,s+4);
fdiv.div3d3.pxWidth(a1,s+3);
fdiv.div3d2.pxWidth(a1,s+2);
fdiv.div3d1.pxWidth(a1,s+1);
this.remove3dLip(this.no3dLip)
}
return this._3dWidth(a1,s)
}
function height_3d(a1,a2){
var s=a2||0;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
this.height_3d=a1;
var fdiv=this._3dLayer;
fdiv.pxHeight(a1,s+4);
fdiv.div3d3.pxHeight(a1,s+3);
fdiv.div3d2.pxHeight(a1,s+2);
fdiv.div3d1.pxHeight(a1,s+1);
this.remove3dLip(this.no3dLip)
}
return this._3dHeight(a1,s)
}

function remove3dLip(a1){
var d=this._3dLayer;
var d2=d.div3d2;
var d3=d.div3d3;
var w=this.width_3d;
var h=this.height_3d;
if(a1=="both"){d.resizeTo(w+2,h+2);d3.resizeTo(w+2,h+2);d2.resizeTo(w+1,h+1);}
if(a1=="right"){d.resizeTo(w+2,h+4);d3.resizeTo(w+2,h+3);d2.resizeTo(w+1,h+2);}
if(a1=="bottom"){d.resizeTo(w+4,h+2);d3.resizeTo(w+3,h+2);d2.resizeTo(w+2,h+1);}
this.no3dLip=a1;
return this;
}

function getBgColor(){
if(Client.ns4){return this.page.bgColor}
else{return this.bgColor||this.style.backgroundColor;}
}
