(function(f){var b=false,e=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;var c=function(){};c.extend=function(k){var j=this.prototype;b=true;var i=new this();b=false;for(var h in k){i[h]=typeof k[h]=="function"&&typeof j[h]=="function"&&e.test(k[h])?(function(l,m){return function(){var o=this._super;this._super=j[l];var n=m.apply(this,arguments);this._super=o;return n}})(h,k[h]):k[h]}function g(){if(!b&&this.init){this.init.apply(this,arguments)}}g.prototype=i;g.prototype.constructor=g;g.extend=c.extend;return g};var d={debug:false,trace:function(g){if(this.debug&&f.console!==undefined){f.console.log("Porthole: "+g)}},error:function(g){if(typeof f.console!==undefined&&typeof f.console.error==="function"){f.console.error("Porthole: "+g)}}};d.WindowProxy=function(){};d.WindowProxy.prototype={post:function(h,g){},addEventListener:function(g){},removeEventListener:function(g){}};d.WindowProxyBase=c.extend({init:function(g){if(g===undefined){g=""}this.targetWindowName=g;this.origin=f.location.protocol+"//"+f.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return d.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(h,g){if(g===undefined){g="*"}this.dispatchMessage({data:h,sourceOrigin:this.getOrigin(),targetOrigin:g,sourceWindowName:f.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(g){this.eventListeners.push(g);return g},removeEventListener:function(h){var g;try{g=this.eventListeners.indexOf(h);this.eventListeners.splice(g,1)}catch(i){this.eventListeners=[]}},dispatchEvent:function(h){var g;for(g=0;g50?50:100}}});d.WindowProxyHTML5=d.WindowProxyBase.extend({init:function(g,h){this._super(h);this.eventListenerCallback=null},dispatchMessage:function(g){this.getTargetWindow().postMessage(d.WindowProxy.serialize(g),g.targetOrigin)},addEventListener:function(h){if(this.eventListeners.length===0){var g=this;if(f.addEventListener){this.eventListenerCallback=function(i){g.eventListener(g,i)};f.addEventListener("message",this.eventListenerCallback,false)}else{if(f.attachEvent){this.eventListenerCallback=function(i){g.eventListener(g,f.event)};f.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(h)},removeEventListener:function(g){this._super(g);if(this.eventListeners.length===0){if(f.removeEventListener){f.removeEventListener("message",this.eventListenerCallback)}else{if(f.detachEvent){if(typeof f.onmessage==="undefined"){f.onmessage=null}f.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(h,g){var i=d.WindowProxy.unserialize(g.data);if(i&&(h.targetWindowName===""||i.sourceWindowName==h.targetWindowName)){h.dispatchEvent(new d.MessageEvent(i.data,g.origin,h))}}});if(!f.postMessage){d.trace("Using legacy browser support");d.WindowProxy=d.WindowProxyLegacy.extend({})}else{d.trace("Using built-in browser support");d.WindowProxy=d.WindowProxyHTML5.extend({})}d.WindowProxy.serialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(g)};d.WindowProxy.unserialize=function(i){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var g=JSON.parse(i)}catch(h){return false}return g};d.WindowProxy.getTargetWindow=function(g){if(g===""){return parent}else{if(g==="top"||g==="parent"){return f[g]}}return f.frames[g]};d.MessageEvent=function a(i,g,h){this.data=i;this.origin=g;this.source=h};d.WindowProxyDispatcher={forwardMessageEvent:function(k){var i,j=f.decodeURIComponent,h,g;if(document.location.hash.length>0){i=d.WindowProxy.unserialize(j(document.location.hash.substr(1)));h=d.WindowProxy.getTargetWindow(i.targetWindowName);g=d.WindowProxyDispatcher.findWindowProxyObjectInWindow(h,i.sourceWindowName);if(g){if(g.origin===i.targetOrigin||i.targetOrigin==="*"){g.dispatchEvent(new d.MessageEvent(i.data,i.sourceOrigin,g))}else{d.error("Target origin "+g.origin+" does not match desired target of "+i.targetOrigin)}}else{d.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(g,j){var h;if(g){for(h in g){if(Object.prototype.hasOwnProperty.call(g,h)){try{if(g[h]!==null&&typeof g[h]==="object"&&g[h] instanceof g.Porthole.WindowProxy&&g[h].getTargetWindowName()===j){return g[h]}}catch(k){}}}}return null},start:function(){if(f.addEventListener){f.addEventListener("resize",d.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(f.attachEvent&&f.postMessage!=="undefined"){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{d.error("Cannot attach resize event")}}}}};if(typeof exports!=="undefined"){module.exports=d}else{f.Porthole=d}})(typeof window!=="undefined"?window:this);