
window.offscreenBuffering = true; // used to reduced DHTML flickering

/*  BROWSER CHECK  */
function ros_bwcheck(){
	this.ver = navigator.appVersion.toLowerCase();
	this.agt = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById)?1:0;
	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.ie = (this.ie4 || this.ie5 || this.ie6);
	this.mac = (this.agt.indexOf("mac")>-1);
	this.ns4 = (document.layers && !this.dom)?1:0;
	this.ns6 = (this.dom && parseInt(this.ver)) >=5?1:0;
	this.nn = (navigator.appName == "Netscape");
	this.bw = (this.ns6 || this.ns4 || this.ie6 || this.ie5 || this.ie4 || this.dom);
	return this;
}

var bw = new ros_bwcheck();

/*  Error Message Function  */
function errorMsg(txt){alert(txt);return false}

/*  Main dhtml object creator  */
function rosObj(id){
	if(!bw.bw) return errorMsg('Upgrade your Browser!')
	
	if(bw.dom){
		this.obj = document.getElementById(id);
	}else if(bw.ie4){
		this.obj = document.all[id];		
	}else if(bw.ns4){
		this.obj = getNSLayer(id,document);
	}else{
		this.obj = 0;
	}
		
	if(!this.obj) return errorMsg('Cannot find object. \nOr if you are using Netscape check the nesting of your tags.')

	
	this.css = (bw.dom||bw.ie4) ? this.obj.style:this.obj;
	this.ref = (bw.dom||bw.ie4) ? document:this.css.document; 
	
	this.x = parseInt(this.css.left)||this.obj.offsetLeft||this.css.pixelLeft||0;
	this.y = parseInt(this.css.top)||this.obj.offsetTop||this.css.pixelTop||0;
	this.w = parseInt(this.css.clip.width)||this.obj.offsetWidth||this.css.pixelWidth||this.ref.width||0;
	this.h = parseInt(this.css.clip.height)||this.obj.offsetHeight||this.css.pixelHeight||this.ref.height||0;
//	this.z = this.css.zIndex; UNTIL I CAN FIND OUT HOW TO GRAB IT OFF THE BAT IN IE
	this.c=0;
	if((bw.dom || bw.ie4) && this.css.clip){
		this.c = this.css.clip.split('(')[1].split(')')[0].split(' ');		
		for(var i=0;i<4;i++) {this.c[i]=parseInt(this.c[i])}
	}
	this.ct = this.css.clip.top || this.c[0] || 0;
	this.cr = this.css.clip.right || this.c[1] || this.w || 0;
	this.cb = this.css.clip.bottom || this.c[2] || this.h || 0;
	this.cl = this.css.clip.left || this.c[3] || 0;
	this.id = id + "Object"; 
	//eval(this.id + "=this");
	return this;
}
/* Test to see if object is hidden */
rosObj.prototype.vis = function(){if(this.css.visibility=='hidden' || this.css.visibility=='HIDDEN' || this.css.visibility=='hide') return true;}

/*  Set Object visibility to visible  */
rosObj.prototype.showIt = function(){this.css.visibility = "visible"}

/* Set Object visibility to hidden  */
rosObj.prototype.hideIt = function(){this.css.visibility = "hidden"}

/*  Move object to specified coordinates  */
rosObj.prototype.moveTo = function(x,y){
	this.x = x;	this.y = y;	
	this.css.left = x; this.css.top = y
}

/*  Move object by specified amount  */
rosObj.prototype.moveBy = function(x,y){
	this.css.left = this.x+=x; 
	this.css.top = this.y+=y
}

/*  Set the background color  */
rosObj.prototype.bg = function(color){
	if(bw.dom || bw.ie4){
		this.css.backgroundColor = color;
	}else if(bw.ns4){
		this.css.bgColor =  color;
	}
}

/*  Writing content to object  */
rosObj.prototype.iHtml = function(text){
	if(this.obj.innerHTML != null){
		this.obj.innerHTML = '';
		this.obj.innerHTML = text;
	}else{
		this.ref.open();
		this.ref.write(text);
		this.ref.close();
	}
}

/*  Clipping object to specified amounts -/- setwidth var is used for IE, & NN6 to prevent overflow  */
rosObj.prototype.clipTo = function(t,r,b,l,setwidth){
	this.ct=t; this.cr=r; this.cb=b; this.cl=l; // in place for the clipBy function b/c without it, clipBy only runs once
	if(bw.ns4){
		this.css.clip.top=t; this.css.clip.right=r; this.css.clip.bottom=b; this.css.clip.left=l;
	}else{
		//if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(l<0)l=0;	
		this.css.clip = "rect(" +t+ "," +r+ "," +b+ "," +l+ ")";
		this.css.clip="rect("+t+","+r+","+b+","+l+")";
    if(setwidth){this.css.pixelWidth=this.css.width=r; 
    this.css.pixelHeight=this.css.height=b}

	}
}

/*  Clipping object by specific amounts  */
/*  Note: 
		--/-  if using this for setTimeout animation,
          be sure to do an inline style for IE so
					you can grab the values off the bat. 
					(if width is greater then clip right(cr)
*/
rosObj.prototype.clipBy = function(t,r,b,l,setwidth){ 
  this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
}

/*  Drag Drop Functionality  */

dd_ON=0;
dd_ONE=0;
dd_TWO=0;

// Capture and/or redirect Events to user-defined functions
function ros_dd(){
  dd_ON=1;
  if(bw.ns4){
  	document.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP)
  }
	document.onmousedown=ros_down;
  document.onmousemove=ros_move;  
  document.onmouseup=ros_up;
}

rosObj.prototype.dragdrop = 
	function(id){
  	if(!dd_ON) ros_dd()
	  this.obj.onmouseover=new Function("ros_over("+this.id+")")
	  this.obj.onmouseout=new Function("dd_TWO=0")
	  //if(id) this.ddobj=id
	}

rosObj.prototype.nodragdrop = function(){
  this.obj.onmouseover=""; this.obj.onmouseout=""
  dd_ONE=0; dd_TWO=0
}

function ros_over(id){dd_TWO=id}

//  document.onmousedown function
function ros_down(e){
  if(dd_TWO){
    origX=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
    origY=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
    dd_ONE=dd_TWO
    dd_ONE.distanceX = origX - dd_ONE.x;
    dd_ONE.distanceY = origY - dd_ONE.y
  }
}

//  e.pageX & e.pageY is for NN, the others are for IE
//  document.onmousemove function
//  removed these outta the function call --/- (,y,rresize)
function ros_move(e){
  origX=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
  origY=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
  if(dd_ONE){
    nx = origX - dd_ONE.distanceX; 
		ny = origY - dd_ONE.distanceY
    //if(dd_ONE.ddobj) dd_ONE.ddobj.moveTo(nx,ny)
    //else dd_ONE.moveTo(nx,ny)
		dd_ONE.moveTo(nx,ny)
  }
  if(!bw.ns4) return false
}

//  document.onmouseup function
function ros_up(e){dd_ONE=0}

/*  Netscape 4.0 - 4.7 function to get reference to layer  */
function getNSLayer(name,doc) {
	var layer;
	if(!doc) doc = document;
  
	for(var i=0;i < doc.layers.length;i++) {
  	layer = doc.layers[i];
	  if(layer.name == name) return layer;
    
		if(layer.document.layers.length > 0) {
    layer = getNSLayer(name, layer.document);
    if(layer.name == name) return layer;
    }
  }
return 0;
}
