var UJC = {
	sid:'ujc_',
	id:0
};
UJC.EF=function(){};

function UJ() {
}
UJ.box=function(){
	var top = document.documentElement.scrollTop;
	var left = document.documentElement.scrollLeft;
	var height = document.documentElement.clientHeight;
	var width = document.documentElement.clientWidth;
	if (top==0 && left==0 && height==0 && width==0) {
		top = document.body.scrollTop;
		left = document.body.scrollLeft;
		height = document.body.clientHeight;
		width = document.body.clientWidth;
	}
	return { t:top,l:left,h:height,w:width } ;
};
UJ.bug=function(s) {
	var l = document.createElement('li');
	var d = $('bug');
	d.appendChild(l);
	l.innerHTML=s;
};
UJ.e=function(e){
	e=e||U.W.event;
	var d=UJ.box();
	var x=e.pageX||(e.clientX+d.l),y=e.pageY||(e.clientY+d.t);
	return { x:x,y:y } ;
};
UJ.gId=function(){
	return UJC.sid+(++UJC.id);
};

UJ.cAlt=function(c){
	this.c=c.container,this.position=c.position?c.position:'default',this.targets=[],this.over=c.over?c.over:UJC.EF,this.outer=c.outer?c.outer:UJC.EF;
	this.init=function(){
	};
	this.addTarget=function(c){
		_me.targets[_me.targets.length]=c;
	};
	this.initTargets=function(c){
		_me.targets=c;
	};
	this.toTags=function(t,o){
		if(typeof o=='undefined') o=U.D;
		else o=$(o);
		var a=o.getElementsByTagName(t);
		for(var l=a.length,i=0;i<l;i++){
			var n=a[i].id;
			if(typeof n=='undefined'||n=='') {
				n=UJ.gId();
				a[i].id=n;
				a[i].setAttribute('id',n);
			}
			_me.targets[_me.targets.length]=n;
		}
	};
	this._on=function(){
		_me.targets=_me.targets.uniq();
		for(var l=_me.targets.length,i=0;i<l;i++){
			$(_me.targets[i]).on({
				'mouseover':function(e){
					_me.show(e);
					_me.over();
				},
				'mouseout':function(e){
					_me.hide();
					_me.outer();
				}
			});
		}
	};
	this.show=function(e){
		var p=UJ.e(e),d=UJ.box(),x=p.x,y=p.y;
		var o=$(_me.c);
		if(o==null) return false;
		var s=Event.element(e).getAttribute('_alt');
		if(s==null) return false;
		o.sh(s);
		o.show();
		o.box();
		if(_me.position=='fixed'){
			var _x=_y=0;
		}else{
			var _x=x+5,_y=y+5;
			if(_x+o.width>d.w+d.l) _x-=(o.width+10);
			if(_y+o.height>d.h+d.t) _y-=(o.height+10);
			if(_x<0) _x=0;
			if(_y<0) _y=0;
		}
		o.setStyle({ 'left':_x+'px', 'top':_y+'px' });
		//o.sh(s+':'+_x+'-'+_y);
		o=null;
	};
	this.hide=function(){
		var o=$(_me.c);
		if(o==null) return false;
		o.hide();
		o=null;
	};
	this.reader=function(){
		this._on();
	};
	var _me=this;
	this.init();
};