private function moveAndZoomToLink(link:LinkElement,p:Person):void
{
var linkStart:int = link.getAbsoluteStart();
var textFlowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition(linkStart);
var linkPositionOnLine:int = linkStart-textFlowLine.absoluteStart;
var controllerIndex:int = textFlow.flowComposer.findControllerIndexAtPosition(linkStart);
var controller:ContainerController = textFlow.flowComposer.getControllerAt(controllerIndex);
var containerSprite:Sprite = controller.container;
var rect:Rectangle = textFlowLine.getBounds();
var atomRect:Rectangle = textFlowLine.getTextLine().getAtomBounds(linkPositionOnLine+1);
var nameWidth:Number = p.firstName.length*atomRect.width;
var globalAtomRect:Rectangle = new Rectangle(rect.x+(atomRect.x-atomRect.width),rect.y,nameWidth,rect.height);
var box:Shape = new Shape();
box.graphics.beginFill(0xff0000,0.3);
box.graphics.drawRect(globalAtomRect.x,globalAtomRect.y,globalAtomRect.width,globalAtomRect.height);
containerSprite.addChild(box);
var localPosition:Point = new Point();
localPosition.x = containerSprite.x+rect.x+globalAtomRect.x;
localPosition.y = containerSprite.y+rect.y;
/*
We're zooming in so scale the local position
*/
var scaledX:Number = localPosition.x*Config.SHIRT_ZOOM_SCALE;
var scaledY:Number = localPosition.y*Config.SHIRT_ZOOM_SCALE;
/*
We don't want the shirt to move so it is out of the viewport so calculate what this range is ...
*/
var maxMoveX:Number = (Config.SHIRT_WIDTH*Config.SHIRT_ZOOM_SCALE)-Config.VIEWPORT_WIDTH;
var maxMoveY:Number = (Config.SHIRT_HEIGHT*Config.SHIRT_ZOOM_SCALE)-Config.VIEWPORT_HEIGHT;
var newX:Number = 0-scaledX;
var newY:Number = 0-scaledY;
var centeredX:Number = newX+Config.VIEWPORT_CENTER_X;
var centeredY:Number = newY+Config.VIEWPORT_CENTER_Y;
/*
Check the shirt hasn't moved out of bounds
*/
var offsetX:Number = centeredX>0? centeredX*-1 : centeredX<0-maxMoveX? (centeredX*-1)-maxMoveX : 0;
var offsetY:Number = centeredY>0? centeredY*-1 : centeredY<0-maxMoveY? (centeredY*-1)-maxMoveY : 0;
/*
Finally, the new position is nudged so it is at the centre of the viewport space or as near as can be.
*/
moveToPointX = centeredX>0? 0 : centeredX<0-maxMoveX? centeredX+((centeredX*-1)-maxMoveX) : centeredX;
moveToPointY = centeredY>0? 0 : centeredY<0-maxMoveY? centeredY+((centeredY*-1)-maxMoveY) : centeredY;
var viewportX:Number = Config.VIEWPORT_CENTER_X+offsetX;
var viewportY:Number = Config.VIEWPORT_CENTER_Y+offsetY;
shirtMoveTo.play();
var evt:PersonSelectionEvent = new PersonSelectionEvent(PersonSelectionEvent.PERSON_SELECTION,true);
evt.viewportPoint = new Point(viewportX,viewportY);
evt.person = p;
dispatchEvent(evt);
}