iens6=document.all||document.getElementById
ns4=document.layers
var mousex=0,mousey=0;

Drag = null
Scroll = null
var sb;

function mouseMove(e) {
	mousex = (!document.all)? e.pageX : (event.x+document.body.scrollLeft)
	mousey = (!document.all)? e.pageY -155: (event.y+document.body.scrollTop)
	flag=1;

	if(sb!=null) return  !sb.mouseMoveActive;
	//else return false;
}
function mouseDown(e) {
/*
	if ((ns4 && e.which!=1) || (iens6 && event.button!=1)) return true
	mousex = (ns4)? e.pageX : event.x+document.body.scrollLeft
	mousey = (ns4)? e.pageY : event.y+document.body.scrollTop
	if (ns4 && e.target!=document) routeEvent(e)
	if (Scroll && ScrollTestActive()) return false
	else if (Drag && drag.mouseDown(mousex,mousey)) return false
	else return DynMouseDown(mousex,mousey)
*/
	//return false;
}
function handlerMU(e){
	if(sb!=null) sb.mouseMoveActive = false;
	//return false;
}

function ScrollBar(name,direction,width,height,grip_w,grip_h,speed,img_root) {
	this.name = name;
	this.direction = direction;
	this.w=width
	this.h=height
	this.speed = speed*5;

	this.scrollInit		= scrollInit;

	this.printStartDIV	= printStartDIV;
	this.printEndDIV	= printEndDIV;
	this.printStartDIV_V= printStartDIV_V;
	this.printEndDIV_V	= printEndDIV_V;
	this.printStartDIV_H= printStartDIV_H;
	this.printEndDIV_H	= printEndDIV_H;
	this.moverate		= moverate;

	this.setrate		= setrate;

	this.movedown		= movedown;
	this.moveup			= moveup;
	this.moveleft		= moveleft;
	this.moveright		= moveright;

	this.movegrip		= movegrip;
	this.movegrip_V		= movegrip_V;
	this.movegrip_H		= movegrip_H;

	this.draggrip		= draggrip;
	this.cleartimer    	= cleartimer;
	this.expand			= expandLayer;
	
	this.onmousemove	= onmousemove;
	this.onmousedown	= onmousedown;
	this.onmouseup		= onmouseup;
	this.checkScroll	= checkScroll;

	this.onscroll		= onScroll;
	this.onmouseWheel	= onmouseWheel;

	this.onmousedown_bar = onmousedown_bar;

	this.img_w = 14;
	this.img_h = 9;
	this.lw = this.w-this.img_w*2;

	this.x = 0;
	this.y = 0;
	this.crossobj;	
	this.containerobj;
	this.contentheight=0;
	this.contentwidth;

	this.xrate = 0;
	this.yrate = 0;
	this.wheelDelta = 0;

	this.objgrip;
	this.grip_w = grip_w;
	this.grip_h = grip_h;
	this.scrolldelay = 100;
	this.mouseMoveActive = false;
	this.timer;

	this.mouseStartX = 0;
	this.mouseStartY = 0;
	this.mouseCurrentX = 0;
	this.mouseCurrentY = 0;
	this.gripStartX = 0;
	this.gripStartY = 0;
	this.img_root = img_root;
}
function expandLayer(){
	this.crossobj.style.overflow = "visible";
	containersb.style.overflow = "visible";
	div_barsb.style.visibility  = "hidden";

}
function printStartDIV(doc){
	if(this.direction=="V") this.printStartDIV_V(doc);
	else this.printStartDIV_H(doc);
}
function printEndDIV(doc){
	if(this.direction=="V") this.printEndDIV_V(doc);
	else this.printEndDIV_H(doc);
}
function onmouseWheel(){
	var recall = false;
	
	if(event!=null)	this.wheelDelta = event.wheelDelta;

	if(this.direction=="V"){ 
		if(this.wheelDelta>0) {
			this.moveup(false);
		}else{
			this.movedown(false);
		}
	}else{
		if(this.wheelDelta>0) {
			this.moveleft(false);
		}else{
			this.moveright(false);
		}	
	}
	
}
function printStartDIV_V(doc){
	var divStart = "";
	divStart += "<table border=0 cellspacing=0 cellpadding=0><tr><td valign=top width="+(this.w-this.img_w)+" height="+this.h+">";

	if (iens6){
		divStart += "<div  onscroll='"+this.name+".onscroll();' id=container"+this.name+" style='WIDTH:"+(this.w-this.img_w)+";  HEIGHT: "+this.h+"; OVERFLOW: hidden; POSITION: relative;  VISIBILITY: visible;overflow:hidden;'>\n";
		divStart += "		<div   onmousewheel='"+this.name+".onmouseWheel();' id=content"+this.name+" style='position:relative;'>";	
	}else if (ns4){
		divStart +="<ilayer name='nscontainer"+this.name+"' width="+(this.w-this.img_w)+" height="+this.h+" clip='0,0,"+(this.w-this.img_w)+","+this.h+"'>";
		divStart +="<layer name='nscontent"+this.name+"' width="+(this.w -this.img_w)+" height="+this.h+" visibility=hidden><form name=frm_act>";
	}

	doc.write(divStart);
	
}
function printEndDIV_V(doc){
	var divEnd = "";
	if(iens6){
		divEnd +="	</div>";
		divEnd +="</div>";
	}else if (ns4){
		divEnd +="</form></layer>";
		divEnd +="</ilayer>";	
	}

	
	divEnd +="</td>";
	divEnd +="<td width="+this.img_w+" height="+this.h+" valign='top'>";

	divEnd +="	<table cellspacing=0 cellpadding=0 border=0>";
	divEnd +="	<tr><td width="+this.img_w+" height="+this.img_h+"><a onmousedown='"+this.name+".moveup(true);' onmouseout='"+this.name+".cleartimer();'  onmouseup='"+this.name+".cleartimer();' onfocus='this.blur(0)'><img name=up_arrow"+this.name+" src='images/up_e.gif' border=0 width="+this.img_w+" height="+this.img_h+" style='cursor:hand;'></a></td></tr>";
	divEnd +="	<tr><td width="+this.img_w+" height="+(this.h-this.img_h*2)+" valign=top>";
if(iens6){
	divEnd +="<div  onmousedown='"+this.name+".onmousedown_bar();' id='div_bar"+this.name+"' style=\"background-image:url('"+this.img_root+"/images/bg_v.gif');position:relative;width:"+this.grip_w+";height:"+(this.h-this.img_h*2)+"\"  onmousemove='"+this.name+".onmousemove();' >";
	divEnd +="  <div id='div_grip"+this.name+"' style=\"background-image:url('images/grip_v.gif');position:absolute;cursor:hand;width:"+this.grip_w+";height:"+this.grip_h+"; OVERFLOW: hidden;\"";
	divEnd +="   onmousemove='"+this.name+".onmousemove();' onmousedown='"+this.name+".onmousedown();' onmouseup='"+this.name+".onmouseup();'>";
	divEnd +="  </div>";
	divEnd +="</div>";
}else if (ns4){
	divEnd +="    <ilayer id='div_bar"+this.name+"' width="+this.grip_w+" height="+(this.h-this.img_h*2)+"  background='"+this.img_root+"images/bg_v.gif'>";
	divEnd +="<layer id='div_grip"+this.name+"' width="+this.grip_w+" height="+this.grip_h+" >";
	divEnd +="<img name='img_bar"+this.name+"' src='"+this.img_root+"images/grip_v.gif' border=0 width="+this.grip_w+" height="+this.grip_h+" ";
	divEnd +=" onmousedown='"+this.name+".onmousedown();'>";
	divEnd +="</layer>";
	divEnd +="</ilayer>";
}

	divEnd +="</td></tr>";
	divEnd +="	<tr><td width=15 height="+this.img_h+"><a onmousedown='"+this.name+".movedown(true);' onmouseout='"+this.name+".cleartimer();'  onmouseup='"+this.name+".cleartimer();' onfocus='this.blur(0)'><img  name=down_arrow"+this.name+" src='images/down_e.gif' border=0 width="+this.img_w+" height="+this.img_h+" style='cursor:hand;'></a></td></tr>";
	divEnd +="	</table>";
	
	divEnd +="</td>";
	divEnd +="</tr></table>";

	doc.write(divEnd);
}

function printStartDIV_H(doc){
	var divStart = "";
	divStart += "<table cellspacing=0 cellpadding=0 border=0><tr><td valign=top width="+this.w+" height="+(this.h-this.grip_h)+">";

	if (iens6){
		divStart += "<div  onscroll='"+this.name+".onscroll();' id=container"+this.name+" style='WIDTH:"+this.w+";  HEIGHT: "+(this.h-this.grip_h)+"; OVERFLOW: hidden; POSITION: relative;  VISIBILITY: visible;overflow:hidden;'>\n";
		divStart += "		<div onmousewheel='"+this.name+".onmouseWheel();' id=content"+this.name+" style='position:relative;'>";	
	}else if (ns4){
		divStart +="<ilayer name='nscontainer"+this.name+"' width="+this.w+" height="+(this.h-this.grip_h)+" clip='0,0,"+this.w+","+(this.h-this.grip_h)+"'>";
		divStart +="<layer name='nscontent"+this.name+"'  width="+this.w+" height="+(this.h -this.img_h)+" visibility=hidden>";

	}

	doc.write(divStart);
}
function printEndDIV_H(doc){
	var divEnd = "";

	if(iens6){
		divEnd +="	</div>";
		divEnd +="</div>";
	}else if (ns4){
		divEnd +="</layer>";
		divEnd +="</ilayer>";	
	}
	divEnd +="</td></tr>";
	divEnd +="<tr><td width="+this.w+" height="+this.img_h+">";
	divEnd +="	<table cellspacing=0 cellpadding=0 border=0>";

	divEnd +="	<tr><td width="+this.img_w+" height="+this.img_h+"><a onmousedown='"+this.name+".moveleft(true);' onmouseout='"+this.name+".cleartimer();'  onmouseup='"+this.name+".cleartimer();' onfocus='this.blur(0)'><img name=up_arrow"+this.name+" src='images/left.gif' border=0 style='cursor:hand;'></a></td>";
	divEnd +="	<td width="+(this.w-this.img_w*2)+" valign=top>";
if(iens6){
	divEnd +="<div onmousedown='"+this.name+".onmousedown_bar();'  id='div_bar"+this.name+"' style=\"background-image:url('"+this.img_root+"images/bg_h.gif');position:relative;width:"+(this.w-this.img_w*2)+";height:"+this.grip_h+"\"  onmousemove='"+this.name+".onmousemove();'>";
	divEnd +="  <div id='div_grip"+this.name+"' style=\"background-image:url('images/globe.gif');position:absolute;cursor:hand;width:"+this.grip_w+";height:"+this.grip_h+"; OVERFLOW: hidden;\"";
	divEnd +="   onmousemove='"+this.name+".onmousemove();' onmousedown='"+this.name+".onmousedown();' onmouseup='"+this.name+".onmouseup();'>";
	divEnd +="  </div>";
	divEnd +="</div>";
}else if (ns4){
	divEnd +="<ilayer id='div_bar"+this.name+"' bgcolor='000000' background='"+this.img_root+"images/bg_v.gif' width="+(this.w-this.img_w*2)+" height="+this.h+">";
	divEnd +="</ilayer>";
}
	divEnd +="  </td>";
	divEnd +="	<td width="+this.img_w+" height="+this.img_h+"><a onmousedown='"+this.name+".moveright(true);' onmouseout='"+this.name+".cleartimer();'  onmouseup='"+this.name+".cleartimer();' onfocus='this.blur(0)'><img name=down_arrow"+this.name+" src='images/right.gif' border=0 style='cursor:hand;'></a></td>";
	divEnd +="	</tr></table>";
	divEnd +="</td>";
	divEnd +="</tr></table>";
	doc.write(divEnd);
}

function onScroll(){
	return this.setrate(true);
}	

function onmousedown_bar(){
	if(!this.checkScroll()) return;
	this.mouseMoveActive = true;
	this.draggrip();
	return false;
}	

function onmousemove(){	
	if(!this.checkScroll()) return;

	if(this.mouseMoveActive){
		this.draggrip();	
	}
	return false;
}
function onmousedown(){
if(!this.checkScroll()) return;
	if(iens6){
		this.mouseStartX = mousex;
		this.mouseStartY = mousey;
		this.gripStartX  = parseInt(this.objgrip.style.left);
		this.gripStartY  = parseInt(this.objgrip.style.top);
	}else if(ns4){
		this.mouseStartX = mousex;
		this.mouseStartY = mousey;
		this.gripStartX  = parseInt(this.objgrip.left);
		this.gripStartY  = parseInt(this.objgrip.top);
	}
	this.mouseMoveActive = true;
}
function onmouseup(){
	this.mouseMoveActive = false;
}
function draggrip(){
	if(!this.checkScroll()) return;

	if(iens6){
		if(this.direction=="V"){
			var ccc = this.gripStartY + (mousey-this.mouseStartY);
			var aaa = (this.contentheight-this.h)*ccc;
			var bbb = (this.h-this.img_h*2)-this.grip_h;			
			var tmprate =  (aaa/bbb)/(this.contentheight-this.h) * 100;	
			/*
			alert("start \n" 
				+ "this.contentheight = " + this.contentheight + "\n" 
				+ "this.h = " + this.h + "\n" 
				+ "this.img_h = " + this.img_h + "\n" 
				+ "this.grip_h = " + this.grip_h + "\n" 
				+ "this.gripStartY = " + this.gripStartY + "\n" 
				+ "this.mouseStartY = " + this.mouseStartY + "\n" 
				+ "mousey = " + mousey + "\n" 
				+ "ccc = " + ccc + "\n" 
				+ "aaa = " + aaa + "\n" 
				+ "bbb = " + bbb + "\n" 
				+ "tmprate = " + tmprate + "\n" 
				+ tmprate);
			*/
			if(tmprate>100) tmprate = 100;
			if(tmprate<0)	tmprate = 0;
			this.moverate(this.xrate,tmprate);
		}else{
			var ccc = this.gripStartX + (mousex-this.mouseStartX);
			var aaa = (this.contentwidth-this.w)*ccc;
			var bbb = (this.w-this.img_w*2)-this.grip_w;			
			var tmprate =  (aaa/bbb)/(this.contentwidth-this.w) * 100;			
			if(tmprate>100) tmprate = 100;
			if(tmprate<0)	tmprate = 0;
			this.moverate(tmprate,this.yrate);
		}
	}else if(ns4){
		if(this.direction=="V"){
			var ccc = this.gripStartY + (mousey-this.mouseStartY);
			var aaa = (this.contentheight-this.h)*ccc;
			var bbb = (this.h-this.img_h*2)-this.grip_h;			
			var tmprate =  (aaa/bbb)/(this.contentheight-this.h) * 100;			
			if(tmprate>100) tmprate = 100;
			if(tmprate<0)	tmprate = 0;
			this.moverate(this.xrate,tmprate);
		}else{
			var ccc = this.gripStartX + (mousex-this.mouseStartX);
			var aaa = (this.contentwidth-this.w)*ccc;
			var bbb = (this.w-this.img_w*2)-this.grip_w;			
			var tmprate =  (aaa/bbb)/(this.contentwidth-this.w) * 100;			
			if(tmprate>100) tmprate = 100;
			if(tmprate<0)	tmprate = 0;
			this.moverate(tmprate,this.yrate);
		}
	}
}
function movegrip(){
	if(!this.checkScroll()) return;

	if(this.direction=="V") this.movegrip_V();
	else this.movegrip_H();
}
function movegrip_V(){
	if(!this.checkScroll()) return;

	var tmpy = ((this.h-this.img_h*2)-this.grip_h)/100 * this.yrate;

	if(iens6){
		this.objgrip.style.top = tmpy;
	}else if(ns4){
		this.objgrip.top = tmpy;
	}
}
function movegrip_H(){
	if(!this.checkScroll()) return;

	var tmpx = ((this.w-this.img_w*2)-this.grip_w)/100 * this.xrate;

	if(iens6){
		this.objgrip.style.left = tmpx;
	}else if(ns4){
		this.objgrip.left = tmpx;
	}	
}
function setrate(bScroll){
	if(document.all){
		if(bScroll!=null &&this.containerobj.scrollTop==0) {
			return false;
		}
		if(!this.checkScroll()) return;
		
		this.crossobj.style.top = this.y - parseInt(this.containerobj.scrollTop);
		this.y = parseInt(this.crossobj.style.top);
		this.containerobj.scrollTop = 0;

		this.xrate = Math.abs(this.x/((this.contentwidth-this.w)/100.));
		this.yrate = Math.abs(this.y/((this.contentheight-this.h)/100.));	

		this.movegrip();
	}else{	
		if(!this.checkScroll()) return;
		this.xrate = Math.abs(this.x/((this.contentwidth-this.w)/100.));
		this.yrate = Math.abs(this.y/((this.contentheight-this.h)/100.));	

		this.movegrip();
	}
	return false;
}
function moverate(xrate,yrate){
	if(!this.checkScroll()) return;
	
	var tempx;
	var tempy;

	tempx = (this.contentwidth-this.w)/100 * xrate;
	tempy = (this.contentheight-this.h)/100 * yrate;

	this.x = -tempx;
	this.y = -tempy;

	if(iens6){
		this.crossobj.style.left = parseInt(this.x);
		this.crossobj.style.top =  parseInt(this.y);
	}else{
		this.crossobj.left = parseInt(this.x);
		this.crossobj.top = parseInt(this.y);
	}

	this.setrate();
}

function movedown( recall ){
	if(!this.checkScroll()) return;

	if(this.y+this.contentheight-this.speed>this.h){
		this.y -=  this.speed;
	}else{
		this.y = (this.h-this.contentheight);
	}

	if(iens6) this.crossobj.style.top = parseInt(this.y);
	else this.crossobj.top = parseInt(this.y);

	this.setrate();
	
	if(recall==null || recall==true) this.timer = setTimeout(this.name + ".movedown(true)",this.scrolldelay); 
}

function moveup(recall){
	if(!this.checkScroll()) return;

	if(this.y+this.speed<0){
		this.y +=  this.speed;
	}else{
		this.y = 0;
	}

	if(iens6) this.crossobj.style.top = parseInt(this.y);
	else this.crossobj.top = parseInt(this.y);

	this.setrate();
	if(recall==null || recall==true) this.timer = setTimeout(this.name + ".moveup(true)",this.scrolldelay);
}

function moveright(recall){
	if(!this.checkScroll()) return;

	if(this.x+this.contentwidth-this.speed>this.w){
		this.x -=  this.speed;
	}else{
		this.x = (this.w-this.contentwidth);
	}

	if(iens6) this.crossobj.style.left = parseInt(this.x);
	else this.crossobj.left = parseInt(this.x);

	this.setrate();
	
	if(recall==null || recall==true) this.timer = setTimeout(this.name + ".moveright(true)",this.scrolldelay);
}
function cleartimer(){
	clearTimeout(this.timer);
}
function moveleft(recall){
	if(!this.checkScroll()) return;

	if(this.x+this.speed<0){
		this.x +=  this.speed;
	}else{
		this.x = 0;
	}

	if(iens6) this.crossobj.style.left = parseInt(this.x);
	else this.crossobj.left = parseInt(this.x);

	this.setrate();
	if(recall==null || recall==true) this.timer = setTimeout(this.name + ".moveleft(true)",this.scrolldelay);
}

function scrollInit(){
	if (iens6){
		this.crossobj=document.getElementById? document.getElementById("content"+this.name) : evel("document.all.content"+this.name);
		this.containerobj = document.getElementById? document.getElementById("container"+this.name) : evel("document.all.container"+this.name);

		this.contentheight=this.crossobj.offsetHeight
		this.contentwidth=this.crossobj.offsetWidth
		this.x = 0;
		this.y = 0;

		this.objgrip = document.getElementById? document.getElementById("div_grip"+this.name) : evel("document.all.img_bar"+this.name);		

		if(!this.checkScroll()){
			var objdiv_bar = document.getElementById? document.getElementById("div_bar"+this.name) : evel("document.all.div_bar"+this.name);
			var up_arrow   = document.getElementById? document.getElementById("up_arrow"+this.name) : evel("document.all.up_arrow"+this.name);
			var down_arrow = document.getElementById? document.getElementById("down_arrow"+this.name) : evel("document.all.down_arrow"+this.name);

			up_arrow.width  = 0;
			up_arrow.height = 0;
			down_arrow.width  = 0;
			down_arrow.height = 0;

			objdiv_bar.style.visibility = "hidden";

			this.objgrip.style.visibility = "hidden";
		}
	}else if (ns4){
		this.crossobj = eval("document.nscontainer"+this.name+".document.nscontent"+this.name);
		this.contentheight=this.crossobj.clip.height
		this.contentwidth=this.crossobj.clip.width
		this.x = 0;
		this.y = 0;

		this.objgrip = eval("document.div_bar" + this.name + ".document.div_grip" + this.name);			

		this.crossobj.visibility="show"
	}

	if(this.contentwidth==this.w) this.w --;
	if(this.contentheight==this.h) this.h --;

	this.moverate(0,0);

}
function checkScroll(){
	var result = false;
	
	if(this.crossobj!=null) {	
		if(this.direction=="V"){
			if(this.h < this.contentheight)	result = true;	
			else result = false;	
		}else{
			if(this.w < this.contentwidth) result = true;	
			else result = false;	
		}
	}else{
		result = false;
	}

	return result;
}


if (ns4) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)

if (iens6){
	document.onmousemove = mouseMove;
	document.onmouseup   = handlerMU;
}else{
	document.captureEvents(Event.MOUSEMOVE )
}

