

// lib.js: dhtml library by rod morelos - last updated: 05.12.2002
// contact: rod@dhtmlcentral.com | viewsrc@hotmail.com | icq#0123456789
// web: www.e-syed.net/viewsrc | www20.brinkster.com/viewsrc 
// keep these four lines and you're free to use this code

// 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: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.agent.indexOf('gecko')>-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.offsetX=0; this.offsetY=0; // element coordinates
this.mozscrollbar=bw.ns6?18:0; // ns6/mozilla scrollbar width/height
return this;
}
var opage=new pageobject();

// get mouse coordinates
pageobject.prototype.mouse=function(e)
{
if (undef(e)) e=event;
if (e.clientX&&e.clientY)
{
this.mouseX=e.clientX+opage.scrollLeft();
this.mouseY=e.clientY+opage.scrollTop();
}
if (e.offsetX&&e.offsetY)
{
this.offsetX=e.offsetX+(bw.ie5mac?opage.scrollLeft():0);
this.offsetY=e.offsetY+(bw.ie5mac?opage.scrollTop():0);
}
else if (e.layerX&&e.layerY)
{
this.offsetX=e.layerX;
this.offsetY=e.layerY;
}
};

// 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 page scroll left
pageobject.prototype.scrollLeft=function()
{
if (!undef(window.scrollX)) return window.scrollX;
else if (!undef(d.body.scrollLeft)) return d.body.scrollLeft;
};

// get page scroll top
pageobject.prototype.scrollTop=function()
{
if (!undef(window.scrollY)) return window.scrollY;
else if (!undef(d.body.scrollTop)) return d.body.scrollTop;
};

// 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: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;
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 (!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 (!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) { this.el.innerHTML=text; this.update(); };

// a dom2 way to write text to layer
dhtmlobject.prototype.writeit=function(text)
{
while (this.el.hasChildNodes()) this.el.removeChild(this.el.firstChild);
this.el.appendChild(d.createTextNode(text)); 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)
{
if (!undef(x)) { this.x=this.x+x; this.css.left=px(this.x); }
if (!undef(y)) { this.y=this.y+y; this.css.top=px(this.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); };

// 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); }
};

// 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));
}
}

