/**!Copyright 2012 Chegg inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */!function(){function f(e,t){var n,r;if(e.indexOf)return e.indexOf(t);for(n=0;r=e[n];n++)if(r==t)return n;return-1}function l(e){if(u.strict)throw new Error(e);"console"in window&&(console.error?console.error(e):console.warn?console.warn(e):console.log(e))}function c(e){return e.replace(/^on([A-Z])/,function(e,t){return t.toLowerCase()})}function h(e){var n=e.match(t);return e.split(":").length>2&&l("Library does not support multiple pseudo events"),{name:n[1],pseudo:n[2],args:n[3]}}function p(e){return h(c(e))}function d(t,n,r){var i;return e?(i=document.createEvent("UIEvents"),i.initUIEvent(t,!1,!1,window,1)):i={},i.dispatcher=n,i.args=r,i.object_event=!0,i}function v(t,n,r){e?t.$event_element.addEventListener(n,r,!1):t.$events[n]?t.$events[n].indexOf(r)==-1&&t.$evetns[n].push(r):t.$events[n]=[r]}function m(t,n,r){var i,s;if(e)t.$event_element.dispatchEvent(r);else for(i=0;s=t.$events[n];i++)s.apply(null,[r])}function g(t,n,r){var i;if(e)t.$event_element.removeEventListener(n,r,!1);else{if(!t.$events[n])return;i=f(t.$events[n],r);if(i<0)return;t.$events[n].splice(i,1)}}var e="createEvent"in document,t=/([^:]+)(?:\:([^(]*)(?:\((.*)\))?)?/,n,r,i,s,o,u,a;u=function(u){var f=this;e?this.$event_element=u||document.createElement("events"):this.$events={},this.$latched={},this.$once={},this.addEvent=n,this.addEvents=r,this.fireEvent=i,this.removeEvent=s,this.addEventOnce=o,this.fireLatchedEvent=a,this.addEvent("destroy:delay(0)",function(){var e="$event_element $latched $events $once addEvent removeEvent addEventOnce fireLatchedEvent".split(" "),t,n;for(t=0;n=e[t];t++)f[n]=null})},u.removeOn=c,u.getPseudos=h,u.processType=p,u.createEvent=d,u.strict=!1,u.Pseudoes={once:{addEvent:function(e,t){return this.addEventOnce(e,t)}},latched:{fireEvent:function(e,t){return this.fireLatchedEvent(e,t)}},times:{addEvent:function(e,t,n){var r=0,i=this;this.addEvent(e,function s(){t.apply(null,arguments),r+=1,r==n&&i.removeEvent(e,s)})}},delay:{addEvent:function(e,t,n){this.addEvent(e,function(){setTimeout(t,n)})},fireEvent:function(e,t,n){var r=this;setTimeout(function(){r.fireEvent(e,t)},n)}}},n=function(t,n){var r=p(t),i=u.Pseudoes[r.pseudo]&&u.Pseudoes[r.pseudo].addEvent,s=this.$latched[r.name]&&this.$latched[r.name].args,o;return i?i.apply(this,[r.name,n,r.args]):(v(this,r.name,n),this.$latched&&this.$latched[r.name]&&(o=d(r.name,this,s),n.apply(null,[o])),this)},r=function(t){var n;for(n in t)t.hasOwnProperty(n)&&this.addEvent(n,t[n]);return this},i=function(t,n){var r=p(t),i=u.Pseudoes[r.pseudo]&&u.Pseudoes[r.pseudo].fireEvent,s,o,a,f;if(i)return i.call(this,r.name,n);a=this.$once[r.name],this.$once[r.name]=null,s=d(r.name,this,n),m(this,r.name,s);if(!a)return this;while(o=a.pop())this.removeEvent(r.name,o,!0);return this},s=function(t,n,r){var i=p(t),s;return g(this,i.name,n),!r&&this.$once[i.name]&&(s=this.$once[i.name].indexOf(n))>-1&&this.$once[i.name].splice(s,1),this},o=function(t,n){var r=this,i=p(t);return this.$once[i.name]||(this.$once[i.name]=[]),this.$once[i.name].indexOf(n)==-1&&this.$once[i.name].push(n),this.addEvent(i.name,n)},a=function(t,n){return this.$latched||(this.$latched={}),this.$latched[t]={args:n},this.fireEvent(t,n),this},this.Events=u}.call(this),!function(){var e={};e.Bind=function(){var e,t;this.bound={};if(!this.bind)return;for(e=0;t=this.bind[e];e++)this[t]&&(this.bound[t]=this[t].bind(this))},e.Options=function(){var n;this.options||(this.options={});for(n in this.defaultOptions)this.defaultOptions.hasOwnProperty(n)&&(this.options[n]=this.defaultOptions[n]);this.setOptions=function(t){var n;if(typeof t!="object"||t===null)return;for(n in t)t.hasOwnProperty(n)&&(n in this.options&&(this.options[n]=t[n]),/^on[A-Z][a-zA-Z]+/.test(n)&&this.addEvent&&typeof t[n]=="function"&&this.addEvent(e.Events.removeOn(n),t[n]));return this}},e.Events=Events,e.calculateOffsets=function(e,t){var n=e,r=0,i=0;t||(t=document.body);while(n&&n!=t)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;return{left:r,top:i}},this.Bromine={utils:e}}.call(this),!function(e,t){function r(e){t.Options.call(this),t.Events.call(this),this.setOptions(e),this.stack=this.options.tests,this.description=this.options.description,this.results=[],this.next=this.next.bind(this),this.current=this.current.bind(this),this.prev=this.prev.bind(this),this.test_index=0,this.depend=e.depend,e.init&&e.init.call(this)}function i(e){t.Bind.call(this),t.Options.call(this),t.Events.call(this),this.setOptions(e),this.tests={},this.depends=[],this.stack=[],this.results={}}function s(){var e=document.createEventObject();return e}var n="addEventListener"in document;r.prototype={constructor:r,defaultOptions:{init:function(){},destroy:function(){},tests:[],depend:"",fail_timeout:1e4},run:function(){this.fireEvent("start:latched"),this.next()},log:function(e){this.results.push(e)},done:function(e,t){this.tests_done=!0,clearTimeout(this.timeout_handle);if(e===!1)return this.fail(t);this.fireEvent("done:latched",{results:this.results}),this.destroy()},fail:function(e){this.tests_done=!0,clearTimeout(this.timeout_handle),this.log({success:!1,msg:e}),this.fireEvent("fail",{results:this.results}),this.destroy()},destroy:function(){this.fireEvent("destroy"),this.options.destroy()},setTimeout:function(){var e=this;this.options.fail_timeout&&(clearTimeout(this.timeout_handle),this.timeout_handle=setTimeout(function(){e.fail("Test timed out")},this.options.fail_timeout))},next:function(){var e=this.stack[this.test_index++];return this.tests_done?null:(this.setTimeout(),e&&e.apply(this,arguments))},current:function(){var e=this.test_index===0?this.stack[this.test_index]:this.stack[this.test_index-1];return this.tests_done?null:(this.setTimeout(),e&&e.apply(this,arguments))},prev:function(){var e;return this.tests_done?null:(this.test_index-=1,this.test_index<1&&(this.test_index=1),e=this.stack[this.test_index-1],this.setTimeout(),e&&e.apply(this,arguments))}},i.prototype={constructor:i,defaultOptions:{exclude:[],run_only:[]},bind:["testDone","testFailed"],registerTest:function(e,t){var n=this.tests[e]=t instanceof r?t:new r(t),i=this;n.addEvents({start:function(e){i.fireEvent("testStart",{name:e.dispatcher.name,test:e.dispatcher})},done:this.bound.testDone,fail:this.bound.testFailed}),n.name=e,this.depends[e]||(this.depends[e]=[]),t.depend?(this.depends[t.depend]||(this.depends[t.depend]=[]),this.depends[t.depend].push(e)):this.stack.push(e)},getTests:function(){return this.stack},run:function(){this.original_stack=JSON.stringify(this.stack),this.stop=!1,this.next()},reset:function(){this.stop=!0,this.stack=JSON.parse(this.original_stack)},next:function(){var e=this.stack.shift(),t=this.tests[e];if(this.stop)return;if(!e){this.fireEvent("done",{results:this.results});return}if(this.options.exclude.indexOf(e)>-1)return this.next();if(this.options.run_only.length&&this.options.run_only.indexOf(e)==-1)return this.next();this.tests[e].run()},testDone:function(e){var t=this.depends[e.dispatcher.name],n,r;this.fireEvent("testDone",{name:e.dispatcher.name,test:e.dispatcher,results:e.args.results});for(n=0;r=t[n];n++){if(!r)continue;this.stack.push(r)}this.results[e.dispatcher.name]=e.dispatcher.results,this.next()},testFailed:function(e){var t=this.depends[e.dispatcher.name],n,r;this.fireEvent("testFail",{name:e.dispatcher.name,test:e.dispatcher,results:e.args.results});for(n=0;r=t[n];n++)this.tests[r].done(!1,"dependancy failed: "+r);this.results[e.dispatcher.name]=e.dispatcher.results,this.next()},registerReporter:function(e){var t=n?e:e.handleEvent;this.addEvents({testStart:t,testDone:t,testFail:t,done:t})}},Bromine.fireEvent=function(t,n){var r;document.createEventObject?(r=s(),t.fireEvent("on"+n,r)):(r=document.createEvent("HTMLEvents"),r.initEvent(n,!0,!0),t.dispatchEvent(r))},Bromine.fireMouseEvent=function(e,n,r){r||(r={});var i,o=t.calculateOffsets(e),u="details"in r?r.details:1,a="x"in r?r.x:o.left,f="y"in r?r.y:o.top,l="button"in r?r.button:0;document.createEvent?(i=document.createEvent("MouseEvents"),i.initMouseEvent(n,!0,!0,window,u,a,f,a,f,r.ctrl,r.alt,r.shift,r.meta,l,r.relatedTarget),e.dispatchEvent(i)):(i=s(),i.screenX=a,i.screenY=f,i.clientX=a,i.clientY=f,i.ctrlKey=r.ctrl,i.altKey=r.alt,i.shiftKey=r.shift,i.metaKey=r.meta,i.button=l,i.relatedTarget=r.relatedTarget,i.detail=u,e.fireEvent("on"+n,i))},Bromine.fireKeyboardEvent=function(e,t,n){var r;n||(n={}),document.createEvent?(r=document.createEvent("KeyboardEvent"),r.initKeyEvent(t,!0,!0,null,n.ctrl,n.alt,n.shift,n.meta,n.key,n.charCode),e.dispatchEvent(r)):(r=s(),r.ctrlKey=n.ctrl,r.altKey=n.alt,r.shiftKey=n.shift,r.metaKey=n.meta,r.keyCode=n.key,r.charCode=n.charCode,e.fireEvent("on"+t,r))},Bromine.fireEventWithDelay=function(t,n,r,i){var s=i||500;Bromine.fireEvent(t,n),window.setTimeout(r,s)},Bromine.Tester=i,Bromine.Test=r}.apply(Bromine,[Bromine,Bromine.utils]),!function(){function e(){}e.prototype={constructor:e,handleEvent:function(e){var t=this[e.type];switch(e.type){case"done":t(e.args.results);break;case"testStart":t(e.args.name,e.args.test);break;default:t(e.args.name,e.args.results,e.args.test)}},done:function(e,t){console.log("Test Runner Done",[e,t])},testStart:function(e,t){console.log("Test Start",[e,res])},testDone:function(e,t,n){console.log("Test Done",[e,t])},testFail:function(e,t,n){console.log("Test Fail",[e,t])}},Bromine.Reporter=e}.call(Bromine);