/*
	Hand Tool
	
	(c) Gosha Bine, 2001
	http://www.stereofrog.com
*/
	
var _h={
	image:"hand.gif",
	width:16,
	height:16,
	modifiers:0,
	notags:"<A><INPUT><SELECT>",
	xgap:-10,
	ygap:-10,
	alwaysVisible:1
}

function cbWindow(){
	this.fail=1;
	var n=window.navigator,an=n.appName.toLowerCase(),ag=n.userAgent.toLowerCase();
	if(ag.indexOf("win")<0 || ag.indexOf("opera")>=0)
		return;
	var k=0,v_ie=0,v_nn=0;
	if((k=ag.indexOf("msie"))>=0) v_ie=parseFloat(ag.substring(k+5));
		else if(an.indexOf("netscape")>=0) v_nn=parseFloat(n.appVersion);
	_ie=_nn=_mz=0;
	if(v_ie>=4)_ie=1;
		else if(v_nn>=5) _mz=1;
			else if(v_nn>=4) _nn=1;
				else return;
	this.fail=0;
}
cbWindow.prototype.evtc=function(e){
	e=window.event||e;
	this.el=_ie?e.srcElement:e.target;
	this.btn=_ie?e.button:e.which;
	this.mkey=_nn?(e.modifiers):(e.altKey+e.ctrlKey*2+e.shiftKey*4);
	this.key=_ie?e.keyCode:e.which;
	this.cx=_nn?(e.pageX-pageXOffset):e.clientX;
	this.cy=_nn?(e.pageY-pageYOffset):e.clientY;
	this.x=e.screenX;
	this.y=e.screenY;
	this.miw=this.cx>0&&this.cx<this.wp(0)&&this.cy>0&&this.cy<this.wp(1);
}

cbWindow.prototype.wp=function(k){
	var b=document.documentElement||document.body;
	if(k==0) return _ie?b.clientWidth:(innerWidth-16);
	if(k==1) return _ie?b.clientHeight:(innerHeight-16);
	if(k==2) return _ie?b.scrollLeft:pageXOffset;
	if(k==3) return _ie?b.scrollTop:pageYOffset;
	return 0;
}

cbWindow.prototype.scroll=function(x,y){
	if(_mz) {
		window.scrollTo(x,pageYOffset);
		window.scrollTo(pageXOffset,y);
	} else window.scrollTo(x,y);
}

cbWindow.prototype.onevt=function(evt,proc){
	if(_ie) document.body[evt]=proc;
		else if(_mz||_nn) window[evt]=proc;
}

function cbLayer(id,nsc){
	this.o=null;
	this.va=[_nn?"hide":"hidden",_nn?"show":"visible"];
	var d=document;
	if(_ie) this.o=d.all[id];
	if(_mz) this.o=d.getElementById(id);
	if(_nn) this.o=d[nsc||"layers"][id];
	if(this.o) this.s=(_nn)?this.o:this.o.style;
	this.fail=(this.o==null);
}

cbLayer.prototype.move=function(x,y){
	if(_ie) with(this.s)pixelLeft=x,pixelTop=y;
	if(_mz) with(this.s)left=x,top=y;
	if(_nn) this.s.moveTo(x,y);
}

cbLayer.prototype.css=function(p,v,nsp){
	if(!_nn) nsp="";
	this.s[nsp||p]=v;
}

cbLayer.prototype.show=function(b){
	this.css("visibility",this.va[b+0]);
}

//------------------------------------------------------------------------------------------------------------

function sfmt(fmt){
	for(var a=sfmt.arguments,ii=1;ii<a.length;ii++)
		fmt=fmt.replace(/~/,a[ii]);
	return fmt;
}
	
function _hinit(){
	window._hw=new cbWindow();if(_hw.fail)return;
	_h.id="HANDTOOL";
	var w=_h.width, h=_h.height, ws="width", hs="height";
	document.write(sfmt(
		_nn?"<layer name=\"~\" ~=~ ~=~ ~=hide>~</layer>":"<div id=\"~\" style='position:absolute;~:~px;~:~px;~:hidden'>~</div>",
		_h.id, ws, w, hs, h, "visibility", sfmt("<img border=0 src=\"~\" ~=~ ~=~>", _h.image, ws, w, hs, h)));
	window._hp=new cbLayer(_h.id);if(_hp.fail)return;
	_hw.onevt("onmousedown",_hdown);
	_hw.onevt("onmouseup",_hup);
	if(_nn) 
		window.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

function _hdown(e){
	_hw.evtc(e);
	if(_hw.btn!=1 || _hw.mkey!=_h.modifiers || !_hw.miw)
		return true;
	if(_ie||_mz){
		for(var el=_hw.el;el;el=_ie?el.parentElement:el.parentNode)
			if(_h.notags.indexOf("<"+(el.tagName||"")+">")>=0) return true;
	} else if (_nn && _hw.el && _hw.el.href) return true;
	_hp.css("zIndex",100);
	_hw.onevt("onmousemove",_hmove);
	_h.ax=_hw.x+_hw.wp(2);
	_h.ay=_hw.y+_hw.wp(3);
	_h.mc=100;
	_h.tmr=setInterval("_hupdate()",3);
	return false;
}

function _hmove(e){
	_h.mc=0;
	_hw.evtc(e);
	_hp.show(_h.alwaysVisible);
	if(!_hw.btn) _hup();
	return false;
}

function _hupdate(){
	if(_hw.miw){
		_hw.scroll(_h.ax-_hw.x,_h.ay-_hw.y)
		_hp.move(_h.xgap+_hw.cx+_hw.wp(2), _h.ygap+_hw.cy+_hw.wp(3));
		_hp.show(_h.alwaysVisible||(++_h.mc>3));
	}
}

function _hup(){
	_hp.show(0);
	_hw.onevt("onmousemove",null);
	clearInterval(_h.tmr);
}

_hinit()
