/*
 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
 Code licensed under the BSD License:
 http://developer.yahoo.com/yui/license.html
 version: 3.3.0
 build: 3167
 */
YUI.add('widget-position-align',function(Y){var L=Y.Lang,ALIGN="align",BINDUI="bindUI",SYNCUI="syncUI",OFFSET_WIDTH="offsetWidth",OFFSET_HEIGHT="offsetHeight",VIEWPORT_REGION="viewportRegion",REGION="region",AlignChange="alignChange";function PositionAlign(config){if(!this._posNode){Y.error("WidgetPosition needs to be added to the Widget, before WidgetPositionAlign is added");}
Y.after(this._syncUIPosAlign,this,SYNCUI);Y.after(this._bindUIPosAlign,this,BINDUI);}
PositionAlign.ATTRS={align:{value:null},centered:{setter:"_setAlignCenter",lazyAdd:false,value:false}};PositionAlign.TL="tl";PositionAlign.TR="tr";PositionAlign.BL="bl";PositionAlign.BR="br";PositionAlign.TC="tc";PositionAlign.RC="rc";PositionAlign.BC="bc";PositionAlign.LC="lc";PositionAlign.CC="cc";PositionAlign.prototype={_syncUIPosAlign:function(){var align=this.get(ALIGN);if(align){this._uiSetAlign(align.node,align.points);}},_bindUIPosAlign:function(){this.after(AlignChange,this._afterAlignChange);},_setAlignCenter:function(val){if(val){this.set(ALIGN,{node:val===true?null:val,points:[PositionAlign.CC,PositionAlign.CC]});}
return val;},_afterAlignChange:function(e){if(e.newVal){this._uiSetAlign(e.newVal.node,e.newVal.points);}},_uiSetAlign:function(node,points){if(!L.isArray(points)||points.length!=2){Y.error("align: Invalid Points Arguments");return;}
var nodeRegion=this._getRegion(node),widgetPoint,nodePoint,xy;if(nodeRegion){widgetPoint=points[0];nodePoint=points[1];switch(nodePoint){case PositionAlign.TL:xy=[nodeRegion.left,nodeRegion.top];break;case PositionAlign.TR:xy=[nodeRegion.right,nodeRegion.top];break;case PositionAlign.BL:xy=[nodeRegion.left,nodeRegion.bottom];break;case PositionAlign.BR:xy=[nodeRegion.right,nodeRegion.bottom];break;case PositionAlign.TC:xy=[nodeRegion.left+Math.floor(nodeRegion.width/2),nodeRegion.top];break;case PositionAlign.BC:xy=[nodeRegion.left+Math.floor(nodeRegion.width/2),nodeRegion.bottom];break;case PositionAlign.LC:xy=[nodeRegion.left,nodeRegion.top+Math.floor(nodeRegion.height/2)];break;case PositionAlign.RC:xy=[nodeRegion.right,nodeRegion.top+Math.floor(nodeRegion.height/2),widgetPoint];break;case PositionAlign.CC:xy=[nodeRegion.left+Math.floor(nodeRegion.width/2),nodeRegion.top+Math.floor(nodeRegion.height/2),widgetPoint];break;default:break;}
if(xy){this._doAlign(widgetPoint,xy[0],xy[1]);}}},_doAlign:function(widgetPoint,x,y){var widgetNode=this._posNode,xy;switch(widgetPoint){case PositionAlign.TL:xy=[x,y];break;case PositionAlign.TR:xy=[x-widgetNode.get(OFFSET_WIDTH),y];break;case PositionAlign.BL:xy=[x,y-widgetNode.get(OFFSET_HEIGHT)];break;case PositionAlign.BR:xy=[x-widgetNode.get(OFFSET_WIDTH),y-widgetNode.get(OFFSET_HEIGHT)];break;case PositionAlign.TC:xy=[x-(widgetNode.get(OFFSET_WIDTH)/2),y];break;case PositionAlign.BC:xy=[x-(widgetNode.get(OFFSET_WIDTH)/2),y-widgetNode.get(OFFSET_HEIGHT)];break;case PositionAlign.LC:xy=[x,y-(widgetNode.get(OFFSET_HEIGHT)/2)];break;case PositionAlign.RC:xy=[(x-widgetNode.get(OFFSET_WIDTH)),y-(widgetNode.get(OFFSET_HEIGHT)/2)];break;case PositionAlign.CC:xy=[x-(widgetNode.get(OFFSET_WIDTH)/2),y-(widgetNode.get(OFFSET_HEIGHT)/2)];break;default:break;}
if(xy){this.move(xy);}},_getRegion:function(node){var nodeRegion;if(!node){nodeRegion=this._posNode.get(VIEWPORT_REGION);}else{node=Y.Node.one(node);if(node){nodeRegion=node.get(REGION);}}
return nodeRegion;},align:function(node,points){this.set(ALIGN,{node:node,points:points});},centered:function(node){this.align(node,[PositionAlign.CC,PositionAlign.CC]);}};Y.WidgetPositionAlign=PositionAlign;},'3.3.0',{requires:['widget-position']});
