// dhtml library by rod morelos (rod@dhtmlcentral.com) www20.brinkster.com/viewsrc 
// keep these two lines and you're free to use this code

// last updated: 08.12.2002

// note: "standards" compliant browsers only!
if (!document.getElementById) { window.location.href='http://www.webstandards.org/upgrade/'; }

// typesavers
var d=document;

// utilities
function px(n) { return (isNaN(n)||window.opera)?n:Math.round(n)+'px'; }
function r(n) { return (Math.round(Math.random()*n)); }
function rand(a,b) { return (Math.round(Math.random()*(b-a)))+a; }
function between(a,n,b) { return ((n>Math.min(a,b))&&(n<Math.max(a,b))); }
function undef(v) { var u; return v==u; }
function redraw() { setTimeout('window.location.reload()',200); }

// browser object; browser check
function browserobject()
{
this.ver=navigator.appVersion.toLowerCase();
this.agent=navigator.userAgent.toLowerCase();
this.dom=d.getElementById?1:0;
this.op6=(this.agent.indexOf('opera 6')>-1||this.agent.indexOf('opera/6')>-1)?1:0;
this.ie5=(this.agent.indexOf('msie 5')>-1&&this.dom&&!this.op6)?1:0;
this.ie5mac=(this.ie5&&this.agent.indexOf('mac')>-1)?1:0;
this.ie6=(this.agent.indexOf('msie 6')>-1&&this.dom&&!this.op6)?1:0;
this.ns6=(this.agent.indexOf('mozilla')>-1&&this.dom)?1:0;
this.ie=(this.ie5||this.ie6||this.ie5mac);
this.ns=(this.ns6);
this.bw=(this.ie||this.ns||this.op6);
return this;
}
var bw=new browserobject();

// page object; document/window related functions
function pageobject()
{
this.mouseX=0; this.mouseY=0; // page coordinates
this.layerX=0; this.layerY=0; // element coordinates
return this;
}
var opage=new pageobject();

// get page scroll left
pageobject.prototype.scrollLeft=function()
{
if (!undef(d.body.scrollLeft)) return d.body.scrollLeft;
else if (!undef(window.scrollX)) return window.scrollX;
};

// get page scroll top
pageobject.prototype.scrollTop=function()
{
if (!undef(d.body.scrollTop)) return d.body.scrollTop;
else if (!undef(window.scrollY)) return window.scrollY;
};

// get page width
pageobject.prototype.w=function()
{
if (d.body&&d.body.clientWidth) return d.body.clientWidth+this.scrollLeft();
else if (window.innerWidth) return window.innerWidth+this.scrollLeft();
};

// get page height
pageobject.prototype.h=function()
{
if (d.body&&d.body.clientHeight) return d.body.clientHeight+this.scrollTop();
else if (window.innerHeight) return window.innerHeight+this.scrollTop();
};

// get mouse coordinates
pageobject.prototype.mouse=function(e)
{
if (undef(e)) e=window.event;
if (undef(e.layerX)) this.layerX=e.offsetX; else this.layerX=e.layerX;
if (undef(e.layerY)) this.layerY=e.offsetY; else this.layerY=e.layerY;
if (!undef(e.clientX)) this.mouseX=e.clientX+this.scrollLeft();
if (!undef(e.clientY)) this.mouseY=e.clientY+this.scrollTop();
if (bw.ie5mac) { this.layerX=this.layerX+this.scrollLeft(); this.layerY=this.layerY+this.scrollTop(); }
};

// disable link focus outlines
pageobject.prototype.nofocus=function()
{
lnk=d.getElementsByTagName?d.getElementsByTagName('a'):d.links?d.links:null;
if (lnk) { for (var l=0;lnk[l];l++) { ae(lnk[l],'focus',new Function('lnk['+l+'].blur()'),true); } }
};

// dhtml object; makes cross-browser object
function dhtmlobject(obj)
{
this.el=d.getElementById?d.getElementById(obj):null;
if (undef(this.el)) alert(obj);
this.css=this.el.style;
this.obj=obj+'Object'; eval(this.obj+'=this');
this.x=this.el.offsetLeft?this.el.offsetLeft:0;
this.y=this.el.offsetTop?this.el.offsetTop:0;
this.w=this.el.offsetWidth?this.el.offsetWidth:0;
this.h=this.el.offsetHeight?this.el.offsetHeight:0;
this.z=this.css.zIndex?this.css.zIndex:0;
this.opaq=100; this.fadetimer=0;
return this;
}

// update function; get left, top, width and height of element again.
dhtmlobject.prototype.update=function()
{
this.x=this.el.offsetLeft?this.el.offsetLeft:parseInt(this.css.left)?parseInt(this.css.left):0;
this.y=this.el.offsetTop?this.el.offsetTop:parseInt(this.css.top)?parseInt(this.css.top):0;
this.w=this.el.offsetWidth?this.el.offsetWidth:parseInt(this.css.width)?parseInt(this.css.width):0;
this.h=this.el.offsetHeight?this.el.offsetHeight:parseInt(this.css.height)?parseInt(this.css.height):0;
};

// set layer visibility property: 0 = hidden; 1 = visible
dhtmlobject.prototype.setv=function(v) { this.css.visibility=(v==0)?'hidden':'visible'; };

// set layer display property
dhtmlobject.prototype.setd=function(d) { this.css.display=d; };

// set layer opacity
dhtmlobject.prototype.seto=function(o)
{
// if (bw.ns6) this.css.setProperty('-moz-opacity',o/100,' ');
if (!undef(this.css.MozOpacity)) this.css.MozOpacity=(o/100);
else if (this.el.filters) this.css.filter='alpha(opacity='+o+')';
this.opaq=o;
};

// get layer opacity
dhtmlobject.prototype.geto=function()
{
// if (bw.ns6) return (this.css.getPropertyValue('-moz-opacity')*100);
if (!undef(this.css.MozOpacity)) return this.css.MozOpacity*100;
else if (this.el.filters) return this.el.filters.alpha.opacity;
};

// write text to layer and update width and height
dhtmlobject.prototype.write=function(text) { if (!undef(this.el.innerHTML)) this.el.innerHTML=text; this.update(); };

// mozilla innerHTML function (similar to the write function above)
dhtmlobject.prototype.sethtml=function(text) { if (bw.ns6) { var r=d.createRange(); r.selectNodeContents(this.el); r.deleteContents(); var f=r.createContextualFragment(text); this.el.appendChild(f); this.update(); } };

// changes the foreground color of the layer
dhtmlobject.prototype.fg=function(color) { this.css.color=color; };

// changes the background color of the layer
dhtmlobject.prototype.bg=function(color) { this.css.backgroundColor=color; };

// attach a background image to the layer
dhtmlobject.prototype.bgimg=function(image) { this.css.backgroundImage='url('+image+')'; };

// set layer z-index
dhtmlobject.prototype.setz=function(z) { this.z=z; this.css.zIndex=this.z; };

// move layer to
dhtmlobject.prototype.moveto=function(x,y)
{
if (!undef(x)) { this.x=x; this.css.left=px(this.x); }
if (!undef(y)) { this.y=y; this.css.top=px(this.y); }
};

// move layer by
dhtmlobject.prototype.moveby=function(x,y) { this.moveto(this.x+x,this.y+y); };

// align layer relative to the page (use your keyboard's numeric keypad as reference)
// 7-8-9 = 7 is top left, 8 is top center and 9 is top right
// 4-5-6 = 4 is left center, 5 is center of page and 6 is right center
// 1-2-3 = 1 is bottom left, 2 is bottom center and 3 is bottom right
dhtmlobject.prototype.alignto=function(num)
{
if (num==1) this.moveto(0,opage.h()-this.h); // bottom left
if (num==2) this.moveto(opage.w()/2-this.w/2,opage.h()-this.h); // bottom center
if (num==3) this.moveto(opage.w()-this.w,opage.h()-this.h); // bottom right
if (num==4) this.moveto(0,opage.h()/2-this.h/2); // left center
if (num==5) this.moveto(opage.w()/2-this.w/2,opage.h()/2-this.h/2); // center of page
if (num==6) this.moveto(opage.w()-this.w,opage.h()/2-this.h/2); // right center
if (num==7) this.moveto(0,0); // top left
if (num==8) this.moveto(opage.w()/2-this.w/2,0); // top center
if (num==9) this.moveto(opage.w()-this.w,0); // top right
};

// set layer width
dhtmlobject.prototype.setw=function(w) { this.w=w; this.css.width=px(this.w); };

// set layer height
dhtmlobject.prototype.seth=function(h) { this.h=h; this.css.height=px(this.h); };

// get layer width
dhtmlobject.prototype.getw=function()
{
if (this.el.offsetWidth) return this.el.offsetWidth;
else if (parseInt(this.css.width)) return parseInt(this.css.width);
else return 0;
};

// get layer height
dhtmlobject.prototype.geth = function()
{
if (this.el.offsetHeight) return this.el.offsetHeight;
else if (parseInt(this.css.height)) return parseInt(this.css.height);
else return 0;
};

// clip layer to
dhtmlobject.prototype.clipto=function(t,r,b,l,d)
{
if (t<0) t=0; if (r<0) r=0; if (b<0) b=0; if (l<0) l=0;
this.css.clip='rect('+px(t)+','+px(r)+','+px(b)+','+px(l)+')';
if (!undef(d)) { this.setw(r); this.seth(b); }
};

// fade animation functions
dhtmlobject.prototype.fadeto=function(target,step,time) { clearTimeout(this.fadetimer); this.fade(target,step,time); };
dhtmlobject.prototype.fade=function(target,step,time)
{
if (target>this.opaq) this.seto(this.opaq+step); else this.seto(this.opaq-step);
if (Math.abs(target-this.opaq)>step) { this.fadetimer=setTimeout(this.obj+'.fade('+target+','+step+','+time+')',time); }
else { this.seto(target); clearTimeout(this.fadetimer); }
};

// checks if the mouse pointer is over the element
dhtmlobject.prototype.ismouseover=function(e)
{
opage.mouse(e); mx=opage.mouseX; my=opage.mouseY; el=this.el;
while (el.parentNode.nodeName.toLowerCase()!='body') { el=el.parentNode; mx-=el.offsetLeft; my-=el.offsetTop; }
if (mx>=this.x&&(mx<=(this.x+this.w))&&my>=this.y&&(my<=(this.y+this.h))) return true; else return false;
};

dhtmlobject.prototype.isover=function(e)
{
htmlel=window.event?event.srcElement:e.target;
if (htmlel.nodeType==3||htmlel.tagName.toLowerCase()=='img') htmlel=htmlel.parentNode;
if (htmlel.id==this.el.id) return true; else return false;
};

// attach an event to an element
function ae(el,et,fn,cap)
{
if (el.addEventListener) { el.addEventListener(et,fn,cap); return true; }
else if (el.attachEvent) { var ae=el.attachEvent('on'+et,fn); return ae; }
else { el['on'+et]=fn; }
};

// detach an event from an element
function re(el,et,fn,cap)
{
if (el.removeEventListener) { el.removeEventListener(et,fn,cap); return true; }
else if (el.detachEvent) { var re=el.detachEvent('on'+et,fn); return re; }
else { el['on'+et]=null; }
};

// create an element
function ce(tag,id,sty,cl,nest)
{
if (d.createElement)
{
el=d.createElement(tag);
el.setAttribute('id',id);
if (bw.ie) el.style.cssText=sty;
else el.setAttribute('style',sty);
if (cl) el.className=cl;
if (nest) d.getElementById(nest).appendChild(el);
else d.body.appendChild(el);
}
}

// delete an element
function de(el,nest)
{
if (d.createElement&&d.getElementById(el))
{
if (nest) d.getElementById(nest).removeChild(d.getElementById(el));
else d.body.removeChild(d.getElementById(el));
}
}
