var tagTimer=0;
var tagMaxSteps=10;
var tagCurHeight=1000;
var tagCurObj=null;
var tagObjDebug=null;

function createTagImage(obj,src,url,tg,w,h){
	var d=document.createElement("DIV");
	d.onmouseout=hideTagImage;	
	var x=0;
	var y=0;
	var o=obj;
	while(o){
		x+=parseInt(o.offsetLeft);
		y+=parseInt(o.offsetTop);
		o=o.offsetParent;
	}
	d.centerX=x+obj.offsetWidth/2;
	d.centerY=y+obj.offsetHeight/2;
	d.style.display="none";
	d.style.top=y+"px";
	d.style.left=x+"px";
	d.style.zIndex=tagCurHeight++;
	d.style.position="absolute";
	d.style.overflow="hidden";
	d.finw=w;
	d.finh=h;
	var o=document.createElement("IMG");
	o.src=src;
	o.border=0;
	if(url){
		var l=document.createElement("A");
		l.href=url;
		l.target=tg;
		l.appendChild(o);
		d.appendChild(l);		
	} else {
		d.appendChild(o);
	}

	d.childPic=o;
	o.width=d.style.width=d.startw=obj.offsetWidth;
	o.height=d.style.height=d.starth=obj.offsetHeight;
	document.body.appendChild(d);
	return d;
}

function debugTag(str){
	if(!tagObjDebug){
		tagObjDebug=document.createElement("DIV");
		tagObjDebug.style.top=0;
		tagObjDebug.style.left=0;
		tagObjDebug.style.width=300;
		tagObjDebug.style.height=200;
		tagObjDebug.style.position="absolute";
		tagObjDebug.style.zIndex=900;
		tagObjDebug.style.overflow="auto";
		tagObjDebug.style.backgroundColor="#FFFFFF";
		tagObjDebug.style.color="#000000";
		document.body.appendChild(tagObjDebug);
	}
	tagObjDebug.innerHTML+=str+"<br>";
}

function showTagImage(obj,src,url,tg,w,h){
	if(!obj.tagObj) obj.tagObj=createTagImage(obj,src,url,tg,w,h);
	var d=obj.tagObj;
	if(tagCurObj && tagCurObj!=d) tagCurObj.onmouseout();
	tagCurObj=d;
	d.step=tagMaxSteps;
	d.childPic.width=d.style.width=d.startw;
	d.childPic.height=d.style.height=d.starth;
	d.style.display="block";
	reposTagImage(d);
	var f=function(){
		if(tagCurObj!=d){
			if(d.tagTimer) clearInterval(d.tagTimer);
			d.tagTimer=0;
			d.style.display="none";
			return;
		}

		d.step--;
		if(d.step<0){
			d.style.width=d.childPic.width=d.finw;	
			d.style.height=d.childPic.height=d.finh;	
			clearInterval(d.tagTimer);
			d.tagTimer=0;
		} else {
			var f1=d.step/tagMaxSteps;			
			var f2=1-f1;
			var w=Math.floor(d.startw*f1+d.finw*f2);
			var h=Math.floor(d.starth*f1+d.finh*f2);
			d.style.width=d.childPic.width=w;	
			d.style.height=d.childPic.height=h;	
		};
		reposTagImage(d);
	}
	d.tagTimer=setInterval(f,10);
}

function reposTagImage(obj){
	obj.style.left=Math.floor(obj.centerX-parseInt(obj.style.width)/2);
	obj.style.top=Math.floor(obj.centerY-parseInt(obj.style.height)/2);
}

function hideTagImage(){
	if(tagCurObj==this) tagCurObj=null;
	this.style.display="none";
}
