function AnchoredInterface(){this.elemId=null;this.anchorId=null;this.disableScroll=false;this.getAnchorX=AnchoredInterface_GetAnchorX;this.getAnchorY=AnchoredInterface_GetAnchorY;this.getAnchorZ=AnchoredInterface_GetAnchorZ;this.getAnchorWidth=AnchoredInterface_GetAnchorWidth;this.getAnchorHeight=AnchoredInterface_GetAnchorHeight;this.getElemWidth=AnchoredInterface_GetElemWidth;this.getElemHeight=AnchoredInterface_GetElemHeight;this.getAnchorPosition=AnchoredInterface_GetAnchorPosition;this.setAnchor=AnchoredInterface_SetAnchor;this.alignElement=AnchoredInterface_AlignElement;}
AnchoredInterface.prototype=new Interface;AnchoredInterface.prototype.constructor=AnchoredInterface;AnchoredInterface.superclass=Interface.prototype;AnchoredInterface.ALIGN={RIGHT_TOP:1,RIGHT_BOTTOM:2,LEFT_BOTTOM:3,LEFT_TOP:4};function AnchoredInterface_GetAnchorX(){return DomUtils.getElementLeft(document.getElementById(this.anchorId));}
function AnchoredInterface_GetAnchorY(){return DomUtils.getElementTop(document.getElementById(this.anchorId));}
function AnchoredInterface_GetAnchorZ(){return DomUtils.getZIndex(document.getElementById(this.anchorId));}
function AnchoredInterface_GetAnchorWidth(){return DomUtils.getElementWidth(document.getElementById(this.anchorId));}
function AnchoredInterface_GetAnchorHeight(){return DomUtils.getElementHeight(document.getElementById(this.anchorId));}
function AnchoredInterface_GetElemWidth(){return DomUtils.getElementWidth(document.getElementById(this.elemId));}
function AnchoredInterface_GetElemHeight(){return DomUtils.getElementHeight(document.getElementById(this.elemId));}
function AnchoredInterface_GetAnchorPosition(){var pos=false;var elem=document.getElementById(this.elemId);if(!elem)throw new Error('Unable to find element: '+this.elemId);var anchor=document.getElementById(this.anchorId);if(!anchor)throw new Error('Unable to find anchor element: '+this.anchorId);var wWidth=parseInt(DomUtils.getWindowWidth(window));var wHeight=parseInt(DomUtils.getWindowHeight(window));var scrollX=parseInt(DomUtils.getWindowScrollX(window));var scrollY=parseInt(DomUtils.getWindowScrollY(window));var aWidth=parseInt(DomUtils.getElementWidth(anchor));var aHeight=parseInt(DomUtils.getElementHeight(anchor));var aX=parseInt(DomUtils.getElementLeft(anchor));var aY=parseInt(DomUtils.getElementTop(anchor));var aWidth=parseInt(DomUtils.getElementWidth(anchor));var aHeight=parseInt(DomUtils.getElementHeight(anchor));var eWidth=parseInt(DomUtils.getElementWidth(elem));var eHeight=parseInt(DomUtils.getElementHeight(elem));if(this.disableScroll){var enoughRoomOnTop=(aY-scrollY>eHeight?true:false);var enoughRoomOnBottom=(wHeight+scrollY-aHeight-aY>eHeight?true:false);var enoughRoomOnLeft=(aX-scrollX+aWidth>eWidth?true:false);var enoughRoomOnRight=(wWidth-aX+scrollX>eWidth?true:false);if(enoughRoomOnBottom&&enoughRoomOnRight){pos=AnchoredInterface.ALIGN.LEFT_TOP;}else if(enoughRoomOnTop&&enoughRoomOnRight){pos=AnchoredInterface.ALIGN.LEFT_BOTTOM;}else if(enoughRoomOnTop&&enoughRoomOnLeft){pos=AnchoredInterface.ALIGN.RIGHT_BOTTOM;}else if(enoughRoomOnBottom&&enoughRoomOnLeft){pos=AnchoredInterface.ALIGN.RIGHT_TOP;}else if(!enoughRoomOnRight){pos=AnchoredInterface.ALIGN.LEFT_TOP;}else{pos=AnchoredInterface.ALIGN.LEFT_TOP;}
return pos;}else{var not_enough_right=((aX-scrollX)+eWidth)-wWidth;var not_enough_left=eWidth-(aX-scrollX);var not_enough_absolute_left=eWidth-aX;var not_enough_bottom=((aY-scrollY)+eHeight)-wHeight;var not_enough_top=eHeight-(aY-scrollY);var not_enough_absolute_top=eHeight-aY;var horiz='';var vertic='';var ss=10;if(not_enough_right<=0||not_enough_right<not_enough_left||not_enough_absolute_left>0){horiz='right';if(not_enough_right>0){for(var i=0;i<=(not_enough_right/(ss*2))+1;i++){setTimeout('window.scroll(parseInt(DomUtils.getWindowScrollX(window))+'+ss+',parseInt(DomUtils.getWindowScrollY(window)))',100);}}
}else{horiz='left';if(not_enough_left>0&&!this.disableScroll){for(var i=0;i<=(not_enough_left/(ss*2))+1;i++){setTimeout('window.scroll(parseInt(DomUtils.getWindowScrollX(window))-'+ss+',parseInt(DomUtils.getWindowScrollY(window)))',100);}}}
if(not_enough_top<=0||(not_enough_top<not_enough_bottom&&not_enough_absolute_top<=0)){vertic='top';if(not_enough_top>0&&!this.disableScroll){for(var i=0;i<=(not_enough_top/(ss*2))+1;i++){setTimeout('window.scroll(parseInt(DomUtils.getWindowScrollX(window)),parseInt(DomUtils.getWindowScrollY(window))-'+ss+')',100);}}
}else{vertic='bottom';if(not_enough_bottom>0&&!this.disableScroll){for(var i=0;i<=(not_enough_bottom/(ss*2))+1;i++){setTimeout('window.scroll(parseInt(DomUtils.getWindowScrollX(window)),parseInt(DomUtils.getWindowScrollY(window))+'+ss+')',100);}}}
if(horiz=='right'&&vertic=='top')pos=AnchoredInterface.ALIGN.RIGHT_TOP;else if(horiz=='right'&&vertic=='bottom')pos=AnchoredInterface.ALIGN.RIGHT_BOTTOM;else if(horiz=='left'&&vertic=='top')pos=AnchoredInterface.ALIGN.LEFT_TOP;else if(horiz=='left'&&vertic=='bottom')pos=AnchoredInterface.ALIGN.LEFT_BOTTOM;return pos;}}
function AnchoredInterface_SetAnchor(anchor){this.anchorId=anchor.id;}
function AnchoredInterface_AlignElement(pos){var elem=document.getElementById(this.elemId);if(!elem)throw new Error('Unable to find element: '+this.elemId);var anchor=document.getElementById(this.anchorId);if(!anchor)throw new Error('Unable to find anchor element: '+this.anchorId);pos=pos||this.getAnchorPosition();var aLeft=DomUtils.getElementLeft(anchor);var aTop=DomUtils.getElementTop(anchor);var aHeight=DomUtils.getElementHeight(anchor);var aWidth=DomUtils.getElementWidth(anchor);var eHeight=DomUtils.getElementHeight(elem);var eWidth=DomUtils.getElementWidth(elem);switch(pos){case AnchoredInterface.ALIGN.RIGHT_TOP:elem.style.left=parseInt(aLeft-eWidth+aWidth)+'px';elem.style.top=parseInt(aTop+aHeight)+'px';break;case AnchoredInterface.ALIGN.RIGHT_BOTTOM:elem.style.left=parseInt(aLeft-eWidth+aWidth)+'px';elem.style.top=parseInt(aTop+aHeight)+'px';break;case AnchoredInterface.ALIGN.LEFT_TOP:elem.style.left=parseInt(aLeft)+'px';elem.style.top=parseInt(aTop+aHeight)+'px';break;case AnchoredInterface.ALIGN.LEFT_BOTTOM:default:elem.style.left=parseInt(aLeft)+'px';elem.style.top=parseInt(aTop-eHeight)+'px';break;}
elem=null;anchor=null;}

