//whatlayer,nameofvar,over,out,down,up,focus
//var mainAngle=0;
documentMouseHandlers=false;

function divObject(div,self,over,out,down,up){
	this.self=self;
	this.object=getDivision(div);
	this.objectString=getDivision(name,true);
	this.slow=setUpSlow;
	this.doSlow=slowdown;
	this.posx=0;
	this.posy=0;
	this.posz=0;
	this.endx=0;
	this.endy=0;
	this.move=moveDiv;
	this.endspeed=0;
	this.visb=false;
	this.visibility=visibleDiv;
	this.content=writeDiv;
	this.resize=resizeDiv;
	this.clip=clipDiv;
	this.alpha=alpha;
	this.opacity=100;
	this.clipTop=null;
	this.clipBottom=null;
	this.clipLeft=null;
	this.clipRight=null;
	this.height=null;
	this.width=null;
	this.getSize=getSize;
	this.getPos=getPos;
	this.info=divInfo;
	this.activeMenuImg=null;
	this.menuImgName='menu';
	this.swapImg=swapImg;
	this.swapMenu=menuImg;
	this.numMenuImg=0;
	this.menuImgPath="images/menuimg/";
	this.menuImgOn="_act.gif";
	this.menuImgOff="_off.gif";
	this.menuImgAct="_on.gif"
	this.scrollLimit=[0,0,0,0] //up,down,left,right
	this.scrollPage=initScrollDiv;
	this.moveScroll=scrollDiv;
	this.scrollDir=false;
	this.scrollSpd=0;
	this.doScroll=false;
	this.bgColor=false;
	this.drag=false;
	this.newBg=newBgcolor
	this.glow=glowDiv;
	this.moveSp=moveSpecial;
	this.overAction=over
	this.outAction=out;
	this.downAction=down;
	this.upAction=up;
	this.dragMe=dragLayer;


	//mouseHandlers

	if(chk.ns4){
		this.object.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
		if(documentMouseHandlers){
			this.object.onmousedown=new Function(this.self+".downmousey=Y;"+this.self+".downmousex=X;eval("+this.downAction+");return true;");
			this.object.onmouseup=new Function(this.self+".upmousey=Y;"+this.self+".upmousex=X;eval("+this.upAction+");return true;");
		}
		this.object.onmouseover =new Function("eval("+this.overAction+");return true;");
		this.object.onmouseout =new Function("eval("+this.outAction+");return true;");
	}
	else{
		if(documentMouseHandlers){
			this.object.onmousedown=new Function(this.self+".downmousey=Y;"+this.self+".downmousex=X;eval("+this.downAction+");return false;");
			this.object.onmouseup=new Function(this.self+".upmousey=Y;"+this.self+".upmousex=X;eval("+this.upAction+");return false;");
		}
		this.object.onmouseover =new Function("eval("+this.overAction+");return true;");
		this.object.onmouseout =new Function("eval("+this.outAction+");return true;");
	}

	//END mousehandlers
	this.getSize();
	this.getPos();
	this.origx=this.posx;
	this.origy=this.posy;
	this.origz=this.posz;
	this.contents=getContent;
	this.contents();

	//this.info();
	//end functions performed at initiation
}

//BASIC functions, such as moving, showing/hiding, write new content, width/height

function divInfo(){
	alert("x:"+this.posx+"\ny:"+this.posy+"\nz:"+this.posz+"\nwidth:"+this.width+"\nheight:"+this.height+"\nVisibility:"+this.visb+"\n");
}

function getContent(){
	this.cont=false;
	if(chk.ns6 || chk.ie){
		this.cont=this.object.innerHTML;
	}
	return this.cont;
}

function menuImg(img,state,active){
	if(active){
		this.actveMenuImg=active;
		for(var i=1;i<=this.numMenuImg;i++){
			this.object.document.images[this.menuImgName+i].src=this.menuImgPath+i+this.menuImgOff
		}
		this.object.document.images[this.menuImgName+img].src=this.menuImgPath+img+this.menuImgAct
	}
	if(state){if(img!=this.actveMenuImg){this.object.document.images[this.menuImgName+img].src=this.menuImgPath+img+this.menuImgOn}}
	else{if(img!=this.actveMenuImg){this.object.document.images[this.menuImgName+img].src=this.menuImgPath+img+this.menuImgOff}}
}

function swapImg(src){
	this.object.document.images[img].src=src
}


function moveDiv(x,y,z){
	if(chk.ie || chk.ns6 || chk.ns7|| chk.moz){
		if(x!=null){this.object.style.left=x+"px";this.posx=x;}
		if(y!=null){this.object.style.top=y+"px";this.posy=y;}
		if(z!=null){this.object.style.zIndex=z;this.posz=z;}
	}
	if(chk.ns4 && !chk.ns6){
		if(x!=null){this.object.left=x;this.posx=x;}
		if(y!=null){this.object.top=y;this.posy=y;}
		if(z!=null){this.object.zIndex=z;this.posz=z;}
	}
}

function moveSpecial(x,y,z){
	if(chk.ie || chk.ns6|| chk.moz||chk.ns7){
		if(x!=null){this.object.style.left=x+"px";}
		if(y!=null){this.object.style.top=y+"px";}
		if(z!=null){this.object.style.zIndex=z;}
	}
	if(chk.ns && !chk.ns6){
		if(x!=null){this.object.left=x;}
		if(y!=null){this.object.top=y;}
		if(z!=null){this.object.zIndex=z;}
	}
}

function dragLayer(){
	if(this.drag){
		layerToDrag=this.self;
	}
}

function visibleDiv(visb){
	if(chk.ie || chk.ns6 || chk.ns7|| chk.moz){
		if(visb){
			this.object.style.visibility="visible";
			this.vis=true;
			}
		else{
		this.object.style.visibility="hidden";
		this.vis=false;
		};
	}
	if(chk.ns&&!chk.ns6){
		if(visb){
			this.object.visibility="show";
			this.vis=true;
			}
		else{
		this.object.visibility="hidden";
		this.vis=false;
		}
	}
}

function writeDiv(txt){
	if(chk.ie || chk.ns6 || chk.ns7|| chk.moz){
		this.object.innerHTML=txt;
	}
	if(chk.ns4&&!chk.ns6){
		this.object.document.open();
		this.object.document.write(txt);
		this.object.document.close();
	}
}

function resizeDiv(width,height){
	if(chk.ie || chk.ns6|| chk.moz||chk.ns7){
		if(width!=null){this.object.style.width=width}
		if(height!=null){this.object.style.height=height}
	}
	if(chk.ns&&!chk.ns){return false;}
}

function clipDiv(t,r,b,l){
	if(chk.ie||chk.ns6||chk.ns7|| chk.moz){
		this.object.style.clip="rect("+t+"px,"+r+"px,"+b+"px,"+l+"px)";
	}
	if(chk.ns4&&!chk.ns6){
		this.object.clip.top=t;
		this.object.clip.left=l;
		this.object.clip.bottom=b;
		this.object.clip.right=r;
	}
	this.clipTop=t;
	this.clipBottom=b;
	this.clipLeft=l;
	this.clipRight=r;
}

function alpha(a){
	if(chk.ie){
		this.object.style.filter="Alpha(opacity="+a+")";
	}
	if(chk.ns6|| chk.moz||chk.ns7){
		a/=100;
		this.object.style.MozOpacity=a;
	}
	this.opacity=a;
}

function glowDiv(color,strength){
	if(chk.ie){
		this.object.style.filter="Glow(Color="+color+",Strength="+strength+")";
	}
}


function getSize(){
	var h=null;
	var w=null;
	if(chk.ie||chk.ns6||chk.ns7|| chk.moz){
		h=this.object.offsetHeight;
		w=this.object.offsetWidth;
	}
	if(chk.ns4){
		h=this.object.document.height;
		w=this.object.document.width;
	}
	if(h!=null){this.height=h}
	else{return false;}
	if(w!=null)(this.width=w);
	else{return false;}
	this.height=h;
	this.width=w;
	//alert(w+"_"+this.width+"_"+h+"_"+this.height);
}

function getPos(){
	var x=null;
	var y=null;
	if(chk.ie||chk.ns6|| chk.ns7|| chk.moz){
		x=this.object.offsetLeft;
		y=this.object.offsetTop;
	}
	if(chk.ns4){
		x=this.object.left;
		y=this.object.top;
	}
	if(x!=null){this.posx=x}
	else{return false;}
	if(y!=null)(this.posy=y);
	else{return false;}
	//alert(x+"_"+this.posx+"_"+y+"_"+this.posy);
}

function newBgcolor(c){
	if(chk.ns4){this.object.bgColor=c;}
	if(chk.ie || chk.ns6 || chk.ns7){this.object.style.backgroundColor=c;}
	this.bgColor=c;
}

//Specialized functions

function setUpSlow(endx,endy,speed,func){
	this.endx=endx;
	this.endy=endy;
	this.endspeed=speed;
	this.doneSlowFunction=func;
	this.doSlow();
}


function slowdown(){
	this.incX=Math.ceil(((this.endx-this.posx)/this.endspeed)*100);
	this.incY=Math.ceil(((this.endy-this.posy)/this.endspeed)*100);
	this.posx=(Math.abs(this.posx-this.endx)>1)?this.posx+(this.incX/100):this.endx;
	this.posy=(Math.abs(this.posy-this.endy)>1)?this.posy+(this.incY/100):this.endy;
	if(this.posy==this.endy&&this.posx==this.endx){
		this.move(this.endx,this.endy);
		eval(this.doneSlowFunction);
	}
	else{
		this.move(this.posx,this.posy);
		setTimeout(this.self+".doSlow()","15");
	}
}

function getDivision(div,st){
 divLength=(div.length)-1;
    if(chk.ie){
		diV='document.all.'+div[divLength];
		}
		if(chk.ns6||chk.ns7|| chk.moz || chk.safari){
			diV='document.getElementById("'+div[divLength]+'")';
		}
		if(chk.ns4){
			for(var i=0;i<=divLength;i++){
			if(i==0){diV='document.layers.'+div[i];}
			else{
			diV=diV+'.document.layers.'+div[i];
			}
		}
    }
	if(st){
		return diV;
		return false;
	}
  diV=eval(diV);
  return diV;
}

function initScrollDiv(dir,spd){
	if(this.doScroll){return false;}
	this.scrollDir=dir;
	this.scrollSpd=spd;
	this.doScroll=true;
	this.moveScroll();
}


function scrollDiv(){
	//this.posx+"_"+this.posy;
	if(!this.doScroll){return false;}
	var end=false;
	switch(this.scrollDir){
		case 'down':
			this.posy-=this.scrollSpd;
			if(this.posy<this.scrollLimit[0]){this.posy=this.scrollLimit[0];end=true;}
		break;
		case 'up':
			this.posy+=this.scrollSpd;
			if(this.posy>this.scrollLimit[1]){this.posy=this.scrollLimit[1];end=true;}
		break;
		case 'right':
			this.posx-=this.scrollSpd;
			if(this.posx>this.scrollLimit[3]){this.posx=this.scrollLimit[3];end=true;}
		break;
		case 'left':
			this.posx+=this.scrollSpd;
			if(this.posx<this.scrollLimit[4]){this.posx=this.scrollLimit[4];end=true;}
		break;
		default:
			return false;
		break;
	}
	this.move(this.posx,this.posy);
	if(!end){
		setTimeout(this.self+".moveScroll()","25");
	}
	else{
		this.doScroll=false;
	}
}

//EVENTUAL 3D FUNCTIONS
