// XDHTML Cross-Browser DHTML Library
// All code copyright 2001 Rod Morelos, www.e-syed.net/viewsrc | www20.brinkster.com/viewsrc
// Feel free to use this script for personal use, all I ask is that this code comment remain in tact.
// If you're are thinking of using this code for profit, you MUST get my permission before doing so.
// Thank you. - Rod Morelos (viewsrc@hotmail.com)

// Browser check (needed)
function checkBrowser()
{
this.agent=navigator.userAgent;
this.ver=navigator.appVersion;
this.dom=document.getElementById?1:0;
this.win=this.agent.indexOf('Windows')>-1;
this.mac=this.agent.indexOf("Mac")>-1;
this.ie4=(document.all && !this.dom)?1:0;
this.ie5=(this.ver.indexOf('MSIE 5')>-1 && this.dom)?1:0;
this.ie6=(this.ver.indexOf('MSIE 6')>-1 && this.dom)?1:0;
this.ie4mac=(this.ie4 && this.mac);
this.ie5mac=(this.ie5 && this.mac);
this.ns4=(document.layers && !this.dom)?1:0;
this.ns6=(this.dom && parseInt(this.ver) >= 5)?1:0;
this.ie=(this.ie4 || this.ie5 || this.ie6 || this.ie4mac || this.ie5mac);
this.ns=(this.ns4 || this.ns6);
this.w3c=(this.ie5 || this.ie6 || this.ns6 || this.ie5mac);
this.bw=(this.ie4 || this.ie5 || this.ie6 || this.ns4 || this.ns6);
return this;
}
var bw=new checkBrowser();

// Get browser window width
function getWinWidth()
{
if (bw.ie) return document.body.clientWidth+document.body.scrollLeft;
else if (bw.ns) return window.innerWidth+window.pageXOffset;
}

// Get browser window height
function getWinHeight()
{
if (bw.ie) return document.body.clientHeight+document.body.scrollTop;
else if (bw.ns) return window.innerHeight+window.pageYOffset;
}

// Get page scroll x
function getPageScrollX()
{
if (bw.ie) return document.body.scrollLeft;
else if (bw.ns) return window.pageXOffset;
}

// Get Page scroll y
function getPageScrollY()
{
if (bw.ie) return document.body.scrollTop;
else if (bw.ns) return window.pageYOffset;
}

// Capture mouse x and y movements
var mousex=0; var mousey=0;
function captureMouse(e)
{
mousex=bw.ns?e.pageX:event.clientX+document.body.scrollLeft;
mousey=bw.ns?e.pageY:event.clientY+document.body.scrollTop;
}

// Page object positioning
function pageObject()
{
this.x=0; this.y=0;
this.x2=getWinWidth(); this.y2=getWinHeight();
this.x50=this.x2/2; this.y50=this.y2/2;
return this;
}		

// Makes crossbrowser object
function makeObject(obj)
{
this.css=bw.w3c?document.getElementById(obj).style:bw.ie4?document.all[obj].style:null;
this.oref=bw.w3c?document.getElementById(obj):bw.ie4?document.all[obj]:null;
this.showIt=f_showIt;
this.hideIt=f_hideIt;
this.showhide=f_showhide;
this.setDisplay=f_setDisplay;
this.x; this.y;
this.moveIt=f_moveIt;
this.moveBy=f_moveBy;
this.moveAt=f_moveAt;
this.setLeft=f_getLeft;
this.setTop=f_getTop;
this.getLeft=f_getLeft;
this.getTop=f_getTop;
this.writeIt=f_writeIt;
this.fg=f_fg;
this.bg=f_bg;
this.bgImage=f_bgImage;
this.width=f_width;
this.height=f_height;
this.setWidth=f_setWidth;
this.setHeight=f_setHeight;
this.clipIt=f_clipIt;
this.clipBy=f_clipBy;
this.getzIndex=f_getzIndex;
this.setzIndex=f_setzIndex;
return this;
}

// Makes an object's visibiltiy visible
function f_showIt() { this.css.visibility='visible'; }

// Makes an object's visibiltiy hidden
function f_hideIt() { this.css.visibility='hidden'; }

// Hide object if it's visible and visa versa
function f_showhide()
{
this.css.visibility=(this.css.visibility=='visible' || this.css.visibility=='')?'hidden':'visible';
}

// Sets the object's display property
function f_setDisplay(disp) { this.css.display=disp; }

// Move object to
function f_moveIt(x,y)
{
this.x=x; this.y=y;
this.css.left=this.x;
this.css.top=this.y;
}

// Move object by
function f_moveBy(x,y)
{
this.x=this.x+x; this.y=this.y+y;
this.css.left=this.x;
this.css.top=this.y;
}

// Page object moves
// Use your keyboard's numeric keypad for reference.
// 7 - 8 - 9  =  7 is top left, 8 is top center and 9 is top right
// |   |   |
// 4 - 5 - 6  =  4 is center left, 5 is center/middle and 6 is center right
// |   |   |
// 1 - 2 - 3  =  1 is bottom left, 2 is bottom center and 3 is bottom right
function f_moveAt(num)
{
pageObj=new pageObject();
if (num==7 || num==null) this.moveIt(0,0); // top left, duh!
if (num==4) this.moveIt(0,pageObj.y50-this.height()/2); // center left
if (num==1) this.moveIt(0,pageObj.y2-this.height()); // bottom left
if (num==8) this.moveIt(pageObj.x50-this.width()/2,0); // top center
if (num==5) this.moveIt(pageObj.x50-this.width()/2,pageObj.y50-this.height()/2); // center middle
if (num==2) this.moveIt(pageObj.x50-this.width()/2,pageObj.y2-this.height()); // bottom center
if (num==9) this.moveIt(pageObj.x2-this.width(),0); // top right
if (num==6) this.moveIt(pageObj.x2-this.width(),pageObj.y50-this.height()/2); // center right
if (num==3) this.moveIt(pageObj.x2-this.width(),pageObj.y2-this.height()); // bottom right
}

// Set left position of object
function f_setLeft(x) { this.x=x; this.css.left=this.x; }

// Set top position of object
function f_setTop(y) { this.y=y; this.css.top=this.y; }

// Get left position of object
function f_getLeft()
{
if (bw.ns6) { if (this.css.left) return parseInt(this.css.left); else return this.oref.offsetLeft; }
else if (bw.ie) { if (this.css.pixelLeft) return parseInt(this.css.pixelLeft);	else return this.oref.offsetLeft; }
}

// Get top position of object
function f_getTop()
{
if (bw.ns6) { if (this.css.top) return parseInt(this.css.top); else return this.oref.offsetTop; }
else if (bw.ie) { if (this.css.pixelTop) return parseInt(this.css.pixelTop); else return this.oref.offsetTop; }
}

// Writing content to object
function f_writeIt(text) { this.oref.innerHTML=text; }

// Changes the foreground color of the object
function f_fg(color) { this.css.color=color; }

// Changes the background color of the object
function f_bg(color) { if (bw.ie4 || bw.w3c) this.css.backgroundColor=color; }

// Changes the background image of the object
function f_bgImage(image) { this.css.backgroundImage='url('+image+')'; this.css.background='url('+image+')'; }

// Get object width
function f_width()
{
if (bw.ie) if (this.css.pixelWidth) return this.css.pixelWidth; else return this.oref.offsetWidth;
else if (bw.ns6) if (this.css.width) return parseInt(this.css.width); else return this.oref.offsetWidth;
}

// Get object height
function f_height()
{
if (bw.ie) if (this.css.pixelHeight) return this.css.pixelHeight; else return this.oref.offsetHeight;
else if (bw.ns6) if (this.css.height) return parseInt(this.css.height); else return this.oref.offsetHeight;
}

// Set object width
function f_setWidth(w) { this.css.width=w; }

// Set object height
function f_setHeight(h) { this.css.height=h; }

// Clipping object to...
function f_clipIt(t,r,b,l) { this.css.clip='rect('+t+','+r+','+b+','+l+')'; }

// Clipping object by...
function f_clipBy(t,r,b,l) { this.clipIt(t+t,r+r,b+b,l+l); }

// Sets the object z-index
function f_setzIndex(zOrder) { this.css.zIndex=zOrder; }

// Gets the object z-index
function f_getzIndex() { if (this.css.zIndex=='') return 0; else return this.css.zIndex; }

/////////////////////////////
// Miscellaneous functions //
/////////////////////////////

// Reload function
function reloadIt() { setTimeout('history.go(0)',200); } // Reload image, etc. from cache
function reloadPage() { setTimeout('document.location.reload()',200); } // Totally reload the page

// Math functions
var pi = 3.1415;
function square(num) { return (num*num); }
function sqrt(num) { return Math.sqrt(num); }
function round(num) { return Math.round(num); }
function rand(num) { return (round(Math.random()*num)+num); }
function degrad(num) { return ( num/(360/(2*pi)) ); } // degrees to radians
function raddeg(num) { return ( num*(360/(2*pi)) ); } // radians to degrees

// Disable focusing for all links in document (IE and NS6+ only)
function hideFocus()
{
if (bw.ie4)
{
for (var i=0;i<document.links.length;i++) { document.links[i].onfocus = function() { this.blur(); } }
}
else if (bw.w3c)
{
atags = document.getElementsByTagName('a');
for (var i=0;i<atags.length;i++) { atags[i].onfocus = function() { this.blur(); } }
}
}

// Image Functions:
// Preload Images
function preloadImg()
{
var preImg=new Array();
for (var i=0;i<arguments.length;i++) { preImg[i]=new Image(); preImg[i].src=arguments[i]; }
}

/*
Miscellaneous JS functions
*/

