//this file stores paths to layers for a number of browsers and provides a complete browser detect. It
//also provides some default layer functionality

function imgswap(t,p,i,s) {
	bw.ns4?document.layers[p].document.layers[t].document.images[i].src=s:document.images[i].src=s;
}

window.onload=checkobjs
windowobjs=[]

function addWindowObj(txt) {
	index=windowobjs.length
	index++
	windowobjs[index]=txt;
}

function imageroll(i,s) {
		document.images[i].src=s;
}

//	img - image, src - new source, div - first div (optional), pdiv - parent div (optional)
function doRoll(img,src,div,pdiv) {
	if (bw.ie) {
		document.images[img].src=src;
	} else {
		div=(!div)?'':'document.'+div+'.';
		pdiv=(!pdiv)?'':'document.'+pdiv+'.';
		dom=eval(pdiv+div+'document.images.'+img);
		dom.src=src;
	}
}

//	img - image, ind - preload index, div - first div (optional), pdiv - parent div (optional)
function preRoll(img,ind,div,pdiv) {
	if (bw.ie) {
		document.images[img].src=preload[ind].src;
	} else {
		div=(!div)?'':'document.'+div+'.';
		pdiv=(!pdiv)?'':'document.'+pdiv+'.';
		dom=eval(pdiv+div+'document.images.'+img);
		dom.src=preload[ind].src;
	}
}

preload=new Array()
function addPreload() {
	for (i=0;i<arguments.length;i++) {
		newindex=preload.length;
		preload[newindex]=new Image();
		preload[newindex].src=arguments[i];
	}
}

function updateHead(s) {
	if (bw.ie) {dHeader=parent.navframe.document.images["pageheader"]}
	if (bw.ns4) {dHeader=parent.navframe.document.header.document.images["pageheader"]}
	dHeader.src=s
}

function checkBrowser(){
	this.win=(navigator.platform=="Win32")?1:0;
	this.mac=(navigator.platform=="MacPPC")?1:0;
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;						/* The getElementById method is applicable to 5th generation browsers only. */
	this.ie7=(this.ver.indexOf("MSIE 7")!=-1 && this.dom)?1:0; 	/* Will handle both ie6*/
	this.ie6=(this.ver.indexOf("MSIE 6")!=-1 && this.dom)?1:0; 	/* Will handle both ie6*/
	this.ie5=(this.ver.indexOf("MSIE 5")!=-1 && this.dom)?1:0; 	/* Will handle both ie5 and ie5.5 */
	this.ie4=(document.all && !this.dom)?1:0;					/* Specifically ie4 */
	this.ns6=(this.dom && parseInt(this.ver)>=5)?1:0;			/* Netscape 6 (Mozilla) */
	this.ns4=(document.layers && !this.dom)?1:0;				
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.ie6)?1:0;		/* Only IE or Navigator */
	this.ie=(this.ie4 || this.ie5 || this.ns6 || this.ie6 || this.ie7)?1:0;					/* Allows single test on bw.ie */
	this.nav=(this.ns4)?1:0;									/* Allows single test on bw.nav */
	return this
}

function objLayer(id,nest,dnest) {
	nest=(!nest)?'':'document.'+nest+'.';
	dnest=(!dnest)?'':'document.'+dnest+'.';
	/* object pointer */ 
	this.obj=bw.dom?document.getElementById(id):bw.ie4?document.all[id]:bw.ns4?eval(dnest+nest+'document.'+id):0	
	
	/* style reference */
	this.css=bw.dom?document.getElementById(id).style:bw.ie4?document.all[id].style:bw.ns4?eval(dnest+nest+'document.'+id):0

	if (bw.ie4 || bw.ie5 || bw.ie6 || bw.ie7) {this.x=this.css.pixelLeft; this.y=this.css.pixelTop; this.h=this.obj.scrollHeight; this.w=this.obj.scrollWidth}
	if (bw.ns6) {this.x=this.css.left; this.y=this.css.top; this.w=this.css.width; this.h=this.css.height;}
	if (bw.ns4) {this.x=this.css.left; this.y=this.css.top; this.h=this.obj.document.height; this.w=this.obj.document.width}
	/* mac variant */
	if (bw.mac && (bw.ie4 || bw.ie5)) {this.h=this.obj.clientHeight; this.w=this.obj.clientWidth}
	if (bw.opera) {this.h=this.obj.clientHeight; this.w=this.obj.clientWidth}
	
	temp=id.split("_");
	this.objname=temp[0]+"obj";
	
	return this;
}

//this creates objects out of layers named with specific keywords
//object names are made AFTER trailing variables are removed from layer name
function checkobjs() {
	if (bw.ie4 || bw.ie5 || bw.ie6 || bw.ie7) {
		for (i=0;i<document.all.length;i++) {
			for (j=0;j<windowobjs.length;j++) {
				if (document.all[i].id.indexOf(windowobjs[j])!=-1) {
					temp=document.all[i].id.split("_");
					eval(temp[0]+"obj=new objLayer('"+document.all[i].id+"')")
					if (document.all[i].id.indexOf("dropdown")!=-1) {setdrop(document.all[i].id)}//if req'd
					if (document.all[i].id.indexOf("floater")!=-1) {setfloat(document.all[i].id)}//if req'd
					if (document.all[i].id.indexOf("scrollouter")!=-1) {setscroll(document.all[i].id)}//if req'd
				}
			}
		}
	} else if (bw.ns4) {
		for (i=0;i<document.layers.length;i++) {
			dnestid=document.layers[i].id;
			
			for (w=0;w<windowobjs.length;w++) {
				if (dnestid.indexOf(windowobjs[w])!=-1) {
					temp=dnestid.split("_");
					eval(temp[0]+"obj=new objLayer('"+dnestid+"')")
					if (dnestid.indexOf("dropdown")!=-1) {setdrop(dnestid)}//if req'd
					if (dnestid.indexOf("floater")!=-1) {setfloat(dnestid)}//if req'd
					if (dnestid.indexOf("scrollouter")!=-1) {setscroll(dnestid)}//if req'd
				}
			}
			
			if (document.layers[i].document.layers.length>0) {
				for (j=0;j<document.layers[i].document.layers.length;j++) {
					nestid=document.layers[i].document.layers[j].id;
					
					for (w=0;w<windowobjs.length;w++) {
						if (nestid.indexOf(windowobjs[w])!=-1) {
							temp=nestid.split("_");
							eval(temp[0]+"obj=new objLayer('"+nestid+"','"+dnestid+"')")
							if (nestid.indexOf("dropdown")!=-1) {setdrop(nestid)}//if req'd
							if (nestid.indexOf("floater")!=-1) {setfloat(nestid)}//if req'd
							if (nestid.indexOf("scrollouter")!=-1) {setscroll(nestid)}//if req'd
						}
					}
					
					if (document.layers[i].document.layers[j].document.layers.length>0) {
						for (k=0;k<document.layers[i].document.layers[j].document.layers.length;k++) {
							tempid=document.layers[i].document.layers[j].document.layers[k].id;
							
							for (w=0;w<windowobjs.length;w++) {
								if (tempid.indexOf(windowobjs[w])!=-1) {
									temp=tempid.split("_");
									eval(temp[0]+"obj=new objLayer('"+tempid+"','"+nestid+"','"+dnestid+"')")
									if (tempid.indexOf("dropdown")!=-1) {setdrop(tempid)}//if req'd
									if (tempid.indexOf("floater")!=-1) {setfloat(tempid)}//if req'd
									if (tempid.indexOf("scrollouter")!=-1) {setscroll(tempid)}//if req'd
								}
							}
						}
					}
				}
			}
		}


	} else if (bw.ns6) {
		var totalEl=document.getElementsByTagName('*')
		for (i=0;i<totalEl.length;i++) {
			for (j=0;j<windowobjs.length;j++) {
				if (totalEl[i].id.indexOf(windowobjs[j])!=-1) {
					temp=totalEl[i].id.split("_");
					eval(temp[0]+"obj=new objLayer('"+totalEl[i].id+"')")
					if (totalEl[i].id.indexOf("dropdown")!=-1) {setdrop(totalEl[i].id)}//if req'd
					if (totalEl[i].id.indexOf("floater")!=-1) {setfloat(totalEl[i].id)}//if req'd
					if (totalEl[i].id.indexOf("scrollouter")!=-1) {setscroll(totalEl[i].id)}//if req'd
				}
			}
		}
	}
}

function obj_updateDim() {
	if (bw.ie4 || bw.ie5 || bw.ns6 || bw.ie6 || bw.ie7) {this.h=this.obj.scrollHeight; this.w=this.obj.scrollWidth}   
	if (bw.ns4) {this.h=this.obj.document.height; this.w=this.obj.document.width}
	/* mac variant */
	if (bw.mac && bw.ie) {this.h=this.obj.clientHeight; this.w=this.obj.clientWidth}
}

function obj_moveTo(x,y){
	this.x=x
	this.y=y
	this.css.left=this.x
	this.css.top=this.y
}

function obj_moveBy(x,y){
	this.x+=x
	this.y+=y
	this.css.left=this.x
	this.css.top=this.y
}

function obj_setZIndex(z){
	this.css.zIndex = z
}

function obj_clipTo(t,r,b,l){
	if(bw.ns4){
		this.css.clip.top = t
		this.css.clip.right = r
		this.css.clip.bottom = b
		this.css.clip.left = l
	} else {
		this.css.clip="rect("+t+","+r+","+b+","+l+")"
	}
}

function obj_hide(){
	this.css.visibility=(bw.ns4)?'hide':'hidden'
}

function obj_show(){
	this.css.visibility=(bw.ns4)?'show':'visible'
}

function obj_writeIt(txt){
	if (bw.ns4){
		this.obj.document.write(txt)
		this.obj.document.close()
	} else {
		this.obj.innerHTML = txt
	}
}

function obj_changeBackColor(c) {
	if (bw.ns4){
		this.css.bgColor = c;
	} else {
		this.css.backgroundColor = c;
	}
}

function obj_changeAlpha(o) {//IE only filter
	if (bw.ns4) {
		//do nothing
	} else {
		this.css.filter = "alpha(opacity="+o+")"
	}
}

function obj_setSize(w,h) {
	this.css.width=w;
	this.css.height=h;
	this.w=w;
	this.h=h;
}

objLayer.prototype.moveTo=obj_moveTo
objLayer.prototype.moveBy=obj_moveBy
objLayer.prototype.clipTo=obj_clipTo
objLayer.prototype.hide=obj_hide
objLayer.prototype.show=obj_show
objLayer.prototype.writeIt=obj_writeIt
objLayer.prototype.setZIndex = obj_setZIndex
objLayer.prototype.changeBack=obj_changeBackColor
objLayer.prototype.changeAlpha=obj_changeAlpha
objLayer.prototype.updateDim=obj_updateDim
objLayer.prototype.setSize=obj_setSize
