/*
YUI 3.6.0pr3 (build 1)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("widget-modality",function(c){var p="widget",q="renderUI",f="bindUI",k="syncUI",u="boundingBox",m="contentBox",r="visible",e="zIndex",l="Change",i=c.Lang.isBoolean,s=c.ClassNameManager.getClassName,j="maskShow",a="maskHide",t="clickoutside",n="focusoutside",d=(function(){
/*! IS_POSITION_FIXED_SUPPORTED - Juriy Zaytsev (kangax) - http://yura.thinkweb2.com/cft/ */
var y=c.config.doc,w=null,x,v;if(y.createElement){x=y.createElement("div");if(x&&x.style){x.style.position="fixed";x.style.top="10px";v=y.body;if(v&&v.appendChild&&v.removeChild){v.appendChild(x);w=(x.offsetTop===10);v.removeChild(x);}}}return w;}());function o(v){}var h="modal",b="mask",g={modal:s(p,h),mask:s(p,b)};o.ATTRS={maskNode:{getter:"_getMaskNode",readOnly:true},modal:{value:false,validator:i},focusOn:{valueFn:function(){return[{eventName:t},{eventName:n}];},validator:c.Lang.isArray}};o.CLASSES=g;o._GET_MASK=function(){var v=c.one("."+g.mask),w=c.one("win");if(v){return v;}v=c.Node.create("<div></div>").addClass(g.mask);if(d){v.setStyles({position:"fixed",width:"100%",height:"100%",top:"0",left:"0",display:"block"});}else{v.setStyles({position:"absolute",width:w.get("winWidth")+"px",height:w.get("winHeight")+"px",top:"0",left:"0",display:"block"});}return v;};o.STACK=[];o.prototype={initializer:function(){c.after(this._renderUIModal,this,q);c.after(this._syncUIModal,this,k);c.after(this._bindUIModal,this,f);},destructor:function(){this._uiSetHostVisibleModal(false);},_uiHandlesModal:null,_renderUIModal:function(){var v=this.get(u);this._repositionMask(this);v.addClass(g.modal);},_bindUIModal:function(){this.after(r+l,this._afterHostVisibleChangeModal);this.after(e+l,this._afterHostZIndexChangeModal);this.after("focusOnChange",this._afterFocusOnChange);if(!d||(c.UA.ios&&c.UA.ios<5)||(c.UA.android&&c.UA.android<3)){c.one("win").on("scroll",this._resyncMask,this);}},_syncUIModal:function(){this._uiSetHostVisibleModal(this.get(r));this._uiSetHostZIndexModal(this.get(e));},_focus:function(w){var x=this.get(u),v=x.get("tabIndex");x.set("tabIndex",v>=0?v:0);this.focus();},_blur:function(){this.blur();},_getMaskNode:function(){return o._GET_MASK();},_uiSetHostVisibleModal:function(A){var v=o.STACK,y=this.get("maskNode"),z=this.get("modal"),x,w;if(A){c.Array.each(v,function(B){B._detachUIHandlesModal();B._blur();});v.unshift(this);this._repositionMask(this);this._uiSetHostZIndexModal(this.get(e));if(z){y.show();c.later(1,this,"_attachUIHandlesModal");this._focus();}}else{w=c.Array.indexOf(v,this);if(w>=0){v.splice(w,1);}this._detachUIHandlesModal();this._blur();if(v.length){x=v[0];this._repositionMask(x);x._uiSetHostZIndexModal(x.get(e));if(x.get("modal")){c.later(1,x,"_attachUIHandlesModal");x._focus();}}else{if(y.getStyle("display")==="block"){y.hide();}}}},_uiSetHostZIndexModal:function(v){if(this.get("modal")){this.get("maskNode").setStyle(e,v||0);}},_attachUIHandlesModal:function(){if(this._uiHandlesModal||o.STACK[0]!==this){return;}var C=this.get(u),z=this.get("maskNode"),B=this.get("focusOn"),w=c.bind(this._focus,this),x=[],y,v,A;for(y=0,v=B.length;y<v;y++){A={};A.node=B[y].node;A.ev=B[y].eventName;A.keyCode=B[y].keyCode;if(!A.node&&!A.keyCode&&A.ev){x.push(C.on(A.ev,w));}else{if(A.node&&!A.keyCode&&A.ev){x.push(A.node.on(A.ev,w));}else{if(A.node&&A.keyCode&&A.ev){x.push(A.node.on(A.ev,w,A.keyCode));}else{c.Log('focusOn ATTR Error: The event with name "'+A.ev+'" could not be attached.');}}}}if(!d){x.push(c.one("win").on("scroll",c.bind(function(D){z.setStyle("top",z.get("docScrollY"));},this)));}this._uiHandlesModal=x;},_detachUIHandlesModal:function(){c.each(this._uiHandlesModal,function(v){v.detach();});this._uiHandlesModal=null;},_afterHostVisibleChangeModal:function(v){this._uiSetHostVisibleModal(v.newVal);},_afterHostZIndexChangeModal:function(v){this._uiSetHostZIndexModal(v.newVal);},isNested:function(){var w=o.STACK.length,v=(w>1)?true:false;return v;},_repositionMask:function(v){var y=this.get("modal"),x=v.get("modal"),z=this.get("maskNode"),A,w;if(y&&!x){z.remove();this.fire(a);}else{if((!y&&x)||(y&&x)){z.remove();this.fire(a);A=v.get(u);w=A.get("parentNode")||c.one("body");w.insert(z,w.get("firstChild"));this.fire(j);}}},_resyncMask:function(A){var B=A.currentTarget,v=B.get("docScrollX"),C=B.get("docScrollY"),y=B.get("innerWidth")||B.get("winWidth"),z=B.get("innerHeight")||B.get("winHeight"),x=this.get("maskNode");x.setStyles({"top":C+"px","left":v+"px","width":y+"px","height":z+"px"});},_afterFocusOnChange:function(v){this._detachUIHandlesModal();if(this.get(r)){this._attachUIHandlesModal();}}};c.WidgetModality=o;},"3.6.0pr3",{requires:["base-build","event-outside","widget"],skinnable:true});