var Overlay=(function(){var _instance;var _events={EVENT_BEFORE_SHOW:"beforeshow",EVENT_AFTER_SHOW:"aftershow",EVENT_BEFORE_HIDE:"beforehide",EVENT_AFTER_HIDE:"afterhide"};var _vars={container:document.body,_container:null,_background:null,_content:null,_frame:null,_close:null};var _methods={initialize:function(){var container=document.createElement("div");container.setAttribute("id","overlayContainer");_vars._container=container;var background=document.createElement("div");background.setAttribute("id","overlayBackground");_vars._background=background;var frame=document.createElement("div");frame.setAttribute("id","overlayFrame");_vars._frame=frame;var close=document.createElement("button");close.setAttribute("id","overlayClose");close.setAttribute("type","button");_vars._close=close;frame.appendChild(close);container.appendChild(background);container.appendChild(frame);},destroy:function(){var close=_vars._close;if(close){OOP.removeEventListener(close,"click",_methods._handler_close_clicked);}
_vars._close=null;_vars._frame=null;var content=_vars._content;if(content){content.parentNode.removeChild(content);if(typeof content._overlayData.width!==typeof undefined){content.style.width="";}
if(typeof content._overlayData.height!==typeof undefined){content.style.height="";}
if(typeof content._overlayData.parent!==typeof undefined){content._overlayData.parent.appendChild(content);}
content._overlayData=null;}
_vars._content=null;var background=_vars._background;if(background){OOP.removeEventListener(background,"click",_methods._handler_background_click);}
_vars._background=null;var container=_vars._container;if(container&&container.parentNode){container.setAttribute("class","");container.parentNode.removeChild(container);}
_vars._container=null;},show:function(contentID,options){if(_vars._content!=null){_instance.hide();}
OOP.dispatchEvent(_instance,new OOP.Event(_instance.EVENT_BEFORE_SHOW));var width,height,offsetX,offsetY;var containerClass="";if(typeof options!==typeof undefined){if(typeof options.width!==typeof undefined){width=options.width;}
if(typeof options.height!==typeof undefined){height=options.height;}
if(typeof options.offsetX!==typeof undefined){offsetX=options.offsetX;}
if(typeof options.offsetY!==typeof undefined){offsetY=options.offsetY;}
if(typeof options.containerClass!==typeof undefined){containerClass=options.containerClass;}}
var container=_vars._container;var background=_vars._background;var frame=_vars._frame;var close=_vars._close;var content=document.getElementById(contentID);content._overlayData=content._overlayData||{};if(typeof width===typeof undefined){if(typeof document.documentElement.currentStyle!==typeof undefined){width=content.currentStyle.width;}else{width=window.getComputedStyle(content).width;}}
if(parseInt(width)){frame.style.width=width;content._overlayData.width=width;content.style.width="100%";}else{frame.style.width="";}
if(typeof height===typeof undefined){if(typeof document.documentElement.currentStyle!==typeof undefined){height=content.currentStyle.height;}else{height=window.getComputedStyle(content).height;}}
if(parseInt(height)){frame.style.height=height;content._overlayData.height=height;content.style.height="100%";}else{frame.style.height="";}
if(typeof offsetX!==typeof undefined){frame.style.left=offsetX;}else{frame.style.left="";}
if(typeof offsetY!==typeof undefined){frame.style.top=offsetY;}else{frame.style.top="";}
_vars._content=content;OOP.addEventListener(background,"click",_methods._handler_background_click);OOP.addEventListener(close,"click",_methods._handler_close_clicked);content._overlayData.parent=content.parentNode;content.parentNode.removeChild(content);frame.appendChild(content);var appendContainer=_instance.container;if(_instance.container.length){appendContainer=_instance.container[0];}
appendContainer.appendChild(container);container.setAttribute("class",containerClass);var timeout=setTimeout(function(){clearTimeout(timeout);container.setAttribute("class",containerClass+" visible");},50);TransitionHelper.offTransitionComplete(container);TransitionHelper.onTransitionComplete(container,function(){TransitionHelper.offTransitionComplete(container);OOP.dispatchEvent(_instance,new OOP.Event(_instance.EVENT_AFTER_SHOW));});},hide:function(){OOP.dispatchEvent(_instance,new OOP.Event(_instance.EVENT_BEFORE_HIDE));var close=_vars._close;if(close){OOP.removeEventListener(close,"click",_methods._handler_close_clicked);}
var background=_vars._background;if(background){OOP.removeEventListener(background,"click",_methods._handler_background_click);}
var container=_vars._container;if(container){TransitionHelper.offTransitionComplete(container);TransitionHelper.onTransitionComplete(container,function(){TransitionHelper.offTransitionComplete(container);var content=_vars._content;if(content){content.parentNode.removeChild(content);if(typeof content._overlayData.width!==typeof undefined){content.style.width="";}
if(typeof content._overlayData.height!==typeof undefined){content.style.height="";}
if(typeof content._overlayData.parent!==typeof undefined){content._overlayData.parent.appendChild(content);}
content._overlayData=null;}
_vars._content=null;container.setAttribute("class","");container.parentNode.removeChild(container);OOP.dispatchEvent(_instance,new OOP.Event(_instance.EVENT_AFTER_HIDE));});var containerClass=container.getAttribute("class");containerClass=containerClass.substr(0,containerClass.length-"visible".length);container.setAttribute("class",containerClass);}},_handler_close_clicked:function(evt){_instance.hide();return false;},_handler_background_click:function(evt){_instance.hide();return false;}};var TransitionHelper=(function(){var transitionEvent=null;var transitionEvents=[["webkitTransition","webkitTransitionEnd"],["transition","transitionend"]];var transitionEventsLen=transitionEvents.length;for(var i=0;i<transitionEventsLen;i++){if(typeof document.documentElement.style[transitionEvents[i][0]]!==typeof undefined){break;}}
if(i!=transitionEventsLen){transitionEvent=transitionEvents[i][1];}
return{onTransitionComplete:function(element,callback){if(transitionEvent){OOP.addEventListener(element,transitionEvent,callback);}else{callback();}},offTransitionComplete:function(element,callback){if(transitionEvent){if(typeof callback!==typeof undefined){OOP.removeEventListener(element,transitionEvent,callback);}else{OOP.removeEventListener(element,transitionEvent);}}}};})();_instance={EVENT_BEFORE_SHOW:_events.EVENT_BEFORE_SHOW,EVENT_AFTER_SHOW:_events.EVENT_AFTER_SHOW,EVENT_BEFORE_HIDE:_events.EVENT_BEFORE_HIDE,EVENT_AFTER_HIDE:_events.EVENT_AFTER_HIDE,container:_vars.container,initialize:_methods.initialize,destroy:_methods.destroy,hide:_methods.hide,show:_methods.show};return _instance;})();if(!OOP){var OOP=(function(){var _methods={event:function(type,data){var event=null;try{event=new CustomEvent(type);}catch(ex){if(document.createEventObject){event=document.createEventObject("Event");if(event.initCustomEvent){event.initCustomEvent(type,true,true);}}else{event={};}}
event._type=type;event._data=data;return event;},addEventListener:function(obj,types,handler){if(!obj._eventHandlers){obj._eventHandlers={};}
types=types.split(",");var typesLen=types.length;for(var i=0;i<typesLen;i++){var type=types[i];if(obj.addEventListener){handler=_methods._addEventHandler(obj,type,handler);obj.addEventListener(type,handler);}else if(obj.attachEvent){var attachHandler=function(){handler(window.event);}
attachHandler.handler=handler;attachHandler=_methods._addEventHandler(obj,type,attachHandler);obj.attachEvent("on"+ type,attachHandler);}else if(typeof jQuery!==typeof undefined){handler=_methods._addEventHandler(obj,type,handler);jQuery.on(type,handler);}else{obj.addEventListener=_methods._addEventListener;obj.addEventListener(type,handler);}}},_addEventListener:function(type,handler){handler._isCustom=true;_methods._addEventHandler(this,type,handler);},_addEventHandler:function(obj,type,eventHandler){if(!obj._eventHandlers[type]){obj._eventHandlers[type]=[];}
var eventHandlers=obj._eventHandlers[type];var eventHandlersLen=eventHandlers.length;for(var i=0;i<eventHandlersLen;i++){if(eventHandlers[i]===eventHandler){return eventHandler;}else if(eventHandlers[i].handler&&eventHandlers[i].handler===eventHandler){return eventHandlers[i];}}
eventHandlers.push(eventHandler);return eventHandler;},removeEventListener:function(obj,types,handler){if(!obj._eventHandlers){obj._eventHandlers={};}
types=types.split(",");var typesLen=types.length;for(var i=0;i<typesLen;i++){var type=types[i];var handlers;if(typeof handler===typeof undefined){handlers=obj._eventHandlers[type]||[];}else{handlers=[handler];}
var handlersLen=handlers.length;for(var j=0;j<handlersLen;j++){var handler=handlers[j];if(obj.removeEventListener){handler=_methods._removeEventHandler(obj,type,handler);obj.removeEventListener(type,handler);}else if(obj.detachEvent){handler=_methods._removeEventHandler(obj,type,handler);obj.detachEvent("on"+ type,handler);}else if(typeof jQuery!==typeof undefined){handler=_methods._removeEventHandler(obj,type,handler);jQuery.off(type,handler);}else{obj.removeEventListener=_methods._removeEventListener;obj.removeEventListener(type,handler);}}}},_removeEventListener:function(types,handler){types=types.split(",");var typesLen=types.length;for(var i=0;i<typesLen;i++){var type=types[i];var handlers;if(typeof handler===typeof undefined){handlers=this._eventHandlers[type]||[];}else{handlers=[handler];}
var handlersLen=handlers.length;for(var j=0;j<handlersLen;j++){var handler=handlers[j];handler._isCustom=false;_methods._removeEventHandler(this,type,handler);}}},_removeEventHandler:function(obj,type,eventHandler){if(!obj._eventHandlers[type]){obj._eventHandlers[type]=[];}
var eventHandlers=obj._eventHandlers[type];var eventHandlersLen=eventHandlers.length;for(var i=0;i<eventHandlersLen;i++){if(eventHandlers[i]===eventHandler){return eventHandlers.splice(i,1)[0];}else if(eventHandlers[i].handler&&eventHandlers[i].handler===eventHandler){return eventHandlers.splice(i,1)[0];}}},dispatchEvent:function(obj,event){if(!obj._eventHandlers){obj._eventHandlers={};}
if(obj.dispatchEvent){obj.dispatchEvent(event);}else if(obj.fireEvent){obj.fireEvent("on"+ type,event);}else if(typeof jQuery!==typeof undefined){jQuery(obj).trigger(jQuery.Event(event._type,{_type:event._type,_data:event._data}));}else{obj.dispatchEvent=_methods._dispatchEvent;obj.dispatchEvent(event);}},_dispatchEvent:function(event){_methods._dispatchEventHandlers(this,event);},_dispatchEventHandlers:function(obj,event){var eventHandlers=obj._eventHandlers[event._type];if(!eventHandlers){return;}
var eventHandlersLen=eventHandlers.length;for(var i=0;i<eventHandlersLen;i++){eventHandlers[i](event);}}};return{Event:_methods.event,addEventListener:_methods.addEventListener,removeEventListener:_methods.removeEventListener,dispatchEvent:_methods.dispatchEvent,};})();}
Overlay.initialize();