/*
element mover 1.0
(c) 2008 Marshall (marshall@gawinet.pl)
*/

function moveH (id, moveBy, step, activator, mode, anchor, remaining) {
	var t;
	var elem=document.getElementById(id);
	if (!elem.style.right) elem.style.right=elem.offsetParent.offsetWidth-elem.offsetLeft-elem.offsetWidth+'px';

	if (!mode) mode="over";
	if (!activator) activator=id;
	if (!anchor) {
		if (elem.style.left) anchor="left";
		else anchor="right";
	}

	if (mode=="over") {
		document.getElementById(activator).onmouseover=null;
		document.getElementById(activator).onmouseout=null;
	}

	if (anchor=="left") curX=parseInt(elem.offsetLeft);
	else curX=parseInt(elem.style.right);
	if (!remaining) remaining=(moveBy>0?moveBy:(moveBy*(-1)));
	delta=(step>=remaining?remaining:step);

	if (moveBy > 0) {
		if (anchor=="left") {
			if (elem.style.position=='relative') delta-=parseInt(document.body.style.marginLeft);
			elem.style.left=curX+delta+'px';
		}
		else elem.style.right=curX+delta+'px';
	}
	else {
		if (anchor=="left") {
			if (elem.style.position=='relative') delta+=parseInt(document.body.style.marginLeft);
			elem.style.left=(curX-(delta)+'px');
		}
		else elem.style.right=curX-delta+'px';
	}
	remaining=remaining-step;
	if (remaining <= 0) {
		if (mode=="over") document.getElementById(activator).onmouseout=function() {moveH(id, moveBy*(-1), step, activator, mode, anchor);}
		if (mode=="click") document.getElementById(activator).onclick=function() {moveH(id, moveBy*(-1), step, activator, mode, anchor);}
		return true;
	}

	if (t) clearTimeout(t);
	t=setTimeout("moveH('"+id+"', "+moveBy+", "+step+", '"+activator+"', '"+mode+"', '"+anchor+"', "+remaining+")", 10);
}

function moveV (id, moveBy, step, activator, mode, anchor, remaining) {
	var t;
	var elem=document.getElementById(id);
	if (!elem.style.bottom) elem.style.bottom=elem.offsetParent.offsetHeight-elem.offsetTop-elem.offsetHeight+'px';

	if (!mode) mode="over";
	if (!activator) activator=id;
	if (!anchor) {
		if (elem.style.top) anchor="top";
		else anchor="bottom";
	}

	if (mode=="over") {
		document.getElementById(activator).onmouseover=null;
		document.getElementById(activator).onmouseout=null;
	}

	if (anchor=="top") curY=parseInt(elem.offsetTop);
	else curY=parseInt(elem.style.bottom);
	if (!remaining) remaining=(moveBy>0?moveBy:(moveBy*(-1)));
	delta=(step>=remaining?remaining:step);

	if (moveBy > 0) {
		if (anchor=="top") {
			//if (elem.style.position=='relative') delta-=parseInt(document.body.style.marginTop);
			//elem.style.top=(parseInt(elem.style.top) < 0?parseInt(elem.style.top):curY)+delta+'px';
			elem.style.top=parseInt(elem.style.top)+delta+'px';
		}
		else elem.style.bottom=curY+delta+'px';
	}
	else {
		if (anchor=="top") {
			//if (elem.style.position=='relative') delta+=parseInt(document.body.style.marginTop);
			elem.style.top=parseInt(elem.style.top)-delta+'px';
		}
		else elem.style.bottom=curY-delta+'px';
	}
	remaining=remaining-step;
	if (remaining <= 0) {
		if (mode=="over") document.getElementById(activator).onmouseout=function() {moveV(id, moveBy*(-1), step, activator, mode, anchor);}
		if (mode=="click") document.getElementById(activator).onclick=function() {moveV(id, moveBy*(-1), step, activator, mode, anchor);}
		return true;
	}

	if (t) clearTimeout(t);
	t=setTimeout("moveV('"+id+"', "+moveBy+", "+step+", '"+activator+"', '"+mode+"', '"+anchor+"', "+remaining+")", 10);
}
