var d=null;
//function CShowMap(ImgSrc,ImgOut,DivOut,Area)
function CShowMap(ImgOut,Area,HRef,Steps)
{
	var me=this;
	//me.ImgSrc=ImgSrc;
	me.ImgOut=$(ImgOut);
	//me.DivOut=$(DivOut);
	
	me.OldH=me.ImgOut.height;
	me.OldW=me.ImgOut.width;
		
	me.ImgOut.style.position='relative';
	//me.DivOut.style.overflow='hidden';
	//me.DivOut.style.height=me.OldH.toString()+'px';
	//me.DivOut.style.width=me.OldW.toString()+'px';
	
	CShowMap.prototype.MSG=function(Mes)
	{
		if(!d) return;
		d.MSG(Mes);
	}
	CShowMap.prototype.OnLoadFrame=function()
	{
		//alert('OnLoadFrame');
		location.href=HRef;
	}
	CShowMap.prototype.GotoLink=function()
	{
		me.MSG(HRef);
		var f=document.createElement('iframe');
		document.body.appendChild(f);
		if(f.contentDocument)
		{
			f.onload=me.OnLoadFrame;
			f.src=HRef;
		}
		else
			me.OnLoadFrame();	
		
	}
	CShowMap.prototype.OnLoadImage=function()
	{
		//alert(ImgSrc);
		/*me.ImgOut.style.left='0px';
		me.ImgOut.style.top='0px';
		me.ImgOut.width=me.OldW;
		me.ImgOut.height=me.OldH;
		
		me.ImgOut.src=ImgSrc;
		document.body.removeChild(me.CurDiv);
		*/
	}
	CShowMap.prototype.Ret=function()
	{
		return false;
	}
	CShowMap.prototype.LoadImage=function()
	{
		me.MSG('LoadImage');
		
		/*
		me.CurDiv=document.createElement('div');
		me.CurDiv.style.display='none';
		
		me.ImgNew=document.createElement('img');
		document.body.appendChild(me.CurDiv);
		
		me.CurDiv.appendChild(me.ImgNew);
		me.ImgNew.onload=me.OnLoadImage;		
		me.ImgNew.src=ImgSrc;
		*/
		//me.MSG(me.CurDiv.innerHTML);
		//for(var p in me.CurDiv) me.MSG(p+'='+me.CurDiv[p]);
	}
	CShowMap.prototype.MagImage=function()
	{	
		var coords;
		var steps=Steps;
		coords=Area.coords.split(",");
		var x1,x2,y1,y2,x,y,x0,y0;
		//x0=me.OldW/2;
		//y0=me.OldH/2;
		
		x1=parseInt(coords[0]);
		x2=parseInt(coords[2]);
		y1=parseInt(coords[1]);
		y2=parseInt(coords[3]);
		
		//x=(x1+x2)/2;
		//y=(y1+y2)/2;
		
		//var move=Math.sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
		
		
		me.MaxW=me.OldW*me.OldW/(x2-x1);
		me.MaxH=me.OldH*me.OldH/(y2-y1);
		me.MaxTop=-y1*me.OldH/(y2-y1);;
		me.MaxLeft=-x1*me.OldW/(x2-x1);;
		
		me.DeltaTop=me.MaxTop/steps;
		me.DeltaLeft=me.MaxLeft/steps;
		me.DeltaW=(me.MaxW-me.OldW)/steps;
		me.DeltaH=(me.MaxH-me.OldH)/steps;
		
		me.MSG("me.DeltaTop="+me.DeltaTop);
		me.MSG("me.DeltaLeft="+me.DeltaLeft);
		//me.MSG("x="+x);
		//me.MSG("y="+y);
		//me.MSG("move="+move);
		//me.MSG("x0="+x0);
		//me.MSG("y0="+y0);
		
		me.CurW=me.OldW;
		me.CurH=me.OldH;
		me.CurTop=0;
		me.CurLeft=0;
		
		me.OldT=setTimeout(me.MagImage_,30);
		me.MSG(Area.coords);
	}
	CShowMap.prototype.MagImage_=function()
	{
		clearTimeout(me.OldT);
		
		me.CurH+=me.DeltaH;
		me.CurW+=me.DeltaW;
		
		me.CurTop+=me.DeltaTop;
		me.CurLeft+=me.DeltaLeft;
		
		if(me.CurW>me.MaxW)
		{
			me.MSG("me.CurH="+me.CurH);
			me.MSG("me.CurW="+me.CurW);
			me.MSG("me.CurTop="+me.CurTop);
			me.MSG("me.CurLeft="+me.CurLeft);
			
			me.MSG("me.MaxH="+me.MaxH);
			me.MSG("me.MaxW="+me.MaxW);
			me.MSG("me.MaxTop="+me.MaxTop);
			me.MSG("me.MaxLeft="+me.MaxLeft);
			
			me.CurH=me.MaxH;
			me.CurW=me.MaxW;
		
			me.CurTop=me.MaxTop;
			me.CurLeft=me.MaxLeft;
		}
		var delta=5;
		//me.CurH+=2*delta;
		//me.CurW+=2*delta;
		//me.CurTop+=Math.floor(me.DeltaTop*delta);
		//me.CurLeft+=Math.floor(me.DeltaLeft*delta);
		me.ImgOut.style.left=me.CurLeft.toString()+'px';
		me.ImgOut.style.top=me.CurTop.toString()+'px';
		me.ImgOut.width=me.CurW;
		me.ImgOut.height=me.CurH;
		
		if(me.CurW>=me.MaxW)
		{
			//me.LoadImage();
			me.GotoLink();
			return;
		}
		me.OldT=setTimeout(me.MagImage_,30);
	}
	me.MagImage();
	
	//me.LoadImage();
	
}
function init_debug()
{
	//d=new CDebug(300,300,600,0,"Map",10000);
}
//addEvent(window,'load',init_debug,false);

