/*
 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) 2010 VigLink. Rights reserved and patent(s) pending.
*/
var vglnk=vglnk||{};
vglnk=function(){var g={},e={bind:function(a,c){return function(){return a.apply(c,arguments)}},browser:function(){var a,c={},b,d=navigator.userAgent.toLowerCase().replace(/\s*[()]\s*/g,"; ").replace(/(\/[\w.]+)\s+/g,"$1; ").replace(/\;\s*$/,"").split(/;\s*/);for(a=0;a<d.length;a++){b=(/[\/ :]([^\/ :]+)$/.exec(d[a])||[])[1];c[b?d[a].substr(0,d[a].length-b.length-1):d[a]]=b||true}return{ie:c.msie,ios:c.mobile&&c.safari,opera:c.opera,playstation:c.playstation}}(),cache:function(){var a={},c="vglnk_"+
(new Date).getTime(),b=0;return function(d,f,h){var i=d[c];if(!i&&h===undefined)return null;i||(i=++b);if(!a[i]){d[c]=i;a[i]={}}if(h!==undefined)a[i][f]=h;return typeof f==="string"?a[i][f]:a[i]}}(),canonicalizeHostname:function(a){if(typeof a==="string")a=e.createA(a);return a.hostname?a.hostname.toString().replace(/^www\./,"").toLowerCase():""},createA:function(a,c){return e.createEl("a",{href:a,target:c})},createEl:function(a,c,b){var d;a=document.createElement(a);c=c||{};b=b||{};for(d in c)a[d]=
c[d];for(d in b)a.style[d]=b[d];return a},destructing:function(a){return function(c){var b=false,d;return function(){if(!b){d=c.apply(null,arguments);b=true}return d}}(a)},eventLink:function(a){a=a.target||a.srcElement;var c;do if(a.nodeType===1){c=a.tagName.toUpperCase();if(c==="A"||c==="AREA")return a}while(a=a.parentNode)},exceptionLogger:function(){var a=function(){};return function(c,b){if(b)a=c;else return function(){if(g.dev)c.apply(this,arguments);else try{c.apply(this,arguments)}catch(d){a(d)}}}}(),
extend:function(){var a,c,b,d,f=arguments.length,h=arguments[0]||{};for(c=1;c<f;c++){d=arguments[c];if(d!==undefined&&d!==null)for(b in d){a=d[b];if(h!==a)if(a!==undefined)h[b]=a}}return h},isArray:function(a){return Object.prototype.toString.call(a)==="[object Array]"},isDefaultPrevented:function(a){return a.isDefaultPrevented&&a.isDefaultPrevented()||a.returnValue===false||a.defaultPrevented===true},jsonp:function(a,c,b){var d,f;b=e.extend({fn:function(){},"return":false,timeout:null},b);if(typeof b.fn===
"string")c=e.extend(c,{jsonp:b.fn});else if(typeof b.fn==="function"){d=e.destructing(b.fn);f=e.uniqid("vglnk_jsonp_");c=e.extend(c,{jsonp:f});window[f]=e.exceptionLogger(function(){d.apply(this,arguments);window[f]=undefined});b.timeout!==null&&setTimeout(e.exceptionLogger(d),b.timeout)}c=e.toQuery(c);a=e.createEl("script",{type:"text/javascript",src:a+(c.length?"?":"")+c});if(b["return"])return a.src;else{b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}},on:function(a,
c,b){var d;try{d=a["on"+c]}catch(f){}if(typeof d==="function")a["on"+c]=function(h){h=h||window.event;h.returnValue=d.apply(a,arguments);return h.returnValue};if(a.addEventListener)a.addEventListener(c,b,false);else a.attachEvent&&a.attachEvent("on"+c,b)},preventDefault:function(a){a.preventDefault&&a.preventDefault();return a.returnValue=false},ready:function(){var a=false,c=[],b=false,d,f,h,i,k;if(document.addEventListener)h=function(){document.removeEventListener("DOMContentLoaded",h,false);k()};
else if(document.attachEvent)i=function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",i);k()}};d=function(){if(!a){a=true;if(document.readyState==="complete")return k();else if(document.addEventListener)document.addEventListener("DOMContentLoaded",h,false);else if(document.attachEvent){document.attachEvent("onreadystatechange",i);var j=false;try{j=window.frameElement===null}catch(m){}document.documentElement.doScroll&&j&&f()}e.on(window,"load",k)}};f=function(){if(!b){try{document.documentElement.doScroll("left")}catch(j){setTimeout(f,
1);return}k()}};k=function(){if(!b){if(!document.body)return setTimeout(e.exceptionLogger(k),13);b=true;if(c){var j,m=c.length;for(j=0;j<m;j++)c[j]();c=null}}};return function(j){d();b?j():c.push(j)}}(),reformatKeys:function(a){var c,b,d=function(f){return"_"+f.toLowerCase()};for(c in a){b=c.replace(/([A-Z])/,d);if(b!==c){a[b]=a[c];delete a[c]}}return a},toQuery:function(a){var c,b="";for(c in a)if(a[c]!==null&&a[c]!==undefined)b+="&"+encodeURIComponent(c)+"="+encodeURIComponent(a[c]);return b.substr(1)},
uniqid:function(a){return(a?a:"")+(new Date).getTime()}},l={api:function(a,c,b){return e.jsonp(g.api_url+"/"+a,e.extend({cuid:g.cuid,format:"jsonp",key:g.key,loc:location.href,subId:g.sub_id,v:1},c),b)},click:function(){var a,c;a=function(b,d){if(d!=="_self"&&(e.browser.ie||e.browser.opera))return"go";try{if(b.document===undefined)throw true;return"jsonp"}catch(f){return"go"}};c=function(b){b=window.open("",b);b.focus();return b};return function(b,d){d=b.target||d||"_self";d=d===window.name?"_self":
d;var f,h,i=c(d),k=a(i,d);f=e.destructing(e.bind(function(){g.time_click&&arguments.length&&this.logTime("clk");var j=Array.prototype.slice.call(arguments);j.unshift(b,i,d);this.onApiClick.apply(this,j)},this));e.cache(this,"link",typeof b==="string"?b:b.href);if(typeof b==="string"){b=e.createA(b,d);if(!this.preprocessLink(b))return f(b.href)}if(!g.enabled)return f(b.href);h={format:k,libid:g.library_id,out:b.href,ref:document.referrer||null,reaf:g.reaffiliate||null,title:document.title,txt:b.innerHTML};
this.logTime();if(k==="go"){if(d==="_blank"&&(e.browser.ie||e.browser.opera))d=i.name=e.uniqid("win_");this.redirect(this.api("click",h,{"return":true}),i,d)}else if(i===window.self)this.api("click",h,{fn:f,timeout:g.click_timeout});else{f=e.exceptionLogger(f);setTimeout(f,g.click_timeout);i.document.open();i.callback=f;i.document.write("<html><head><title>"+b.href+'</title><script type="text/javascript" src="'+this.api("click",h,{fn:"callback","return":true})+'"><\/script></head></html>');i.document.close()}}}(),
init:e.exceptionLogger(function(){e.exceptionLogger(e.bind(this.logException,this),true);this.initV1Api();this.initOptions();g.enabled&&this.ping()}),initLinks:function(){var a,c,b,d=document.links;a=0;for(c=d.length;a<c;a++){b=d[a];this.preprocessLink(b)&&e.on(b,"mouseover",e.bind(this.onMouseover,this))}},initOptions:function(){g=e.extend({cuid:null,dev:false,enabled:!e.browser.playstation,key:null,sub_id:null,reaffiliate:false,url:null},vglnk,{click_timeout:1E3,hop_timeout:2E3,debug:false,library_id:null,
nofollow:{},norewrite:{},swap:{},time_click:false,time_ping:false});if(!g.api_url){var a,c,b,d=document.getElementsByTagName("script");a=0;for(c=d.length;a<c;a++)if(d[a].src&&(b=d[a].src.match(/^(.*)\/vglnk\.js(\?|$)\s*/))){g.api_url=b[1];break}}},initV1Api:function(){var a,c={vl_cB:e.bind(this.onApiClick,this),vl_ping:e.bind(this.onApiPing,this),vl_disable:function(){g.enabled=false}},b={vglnk_api_key:"key",vglnk_cuid:"cuid",vglnk_domain:"api_url",vglnk_reaf:"reaffiliate",vglnk_subid:"sub_id"};for(a in c)window[a]=
c[a];for(a in b)if(window[a]!==undefined)vglnk[b[a]]=window[a]+(a==="vglnk_domain"?"/api":"")},isRewritable:function(){var a=e.canonicalizeHostname(document.location);return function(c){var b;b=e.canonicalizeHostname(c);return!(a===b||b===""||g.norewrite[b]||/(^| )no(rewrite|skim)( |$)/.test(c.rel))}}(),log:function(a,c,b){var d="pixel.gif";if(a==="time"){d="time.gif";a={libId:g.library_id,time:b,type:c}}else if(a==="exception")a={e:c,o:b};else return;e.createEl("img").src=g.api_url+"/"+d+"?"+e.toQuery(e.extend(a,
{key:g.key}))},logException:function(a){if(g.debug){var c={link:e.cache(this,"link"),loc:document.location.href,UA:navigator.userAgent};if(typeof a==="string")c.message=a;else c=e.extend(c,a);this.log("exception",a,e.toQuery(c))}},logTime:function(){var a;return function(c){if(arguments.length===0)a=(new Date).getTime();else this.log("time",c,(new Date).getTime()-a)}}(),onApiClick:e.exceptionLogger(function(a,c,b,d,f){var h=d||a.href,i=e.bind(function(){this.redirect(h,c,b||a.target)},this);if(typeof f===
"object"&&(f.tracking||f.image)){d=e.createEl(f.tracking?"iframe":"img",{src:f.tracking||f.image},{height:0,width:0,visibility:"hidden"});document.body.appendChild(d);setTimeout(e.exceptionLogger(i),f.timeout||g.hop_timeout)}else i()}),onApiPing:e.exceptionLogger(function(){g=e.extend(g,typeof arguments[4]==="object"?e.reformatKeys(arguments[4]):{});g.library_id=arguments[0];g.click_timeout=arguments[1];g.time_ping&&this.logTime("png");var a,c,b,d,f,h={2:"norewrite",3:"swap",5:"nofollow"};for(f in h)if(e.isArray(arguments[f])){a=
arguments[f];c={};b=0;for(d=a.length;b<d;b++)if(e.isArray(a[b]))c[a[b][0]]=a[b][1];else c[a[b]]=1;g[h[f]]=e.extend(g[h[f]],c)}e.ready(e.bind(this.initLinks,this))}),onClick:e.exceptionLogger(function(a){a=a||window.event;var c=a.ctrlKey||a.metaKey||a.altKey||a.shiftKey,b=a.which&&a.which===1||a.button===0,d=e.eventLink(a);if(!(!d||c||!b||e.isDefaultPrevented(a))){this.click(d);return e.preventDefault(a)}}),onMouseover:e.exceptionLogger(function(a){if((a=e.eventLink(a||window.event))&&!e.cache(a,"evented")){e.on(a,
"click",e.bind(this.onClick,this));e.cache(a,"evented",true)}}),ping:function(){if(g.key){this.logTime();this.api("ping")}},preprocessLink:function(a){if(this.isRewritable(a)){if(g.swap[a.href])a.href=g.swap[a.href];if(g.nofollow[a.href])a.rel=(a.rel?a.rel+" ":"")+"nofollow";return a}},redirect:function(a,c,b){if(e.browser.ie||e.browser.opera){b=e.createA(a,b);document.body.appendChild(b);b.click();b.parentNode.removeChild(b)}else setTimeout(e.exceptionLogger(function(){if(!c||c===window.self)window.location=
a;else c.location.replace(a)}),0)}};l.init();return e.extend(function(){},{click:e.exceptionLogger(e.bind(l.click,l))})}();