﻿var maxZIndex=10;

function imageAnimation(divID,obName,plSpeed,plStyle)
{
	this.div = document.getElementById(divID);
	this.tmIntr=0;
	this.id=obName;
	this.playSpeed=plSpeed;
	this.playStyle=plStyle;
	this.divLeft=document.getElementById(divID).style.left;
	this.divTop=document.getElementById(divID).style.top;
}

function imageShow(ob,maxWidth,maxHeight)
{
	var wIncr, hIncr;
	var divTopIncr,divLeftIncr;
	clearInterval(ob.tmIntr);
	wIncr=Math.ceil((maxWidth-parseInt(ob.div.style.width,10))/ob.playSpeed);
	hIncr=Math.ceil((maxHeight-parseInt(ob.div.style.height,10))/ob.playSpeed,10);
	wIncr=parseInt(ob.div.style.width,10)+wIncr;
	hIncr=parseInt(ob.div.style.height,10)+hIncr;
	if(wIncr>maxWidth)
		wIncr=maxWidth;
	if(hIncr>maxHeight)
		hIncr=maxHeight
	divLeftIncr=wIncr-parseInt(ob.div.style.width,10);
	divTopIncr=hIncr-parseInt(ob.div.style.height,10);

	ob.div.style.width=wIncr + "px"
	ob.div.style.height=hIncr + "px"
	ob.div.style.zIndex=parseInt(ob.div.style.zIndex) + maxZIndex + 1;
	maxZIndex++;


	if(wIncr>=maxWidth && hIncr>=maxHeight)
		return;

	if(ob.playStyle==1)
		ob.div.style.top=parseInt(ob.div.style.top,10)-divTopIncr+"px";
	else if(ob.playStyle==2)
		ob.div.style.left=parseInt(ob.div.style.left,10)-divLeftIncr+"px";
	else if(ob.playStyle==3)
	{
		ob.div.style.top=parseInt(ob.div.style.top,10)-divTopIncr+"px";
		ob.div.style.left=parseInt(ob.div.style.left,10)-divLeftIncr+"px";
	}
	else if(ob.playStyle==4 && divLeftIncr!=maxWidth)
		ob.div.style.left=parseInt(ob.div.style.left,10)-Math.ceil((divLeftIncr/2))+"px";
	else if(ob.playStyle==5 && divTopIncr!=maxHeight)
		ob.div.style.top=parseInt(ob.div.style.top,10)-Math.ceil((divTopIncr/2))+"px";
	else if(ob.playStyle==6)
	{
		if(divLeftIncr!=maxWidth)
			ob.div.style.left=parseInt(ob.div.style.left,10)-Math.ceil((divLeftIncr/2))+"px";
		if(divTopIncr!=maxHeight)
			ob.div.style.top=parseInt(ob.div.style.top,10)-Math.ceil((divTopIncr/2))+"px";
	}


	ob.tmIntr=setInterval("imageShow("+ob.id+","+maxWidth+","+maxHeight+")",1);
}

function imageHide(ob,minWidth,minHeight)
{
	var wIncr, hIncr;
	var divTopIncr,divLeftIncr;
	clearInterval(ob.tmIntr);
	wIncr=Math.ceil((parseInt(ob.div.style.width,10)-minWidth)/ob.playSpeed);
	hIncr=Math.ceil((parseInt(ob.div.style.height,10)-minHeight)/ob.playSpeed,10);
	wIncr=parseInt(ob.div.style.width,10)-wIncr;
	hIncr=parseInt(ob.div.style.height,10)-hIncr;
	if(wIncr<minWidth)
		wIncr=minWidth;
	if(hIncr<minHeight)
		hIncr=minHeight
	
	divLeftIncr=parseInt(ob.div.style.width,10)-wIncr;
	divTopIncr=parseInt(ob.div.style.height,10)-hIncr;
	

	ob.div.style.width=wIncr + "px"
	ob.div.style.height=hIncr + "px"
	ob.div.style.zIndex=maxZIndex - 1;
	if(parseInt(ob.div.style.zIndex,10)<1)
		ob.div.style.zIndex=1;

	if(wIncr<=minWidth && hIncr<=minHeight)
	{
		ob.div.style.top=ob.divTop;
		ob.div.style.left=ob.divLeft;
		return;
	}
	if(ob.playStyle==1)
		ob.div.style.top=parseInt(ob.div.style.top,10)+divTopIncr+"px";
	else if(ob.playStyle==2)
		ob.div.style.left=parseInt(ob.div.style.left,10)+divLeftIncr+"px";
	else if(ob.playStyle==3)
	{
		ob.div.style.top=parseInt(ob.div.style.top,10)+divTopIncr+"px";
		ob.div.style.left=parseInt(ob.div.style.left,10)+divLeftIncr+"px";
	}
	else if(ob.playStyle==4)
	{
		if(parseInt(ob.div.style.left,10)>parseInt(ob.divLeft,10))
			ob.div.style.left=ob.divLeft;
		else
			ob.div.style.left=parseInt(ob.div.style.left,10)+Math.ceil((divLeftIncr/2))+"px";
	}
	else if(ob.playStyle==5)
	{
		if(parseInt(ob.div.style.top,10)>parseInt(ob.divTop,10))
			ob.div.style.top=ob.divTop;
		else
			ob.div.style.top=parseInt(ob.div.style.top,10)+Math.ceil((divTopIncr/2))+"px";
	}
	else if(ob.playStyle==6)
	{
		if(parseInt(ob.div.style.left,10)>parseInt(ob.divLeft,10))
			ob.div.style.left=ob.divLeft;
		else
			ob.div.style.left=parseInt(ob.div.style.left,10)+Math.ceil((divLeftIncr/2))+"px";
		if(parseInt(ob.div.style.top,10)>parseInt(ob.divTop,10))
			ob.div.style.top=ob.divTop;
		else
			ob.div.style.top=parseInt(ob.div.style.top,10)+Math.ceil((divTopIncr/2))+"px";
	}
	ob.tmIntr=setInterval("imageHide("+ob.id+","+minWidth+","+minHeight+")",1);
}

function imagePlayStyle()
{
	
}