/*
 VigLink JavaScript Library -- http://www.viglink.com

 Permission is hereby granted to create derivative works, but only for use
 with the VigLink web service.

 Copyright (c) 2012 VigLink. Rights reserved and patent(s) pending.
*/
(function(m){var l,c;c={each:function(a,b){var d,c;d=0;for(c=a.length;d<c;d++)b(a[d],d)},extend:function(a){var b,c,f,g,e=arguments.length,a=a||{};for(c=1;c<e;c++)if(g=arguments[c],g!==void 0&&g!==null)for(f in g)b=g[f],a!==b&&b!==void 0&&(a[f]=b);return a}};c.extend(c,{addClass:function(a,b){if(!c.hasClass(a,b))a.className=(a.className?a.className+" ":"")+b},attrValues:function(a,b,c){return(b=a[b])?b.split(c||" "):[]},bind:function(a,b){return function(){return a.apply(b,arguments)}},browser:function(){var a=
{},b,d=navigator.userAgent.toLowerCase().replace(/\s*[()]\s*/g,"; ").replace(/(\/[\w.]+)\s+/g,"$1; ").replace(/\;\s*$/,"").split(/;\s*/);c.each(d,function(c){b=(/[\/ :]([^\/ :]+)$/.exec(c)||[])[1];a[b?c.substr(0,c.length-b.length-1).replace(/\d*$/,""):c]=b||!0});return{aol:a.aol,blackberry:a.blackberry,ie:a.msie,ios:a.mobile&&a.safari,opera:a.opera,playstation:a.playstation,version:parseFloat(a.version)||!1}}(),cache:function(){var a={},b="vglnk_"+(new Date).getTime(),c=0;return function(f,g,e){if(f){var h=
f[b];if(h||e!==void 0)return h||(h=++c),a[h]||(f[b]=h,a[h]={}),e!==void 0&&(a[h][g]=e),typeof g==="string"?a[h][g]:a[h]}}}(),canonicalizeHostname:function(a){typeof a==="string"&&(a=c.createA(a));return a.hostname?a.hostname.toString().toLowerCase().replace(/^www\./,"").replace(/:.*$/,""):""},clone:function(a){return c.extend({},a)},contains:function(a,b){return c.indexOf(a,b)!==-1},contextIsAncestor:function(a){for(var b=window.self;b.parent&&b.parent!==b;)if(b=b.parent,b===a)return!0;return!1},
cors:function(a){var b,c=function(){eval(b.responseText)};b=new window.XMLHttpRequest;b.onreadystatechange=function(){b.readyState===4&&b.status===200&&c()};b.open("GET",a);b.withCredentials=!0;b.send()},createA:function(a,b){return c.createEl("a",{href:a,target:b})},createEl:function(a,b,d,f){var g,a=(f||document).createElement(a),b=b||{},d=d||{};for(g in b)b[g]!==void 0&&(a[g]=b[g]);c.css(a,d);return a},css:function(a,b){for(var c in b)try{a.style[c]=b[c]}catch(f){}return a},destructing:function(a){return function(a){var c=
!1,f;return function(){c||(f=a.apply(null,arguments),c=!0);return f}}(a)},escapeRegExp:function(){var a;return function(b){a=a||RegExp("([.*+?^${}()|[\\]\\\\])","g");return b.replace(a,"\\$1")}}(),eventLink:function(a){var b,c=a.target||a.srcElement;do{try{b=c.nodeType}catch(f){break}if(b===1&&(a=c.tagName.toUpperCase(),a==="A"||a==="AREA"))return c;c=c.parentNode}while(c)},exceptionLogger:function(){var a=!1,b=function(){};return function(c,f){if(f!==void 0)a=f,b=c;else return function(){if(a)try{return c.apply(this,
arguments)}catch(f){b(f)}else return c.apply(this,arguments)}}}(),fromQuery:function(a){a.substr(0,1)==="?"&&(a=a.substr(1));var a=a.split("&"),b={};c.each(a,function(a){a=a.split("=");b[decodeURIComponent(a[0])]=decodeURIComponent(a[1])});return b},hasAttrValue:function(a,b,d,f){return b?c.contains(c.attrValues(a,b,f),d):!1},hasClass:function(a,b){return c.hasAttrValue(a,"className",b)},hasRel:function(a,b){return c.hasAttrValue(a,"rel",b)},indexOf:function(){return Array.prototype.indexOf?function(a,
b){return Array.prototype.indexOf.call(a,b)}:function(a,b){var c,f;c=0;for(f=a.length;c<f;c++)if(a[c]===b)return c;return-1}}(),isArray:function(a){return c.type(a)==="array"},isDefaultPrevented:function(a){return a.isDefaultPrevented&&a.isDefaultPrevented()||a.returnValue===!1||a.defaultPrevented===!0},jsonp:function(a){var b=document.getElementsByTagName("script")[0],a=c.createEl("script",{type:"text/javascript",src:a});b.parentNode.insertBefore(a,b)},map:function(a,b){var d=[];c.each(a,function(a,
c){a!==void 0&&(d[c]=b(a))});return d},on:function(){var a;return function(b,d,f){var g,e;if(arguments.length===1)a=b;else{if(arguments.length===2){if(!a)return;f=d;d=b;b=a}try{g=b["on"+d]}catch(h){}typeof g==="function"&&(b["on"+d]=c.bind(function(a){var a=a||window.event,d=g.apply(b,arguments);this.exceptionLogger(function(){if(a){if(d!==void 0&&a.returnValue!==!1)a.returnValue=d;c.isDefaultPrevented(a)&&c.type(a.preventDefault)==="function"&&a.preventDefault();return a.returnValue}return d})()},
this));e=c.exceptionLogger(function(){if(a.enabled())return f.apply(null,arguments)});b.addEventListener?b.addEventListener(d,e,!1):b.attachEvent&&b.attachEvent("on"+d,e)}}}(),position:function(a){var b,c=0,f=0,g=0,e=0;if(!a.offsetParent)return!1;b=a;do c+=b.offsetLeft,f+=b.offsetTop,b=b.offsetParent;while(b);b=a;do g+=b.scrollLeft,e+=b.scrollTop,b=b.parentNode;while(b&&b!==document.body);return{x:c-g,y:f-e}},preventDefault:function(a){a.preventDefault&&a.preventDefault();return a.returnValue=!1},
ready:function(){var a=!1,b=[],d=!1,f,g,e,h,j;document.addEventListener?e=function(){document.removeEventListener("DOMContentLoaded",e,!1);j()}:document.attachEvent&&(h=function(){document.readyState==="complete"&&(document.detachEvent("onreadystatechange",h),j())});f=function(){if(!a){a=!0;if(document.readyState==="complete")return j();else if(document.addEventListener)document.addEventListener("DOMContentLoaded",e,!1);else if(document.attachEvent){document.attachEvent("onreadystatechange",h);var b=
!1;try{b=window.frameElement===null}catch(d){}document.documentElement.doScroll&&b&&g()}c.on(window,"load",j)}};g=function(){if(!d){try{document.documentElement.doScroll("left")}catch(a){setTimeout(c.exceptionLogger(g),1);return}j()}};j=function(){if(!d){if(!document.body)return setTimeout(c.exceptionLogger(j),13);d=!0;b&&(c.each(b,function(a){a()}),b=null)}};return function(a){f();d?a():b.push(a)}}(),reformatKeys:function(a){var b,d,f=function(a){return"_"+a.toLowerCase()};for(b in a)d=b.replace(/([A-Z])/g,
f),c.type(a[b])==="object"&&(a[b]=c.reformatKeys(a[b])),d!==b&&(a[d]=a[b],delete a[b]);return a},removeClass:function(a,b){if(c.hasClass(a,b)){var d,f,e=c.attrValues(a,"className");d=0;for(f=e.length;d<f;d++)e[d]===b&&delete e[d];a.className=e.join(" ")}},request:function(a,b,d){var f,e,d=c.extend({fn:function(){},"return":!1,timeout:null},d);typeof d.fn==="string"?b=c.extend(b,{jsonp:d.fn}):typeof d.fn==="function"&&(f=c.destructing(d.fn),e=c.uniqid("vglnk_jsonp_"),b=c.extend(b,{jsonp:e}),window[e]=
c.exceptionLogger(function(){f.apply(this,arguments);window[e]=void 0}),d.timeout!==null&&setTimeout(c.exceptionLogger(f),d.timeout));b=c.extend({format:"jsonp"},b);b=c.toQuery(b);a=a+(b.length?"?":"")+b;return d["return"]?a:c.traits.cors?c.cors(a):c.jsonp(a)},toQuery:function(a){var b,c="";for(b in a)a[b]!==null&&a[b]!==void 0&&(c+="&"+encodeURIComponent(b)+"="+encodeURIComponent(a[b]));return c.substr(1)},type:function(a){return a===null?"null":a===void 0?"undefined":Object.prototype.toString.call(a).slice(8,
-1).toLowerCase()},updateUrl:function(a,b){return c.extend(c.createA(a),b).href},uniqid:function(){var a=0;return function(b){return(b||"")+(new Date).getTime()+a++}}()});c.traits={basicCompatibility:!(c.browser.blackberry||c.browser.playstation),cors:window.XMLHttpRequest&&(new window.XMLHttpRequest).withCredentials!==void 0,crossWindowCommunication:!(c.browser.ios&&c.browser.version&&(c.browser.version<5||c.browser.version>5)),jsRedirectSetsReferrer:c.browser.aol||!(c.browser.ie||c.browser.opera),
quirksMode:!Boolean(window.addEventListener),windowLevelHandlers:Boolean(window.addEventListener)};var e,n,k;l={api:function(a,b,d){a=e.api_url+"/"+a;b=c.extend({cuid:e.cuid,key:e.key,drKey:e.key?null:e.dr_key,loc:location.href,subId:e.sub_id,v:1},b);if(b.subId&&b.key!==e.key)b.subId=null;return c.request(a,b,d)},addEventListener:function(a,b){this.fire(a,b)},click:function(){var a=function(a){if(a==="_self")return window.self;else if(c.traits.crossWindowCommunication&&c.traits.jsRedirectSetsReferrer)return a=
window.open("",a),a.focus(),a},b=function(a){var b=a.previousSibling,e=a.nextSibling,i=["",a.textContent,""];i[1]!==void 0&&(i[0]=b&&b.nodeType===3?b.data:"",i[2]=e&&e.nodeType===3?e.data:"",i=function(a,b,c){a=a.replace(/\s+/g," ");b=b.replace(/\s+/g," ");c=c.replace(/\s+/g," ");a=a.replace(/^\s+/,"");b.substr(0,1)===" "&&(b=b.substr(1),a+=a.substr(a.length-1,1)!==" "?" ":"");b.substr(b.length-1,1)===" "&&(b=b.substr(0,b.length-1),c=(c.substr(0,1)!==" "?" ":"")+c);c=c.replace(/\s+$/,"");return[a,
b,c]}.apply(this,i),i[0]!==""&&i[2]!==""&&(i[0]=i[0].split(" ").reverse().slice(0,10+(i[0].substr(i[0].length-1,1)===" "?1:0)).reverse().join(" "),i[2]=i[2].split(" ").slice(0,10).join(" "),a={type:"context",itype:(c.cache(a,"params")||{}).type,before:i[0],after:i[2],txt:i[1],loc:location.href,out:a.href,v:2},l.log("info",c.toQuery(a))))};return function(d,f){var f=d.target||f,f=!f||f===window.name||f==="_top"&&window.top===window.self||f==="_parent"&&window.parent===window.self?"_self":f,g,i,h=a(f),
j;if(f!=="_self"&&(!c.traits.crossWindowCommunication||!c.traits.jsRedirectSetsReferrer))j="go";else try{if(h.document===void 0)throw!0;j="jsonp"}catch(o){j="go"}g=c.destructing(c.bind(function(){e.time_click&&arguments.length&&this.logTime("clk");var a=Array.prototype.slice.call(arguments);a.unshift(d,h,f);this.onApiClick.apply(this,a)},this));c.cache(this,"link",typeof d==="string"?d:d.href);if(typeof d==="string"&&(d=c.createA(d,f),!this.preprocessLink(d)))return g();if(!e.enabled)return g();i=
this.clickParams(d,j);this.logTime();e.log_context&&b(d);if(j==="go")this.redirect(this.api("click",i,{"return":!0}),h,f);else if(h===window.self)this.api("click",i,{fn:g,timeout:e.click_timeout});else if(c.contextIsAncestor(h))return this.redirect(d.href,h,f);else g=c.exceptionLogger(g),setTimeout(function(){g()},e.click_timeout),h.document.open(),h.callback=g,h.document.write("<html><head><title>"+d.href+'</title><script type="text/javascript" src="'+this.api("click",i,{fn:"callback","return":!0})+
'"><\/script></head></html>'),h.document.close()}}(),clickParams:function(a,b){var d=c.extend(c.cache(a,"params"),{format:b,libid:e.library_id,out:a.href,ref:document.referrer||null,reaf:e.reaffiliate||null,title:document.title,txt:a.innerHTML});if(d.txt.length>128)d.txt=d.txt.replace(/<[^>]+>/g,""),d.txt=d.txt.length>128?d.txt.substr(0,125)+"...":d.txt;return d},enabled:function(){if(e.enabled&&n!==window&&window.vglnk&&(window.vglnk.key||typeof window.vglnk==="function"))e.enabled=!1;return e.enabled},
expose:function(a,b){if(b=b||this[a])typeof b==="function"?b=c.exceptionLogger(c.bind(b,this)):typeof b==="object"&&(b=c.clone(b)),k[a]||(k[a]=b)},fire:function(){var a={};return function(b,d){var b=b.toLowerCase(),e=a[b]||{fired:!1,listeners:[]};typeof d==="function"?e.fired?d({type:b}):e.listeners.push(d):(e.fired=!0,c.each(e.listeners,function(a){typeof a==="function"&&a({type:b})}),e.listeners=[]);a[b]=e}}(),handleRightClick:function(a,b){if(e.rewrite_modified&&a&&b)switch(b){case "setup":c.cache(a,
"href")||c.cache(a,"href",a.href);a.href=this.api("click",this.clickParams(a,"go"),{"return":!0});setTimeout(c.exceptionLogger(c.bind(function(){this.handleRightClick(a,"teardown")},this)),0);break;case "teardown":a.href=c.cache(a,"href"),c.cache(a,"href",null)}},harmony:function(){c.harmony={UNSAFE_QUIRKSMODE_HANDLERS:1};return function(a){return e.harmony_level<a}}(),init:c.exceptionLogger(function(){this.initLibEvents();this.initNamespace();this.initOptions();c.exceptionLogger(c.bind(this.logException,
this),!e.dev);this.initDRApi();this.initApi();this.enabled()&&(this.initLegacyCallbacks(),this.ping())}),initApi:function(){var a,b={};if(window.vglnk)for(a in window.vglnk)a.substr(-7)==="_plugin"&&(b[a]=window.vglnk[a]);k=n[m]=function(){};this.expose("click");this.expose("link",l.preprocessLink);this.expose("opt");this.expose("$",c.clone(c));c.extend(k,k===window.vglnk?b:{})},initDRApi:function(){var a=!1;window.DrivingRevenue=c.exceptionLogger(c.destructing(c.bind(function(){a=!0;e.dr_key=window.DR_id;
this.enabled()&&this.ping()},this)));c.on("DOMReady",function(){if(!a)try{delete window.DrivingRevenue}catch(b){window.DrivingRevenue=void 0}})},initLibEvents:function(){c.on(l);c.ready(c.bind(function(){this.fire("DOMReady")},this))},initNamespace:function(){window.vglnk&&window.vglnk.key&&(m="vglnk");var a=window,b=m.split("."),c;for(m=b.pop();b.length>0;)c=b.shift(),a[c]=a[c]||{},a=a[c];n=a;k=n[m]=n[m]||{}},initOptions:function(){var a;this.initLegacyOptions();e=c.extend(this.publicOptions({api_url:"//api.viglink.com/api",
cuid:null,dev:!1,dr_key:null,enabled:c.traits.basicCompatibility,key:null,partner:null,sub_id:null,reaffiliate:!1,harmony_level:0,rewrite_original:!0,rewrite_modified:!1}),e,k,{click_timeout:1E3,hop_timeout:2E3,debug:!1,library_id:null,log_context:!0,nofollow:{},norewrite:{},plugins:{link_affiliation:{},modified_clicks:{}},swap:{},time_click:!1,time_ping:!1});for(a in e)a.substr(-7)==="_plugin"&&delete e[a]},initLegacyOptions:function(){var a,b={DR_id:"dr_key",vglnk_api_key:"key",vglnk_cuid:"cuid",
vglnk_domain:"api_url",vglnk_reaf:"reaffiliate",vglnk_subid:"sub_id"};for(a in b)window[a]!==void 0&&(k[b[a]]=window[a],a==="vglnk_domain"&&(k[b[a]]+="/api"))},initLegacyCallbacks:function(){var a,b={vl_cB:c.bind(this.onApiClick,this),vl_disable:function(){e.enabled=!1}};for(a in b)window[a]=b[a]},initLinks:function(){c.each(document.links,c.bind(this.preprocessLink,this))},initPlugins:function(){var a,b=1,d=[],e=function(){var g=[],h=function(a){return function(){if(a){var b=Array.prototype.slice.call(arguments);
b.unshift("custom",a);l.log.apply(this,b)}}};a=null;c.each(d,function(a){var b;b=a[0];var d=a[1],e=a[2];(b=window.vglnk&&window.vglnk[b+"_plugin"])?(a=c.type(b.run)==="function"?b.run:b,b=c.type(b.setup)==="function"?b.setup:null,d&&d.mode===1?(b&&b(d,c.clone(c),k,h(d.key)),delete d.mode):a&&(b&&!e&&b(d,c.clone(c),k,h(d.key)),a(d,c.clone(c),k,h(d.key)))):g.push(a)});d=g;d.length>0&&(a=setTimeout(c.exceptionLogger(e),Math.min(Math.max(Math.pow(2,++b),100),5E3)))},g=function(c,g){return function(c,
g){return function(){d.push([c,g,!0]);b=1;clearTimeout(a);e()}}(c,g)};return function(a){for(var b in a)typeof a[b]==="object"&&a[b].enabled!==!1&&(d.push([b,a[b]]),a[b].mode===1&&this.expose("init_"+b,g(b,a[b])));e()}}(),isRewritable:function(){var a=c.canonicalizeHostname(document.location);return function(b){var d,f="";try{d=b.hostname,f=b.protocol,d.charAt(0)}catch(g){return!1}d!==""&&(d=c.canonicalizeHostname(b));return!(d===""||a===d||!f.match(/^https?:$/i)||e.norewrite[d]||!e.rewrite_original&&
!c.cache(b,"type")||c.hasRel(b,"norewrite")||c.hasRel(b,"noskim"))}}(),initEvents:c.destructing(function(){var a=c.traits.windowLevelHandlers?window:document;c.on(a,"mousedown",function(a){a=a||window.event;if((a=c.eventLink(a))&&!c.cache(a,"evented"))c.on(a,"click",function(){}),c.cache(a,"evented",!0)});if(!c.traits.quirksMode||l.harmony(c.harmony.UNSAFE_QUIRKSMODE_HANDLERS))c.on(a,"click",c.bind(l.onClick,l)),c.on(a,"contextmenu",c.bind(l.onContextmenu,l))}),log:function(a,b,d,f){var g=c.toQuery({nocache:c.uniqid()}),
i="pixel.gif";if(a==="custom")g+="&"+c.toQuery({key:b,type:d}),c.each(c.type(f)==="array"?f:[f],function(a){c.each(["e","i","o"],function(b){delete a[b]});g+="&"+c.toQuery(a)});else{g+="&"+c.toQuery({key:e.key,drKey:e.key?null:e.dr_key});if(a==="time")i="time.gif",a={libId:e.library_id,time:d,type:b};else if(a==="exception")a={e:b,o:d};else if(a==="info")a={i:b};else return;g+="&"+c.toQuery(a)}c.createEl("img").src=e.api_url+"/"+i+"?"+g},logException:function(a){if(e.debug){var b={link:c.cache(this,
"link"),loc:document.location.href,UA:navigator.userAgent};typeof a==="string"?b.message=a:b=c.extend(b,a);this.log("exception",a,c.toQuery(b))}},logTime:function(){var a;return function(b){arguments.length===0?a=(new Date).getTime():this.log("time",b,(new Date).getTime()-a)}}(),onApiClick:function(a,b,d,f,g){var i=f||a.href,f=c.bind(function(){this.redirect(i,b,d)},this);typeof g==="object"&&(g.tracking||g.image)?(a=c.createEl(g.tracking?"iframe":"img",{src:g.tracking||g.image},{height:0,width:0,
visibility:"hidden"}),document.body.appendChild(a),setTimeout(c.exceptionLogger(f),g.timeout||e.hop_timeout)):f()},onApiPing:function(a,b,d,f,g,i){e.rewrite_original=!1;var g=c.reformatKeys(g||{}),h,j,k;j=function(a){var b={},d=function(a){c.isArray(a)?b[a[0]]=a[1]:b[a]=1};c.isArray(a)&&c.each(a,d);return b};k=c.extend(e.plugins,g.plugins);e=c.extend(e,g);delete e.plugins;e.library_id=a;e.click_timeout=b;e.time_ping&&this.logTime("png");c.extend(e.norewrite,j(d));c.extend(e.swap,j(f));c.extend(e.nofollow,
j(i));for(h in e)h.toLowerCase().substr(0,2)==="on"&&h.length>2&&c.type(e[h])==="function"&&(c.on(l,h.toLowerCase().substr(2),c.bind(e[h],window)),delete e[h]);this.initPlugins(k);this.initLinks();this.initEvents();this.fire("libready")},onClick:function(a){var a=a||window.event,b=a.ctrlKey||a.metaKey||a.altKey||a.shiftKey,d=a.which&&a.which===1||a.button===0,e=c.eventLink(a);if(e&&this.isRewritable(e)&&!b&&d&&!c.isDefaultPrevented(a))return this.click(e),c.preventDefault(a)},onContextmenu:function(a){(a=
c.eventLink(a||window.event))&&this.isRewritable(a)&&this.handleRightClick(a,"setup")},opt:function(a,b){b!==void 0&&this.publicOptions()[a]!==void 0&&(e[a]=b);return e[a]},ping:function(){var a=!1;return function(){if(!a&&(e.key||e.dr_key))a=!0,this.logTime(),this.api("ping",null,{fn:c.bind(this.onApiPing,this)})}}(),preprocessLink:function(a){if(this.isRewritable(a)){var b;b=c.createA(e.api_url);if(a.pathname=="/api/click"&&(a.hostname==b.hostname||a.hostname.match(/(^|\.)(api|cdn|apicdn)\.viglink\.com$/)))if(b=
c.fromQuery(a.search),b.out!==void 0)a.href=b.out,delete b.out,c.cache(a,"params",b);if(e.swap[a.href])a.href=e.swap[a.href];if(e.nofollow[a.href]&&!c.hasRel(a,"nofollow"))a.rel=(a.rel?a.rel+" ":"")+"nofollow";if(window.IPBoard&&window.IPBoard.prototype&&window.IPBoard.prototype.delegate&&c.hasRel(a,"external"))a.rel=a.rel.replace(/(^| )external( |$)/,""),a.target="_blank";return a}},publicOptions:function(){var a={};return function(b){c.type(b)==="object"&&(a=b);return c.extend({},a)}}(),redirect:function(a,
b,d){!c.traits.crossWindowCommunication&&!b?(d=window.open(a,d),d.focus()):c.traits.jsRedirectSetsReferrer?setTimeout(c.exceptionLogger(function(){!b||b===window.self?window.location=a:c.contextIsAncestor(b)?b.location=a:b.location.replace(a)}),0):(d==="_blank"&&(d=c.uniqid("win_")),d=c.createA(a,d),d.rel="norewrite",document.body.appendChild(d),d.click(),d.parentNode.removeChild(d))}};l.init()})(typeof vglnk_self==="undefined"?"vglnk":vglnk_self);window.vglnk=window.vglnk||{};
window.vglnk.link_affiliation_plugin={run:function(m,l,c){c.opt("rewrite_original",!0)}};window.vglnk=window.vglnk||{};window.vglnk.modified_clicks_plugin={run:function(m,l,c){c.opt("rewrite_modified",!0)}};