/*
Copyright (c) 2007-2008 the OTHER media Limited
Licensed under the BSD license, http://ojay.othermedia.org/license.html
*/
// @require ojay/core-min
(function(d){var h=function(b){return function(){var a=this._0._1;a.setStyle({visibility:'hidden'});this.show('none',{silent:true})[b]().hide('none',{silent:true});a.setStyle({visibility:''});return this}};d.Overlay=JS.Class({include:[JS.State,d.Observable],extend:{BASE_LAYER:1000,MINIMUM_OFFSET:20,DEFAULT_SIZE:{width:400,height:300},DEFAULT_POSITION:{left:50,top:50},DEFAULT_OPACITY:1,CONTAINER_CLASS:'overlay-container',TRANSITION_TIME:0.4,EASING:'easeOutStrong',Transitions:JS.Singleton({_7:{},INTERFACE:new JS.Interface(['hide','show']),_b:{hide:function(a){return a},show:function(a){return a}},add:function(a,b){JS.Interface.ensure(b,this.INTERFACE);this._7[a]=b;return this},get:function(a){return this._7[a]||this._b}}),getLayer:function(a){if(a.getLayer)return Number(a.getLayer());if(a.nodeType==d.HTML.ELEMENT_NODE||typeof a=='string')a=d(a);if(a.getStyle)return Number(a.getStyle('zIndex'))||0;return 0}},initialize:function(a){this._0={};a=this._6=a||{};d(document.body).insert(this.getHTML().node,'top');this.setState('INVISIBLE');this.setSize(a.width,a.height);this.setPosition(a.left,a.top);this.setLayer(a.layer);this.setOpacity(a.opacity)},getHTML:function(){var a=this,b=a._0;if(b._1)return b._1;var c=d(d.HTML.div({className:this.klass.CONTAINER_CLASS}));c.setStyle({position:'absolute',overflow:'hidden'}).hide();c.setStyle({padding:'0 0 0 0',border:'none'});(this._6.className||'').trim().split(/\s+/).forEach(c.method('addClass'));return b._1=c},getContainer:function(){return this._0._1},setPosition:function(a,b){if(this.inState('CLOSED'))return this;var c=this.klass.DEFAULT_POSITION;a=this._5(a===undefined?c.left:a);b=this._5(b===undefined?c.top:b);this._a={left:a,top:b};if(this.inState('VISIBLE'))this._0._1.setStyle(this._a);return this},getPosition:function(a){var b=this._a,c=b.left,e=b.top;return a?{left:c,top:e}:{left:parseInt(c),top:parseInt(e)}},setSize:function(a,b){if(this.inState('CLOSED'))return this;var c=this.klass.DEFAULT_SIZE;a=this._5(a===undefined?c.width:a);b=this._5(b===undefined?c.height:b);this._8={width:a,height:b};if(this.inState('VISIBLE'))this._0._1.setStyle(this._8);return this},getSize:function(a){var b=this._8,c=b.width,e=b.height;return a?{width:c,height:e}:{width:parseInt(c),height:parseInt(e)}},getRegion:function(){return!this.inState('INVISIBLE','CLOSED')?this._0._1.getRegion():undefined},setOpacity:function(a){this._4=(a===undefined)?this.klass.DEFAULT_OPACITY:Number(a);if(this._4>1)this._4/=100;if(this.inState('VISIBLE'))this._0._1.setStyle({opacity:this._4});return this},getOpacity:function(){return this._4},positionBehind:function(a){return this.setLayer(this.klass.getLayer(a)-1)},positionInFront:function(a){return this.setLayer(this.klass.getLayer(a)+1)},setLayer:function(a){if(this.inState('CLOSED'))return this;this._9=(a===undefined)?this.klass.BASE_LAYER:Number(a);this._0._1.setStyle({zIndex:this._9});return this},getLayer:function(){return this._9},states:{INVISIBLE:{center:h('center'),show:function(a,b){this.setState('SHOWING');a=this.klass.Transitions.get(a||'none');var c=new JS.MethodChain()._(this).setState('VISIBLE');if((b||{}).silent!==true)c._(this).notifyObservers('show');c._(this);return a.show(this,c)},close:function(a){this._0._1.remove();this.setState('CLOSED');if((a||{}).silent!==true)this.notifyObservers('close');return this}},SHOWING:{},VISIBLE:{center:function(){var a=this.getRegion(),b=d.getVisibleRegion(),c=b.left+(b.getWidth()-a.getWidth())/2,e=b.top+(b.getHeight()-a.getHeight())/2;if(c<this.klass.MINIMUM_OFFSET)c=this.klass.MINIMUM_OFFSET;if(e<this.klass.MINIMUM_OFFSET)e=this.klass.MINIMUM_OFFSET;return this.setPosition(c,e)},hide:function(a,b){this.setState('HIDING');a=this.klass.Transitions.get(a||'none');var c=new JS.MethodChain()._(this).setState('INVISIBLE');if((b||{}).silent!==true)c._(this).notifyObservers('hide');c._(this);return a.hide(this,c)},close:function(a,b){return this.hide(a,b)._(this).close(b)},resize:function(a,b,c,e,f){var g=a,f=f||{};if(typeof g=='object'){f=b||{};a=g.left;b=g.top;c=g.getWidth();e=g.getHeight()}this.setState('RESIZING');return this._0._1.animate({left:{to:a},top:{to:b},width:{to:c},height:{to:e}},f.duration||this.klass.TRANSITION_TIME,{easing:f.easing||this.klass.EASING})._(this).setSize(c,e)._(this).setPosition(a,b)._(this).setState('VISIBLE')._(this)}},HIDING:{},RESIZING:{},CLOSED:{}},_5:function(a){return String(a).replace(/^(-?\d+(?:\.\d+)?)$/g,'$1px')}});d.Overlay.Transitions.add('none',{hide:function(a,b){a.getContainer().hide();b.fire();return a},show:function(a,b){a.getContainer().setStyle({opacity:a.getOpacity()}).setStyle(a.getSize(true)).setStyle(a.getPosition(true)).show();b.fire();return a}}).add('fade',{hide:function(a,b){a.getContainer().animate({opacity:{to:0}},d.Overlay.TRANSITION_TIME).hide()._(b.toFunction());return b},show:function(a,b){a.getContainer().setStyle({opacity:0}).setStyle(a.getSize(true)).setStyle(a.getPosition(true)).show().animate({opacity:{to:a.getOpacity()}},d.Overlay.TRANSITION_TIME)._(b.toFunction());return b}}).add('zoom',{hide:function(a,b){var c=a.getRegion().scale(0.5),e=c.getCenter();a.getContainer().animate({opacity:{to:0},left:{to:c.left},width:{to:c.getWidth()},top:{to:c.top},height:{to:c.getHeight()}},d.Overlay.TRANSITION_TIME,{easing:d.Overlay.EASING}).hide()._(b.toFunction());return b},show:function(a,b){var c=a.getPosition(),e=a.getSize();a.getContainer().setStyle({opacity:0,left:(c.left+e.width/4)+'px',top:(c.top+e.height/4)+'px',width:(e.width/2)+'px',height:(e.height/2)+'px'}).show().animate({opacity:{to:a.getOpacity()},left:{to:c.left},width:{to:e.width},top:{to:c.top},height:{to:e.height}},d.Overlay.TRANSITION_TIME,{easing:d.Overlay.EASING})._(b.toFunction());return b}});d.ContentOverlay=JS.Class(d.Overlay,{extend:{CONTENT_CLASS:'overlay-content'},initialize:function(a){this.callSuper();this.setContent(this._6.content)},getHTML:function(){var a=this,b=a._0;if(b._3)return b._1;var c=this.callSuper().node,e=new d.HtmlBuilder(c);b._3=d(e.div({className:a.klass.CONTENT_CLASS}));return b._1},setContent:function(a){if(this.inState('CLOSED'))return this;this._0._3.setContent(a||'');return this},getContentElement:function(){return this._0._3},insert:function(a,b){if(this.inState('CLOSED'))return this;this._0._3.insert(a,b);return this},states:{INVISIBLE:{fitToContent:h('fitToContent')},VISIBLE:{fitToContent:function(){var a=this._0._3.getRegion();return this.setSize(a.getWidth(),a.getHeight())}}}});d.Tooltip=JS.Class(d.ContentOverlay,{initialize:function(a,b){this.callSuper(b);this._0._1.addClass('tooltip');this.setContent(a);this.klass._2.push(this)},extend:{update:function(c,e){var f=YAHOO.util.Event.getXY(e);this._2.forEach(function(a){var b=a.getRegion();width=b?b.getWidth():100;a.setPosition(f[0]+20-width/2,f[1]+20)})},_2:[]}});d(document).on('mousemove',d.Tooltip.method('update'));d.PageMask=JS.Class(d.Overlay,{extend:{DEFAULT_COLOR:'000000',DEFAULT_OPACITY:0.5,_2:[],resizeAll:function(){this._2.forEach('setSize')}},initialize:function(a){this.klass._2.push(this);this.callSuper();this.setColor(this._6.color);if(!YAHOO.env.ua.ie)this._0._1.setStyle({position:'fixed'})},setPosition:function(){return this.callSuper(0,0)},setSize:function(){if(!YAHOO.env.ua.ie)return this.callSuper('100%','100%');var a=d(document.body).getRegion(),b=d.getViewportSize();return this.callSuper(Math.max(a.getWidth(),b.width),Math.max(a.getHeight(),b.height))},setColor:function(c){this._c=(arguments.length==3)?Array.from(arguments).map(function(a){var b=Math.round(a%256).toString(16);return(b.length==1?'0':'')+b}).join(''):(c?String(c).replace(/[^0-9a-f]/ig,''):this.klass.DEFAULT_COLOR);this._0._1.setStyle({backgroundColor:'#'+this._c});return this},states:{INVISIBLE:{show:function(){this.setSize();return this.callSuper()}}}});if(YAHOO.env.ua.ie)d(window).on('resize',d.PageMask.method('resizeAll'))})(Ojay);