var iPasos;
var oTimer;
var oDvDest;
var oDvMov;
var oDvShad;
var iDistIniX;
var iDistIniY;
var iSeg;
var iInter;

function ActivarPubMov(aDistIniX, aDistIniY, aSeg, aInter, delay){
	iDistIniX = aDistIniX;
	iDistIniY = aDistIniY;	
	iSeg = aSeg;
	iInter = aInter;
	oTimer = window.setInterval("IniPubMov()", delay*1000 );
}

function IniPubMov(){
	window.clearInterval(oTimer);
	ActPubMov();
}

function ActPubMov(){	
	if (document.cookie.indexOf('IsPostBack=1') < 0)
	{
		document.cookie = 'IsPostBack=20';
		iSegundos = iSeg;
		iIntervalo = iInter;
		iPasos = Math.round((iSegundos * 1000) / iIntervalo);
		oDvMov = document.getElementById("dvPubMov");
		oDvDest = document.getElementById("dvPubButton");
		oDvShad = document.getElementById("dvPubBorder");
		oDvDest.style.width = document.getElementById("dvPubTabla").offsetWidth + "px";
		GetPos(oDvDest);
		oDvMov.style.left = (oDvDest._PMedioX - parseInt(oDvMov.offsetWidth / 2) + iDistIniX) + "px";
		oDvMov.style.top = (oDvDest._PMedioY - parseInt(oDvMov.offsetHeight / 2) + iDistIniY) + "px";
		oDvMov.style.visibility = "visible";
		oTimer = window.setInterval("MovElem()", iIntervalo );
	}
	else {
		oDvDest = document.getElementById("dvPubButton");  
		oDvDest.style.visibility = "hidden";
	}
}

function MovElem(){
	var iMovX;
	var iMovY;
	if (iPasos > 1)	{
		iMovX = Math.round(parseFloat(oDvDest._PMedioX - parseInt(oDvMov.style.left) - parseInt(oDvMov.offsetWidth / 2)) / parseFloat(iPasos));
		iMovY = Math.round(parseFloat(oDvDest._PMedioY - parseInt(oDvMov.style.top) - parseInt(oDvMov.offsetHeight / 2)) / parseFloat(iPasos));
	}
	else{
	
	iMovX = (oDvDest._PMedioX);
	iMovY = (oDvDest._PMedioY);
		
	}
	oDvMov.style.left = (parseInt(oDvMov.style.left) + iMovX) + "px";
	oDvMov.style.top = (parseInt(oDvMov.style.top) + iMovY) + "px";
	iPasos--;
	if (iPasos <= 0) {
		window.clearInterval(oTimer);
		iPasos = -1;
		oDvShad.style.width = oDvMov.offsetWidth + "px";
		oDvShad.style.height = oDvMov.offsetHeight + "px";
		oDvShad.style.top = oDvMov.style.top;
		oDvShad.style.left = oDvMov.style.left;
		oDvShad.style.visibility = "hidden";
		oDvMov.style.visibility = "hidden";
		//oTimer = window.setInterval("RedShad()", 1);
	}
}

function RedShad(){
	var iRedX = 0;
	var iRedY = 0;
	if (iPasos > 0){
		iRedX = (Math.round((parseInt(oDvShad.style.width) - oDvDest.offsetWidth) / iPasos));
		if (Math.abs(iRedX) > 2){
			iRedX = iRedX - (iRedX % 2);
			oDvShad.style.width = (parseInt(oDvShad.style.width) - iRedX) + "px";
			oDvShad.style.left = (parseInt(oDvShad.style.left) + (iRedX / 2)) + "px";
		}
		iRedY = (Math.round((parseInt(oDvShad.style.height) - oDvDest.offsetHeight) / iPasos));
		if (Math.abs(iRedY) > 2) {
			iRedY = iRedY - (iRedY % 2);
			oDvShad.style.height = (parseInt(oDvShad.style.height) - iRedY) + "px";
			oDvShad.style.top = (parseInt(oDvShad.style.top) + (iRedY / 2)) + "px";
		}
	}
	else	{
		window.clearInterval(oTimer);
		oDvDest.style.visibility = "hidden";
		oDvShad.style.visibility = "hidden";
	}
	iPasos--;
}

function GetPos(xoElem){
	var bEsIE = (navigator.userAgent.toLowerCase().indexOf("msie") > 0);
	var iPosX = 0;
	var iPosY = 0;
	var oElem = xoElem;
	if (oElem.offsetParent){
		while (oElem.offsetParent)	{
			iPosX += oElem.offsetLeft;
			iPosY += oElem.offsetTop;
			if (oElem.tagName == "TABLE" && bEsIE && parseInt(0 + oElem.border) > 0){
				iPosX++;
				iPosY++;
			}
			oElem = oElem.offsetParent;
		}
	}
	else {
		if (oElem.x && oElem.y) {
			iPosX = oElem.x;
			iPosY = oElem.y;
		}
	}
	iPosX += parseInt(xoElem.offsetWidth / 2);
	iPosY += parseInt(xoElem.offsetHeight / 2);
	xoElem._PMedioX = iPosX;
	xoElem._PMedioY = iPosY;
}
