(function($){$.extend($,{cupEvent:{version:'1.0.0',initialized:false,uuid:new Date().getTime()}});function Events(){this.subscribers=[];this.markerClassName='hasEvent';}
$.extend(Events.prototype,{addSubscriber:function(name,subscriber){this.subscribers.push(subscriber);},attachEvents:function(el){var $el=$(el);$el.addClass(this.markerClassName);if($el.is('a')){$el.click($.proxy(function(event){var eventPayload=$el.data('cupEvent');if(eventPayload){this.dispatchEvent(eventPayload);}},this));}},dispatchEvent:function(event,callback){var calledBack=false;var numberOfSubscribers=this.subscribers.length;var numberOfCallbacks=0;function dispatch(){if(callback&&!calledBack){callback();calledBack=true;}}
setTimeout(function(){dispatch(true);},3000);this.subscribers.forEach(function(subscriber){subscriber.onEvent.call(this,event,function(err,res){numberOfCallbacks++;if(numberOfCallbacks===numberOfSubscribers){dispatch();}});});}});$.fn.cupEvent=function(){$(this).find('[data-cup-event]').not('.hasEvent').each(function(i,el){$.cupEvent.attachEvents(el);});};$.cupEvent=new Events();return $.cupEvent;})(jQuery);