// JavaScript Document

if(typeof shell==="undefined"){shell={}}shell.Metrics=new Class({initialize:function(){this.domainRegex=new RegExp("(https?:)//([^\\/]+).*","i");this.isGAEnabled=(typeof _gaq!=="undefined");this.isSageEnabled=(typeof SHELL_metrics!=="undefined"&&typeof SHELL_metrics.dd!=="undefined"&&typeof SHELL_metrics.ci!=="undefined")},setupMetrics:function(){var a=this;if(this.isSageEnabled){this.addSageScript()}if(this.isGAEnabled){this.addGAScript();$$(".ga_link_by_post").each(function(b){a.setupGALinkHandler(b)});$$("form").each(function(b){a.setupGAFormHandler(b)})}$$(".metrics").each(function(b){a.setupSageEventHandlers(b);a.setupGAEventHandlers(b)});$$(".follow_us a").each(function(b){b.set("class","metrics_follow");a.setupGAEventHandlers(b)});$$(".page_tools .message a, .page_tools .bookmark .icons a").each(function(b){b.set("class","metrics_tools");a.setupGAEventHandlers(b)});$$(".page_tools .printer a").each(function(b){b.set("class","metrics_other");a.setupGAEventHandlers(b)});$$("form.search input.button").each(function(b){b.set("class",b.get("class")+" metrics_search");a.setupGAEventHandlers(b)})},addSageScript:function(){var b=document.createElement("script"),a=document.getElementsByTagName("script")[0];b.type="text/javascript";b.async=true;b.src=document.location.protocol+"//"+SHELL_metrics.dd+"/tag-"+SHELL_metrics.ci+".js";a.parentNode.insertBefore(b,a)},addGAScript:function(){var b=document.createElement("script"),a=document.getElementsByTagName("script")[0];if(window.name===""){_gaq.push(["_trackPageview"])}b.type="text/javascript";b.async=true;b.src=("https:"===document.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";a.parentNode.insertBefore(b,a)},trackGAEvent:function(b,c,a,d){if(!this.isGAEnabled){return}if(isNaN(d)){_gaq.push(["_trackEvent",b,c,a])}else{_gaq.push(["_trackEvent",b,c,a,d])}},trackSageEvent:function(a,c,b){if(!this.isSageEnabled){return}if(a==="Links"){sage_ev(c,b)}else{if(a==="Flash"){sageflash(b,c)}}},getHandler:function(b,c,a){handler=function(d){shell.metrics.trackGAEvent(b,c,a);return true};return handler},setupGAEventHandlers:function(e){var d="",f="",b="",c,a;if(e.hasClass("metrics_download")){d="Downloads";a=e.get("href");f=a.replace(/^.*\./,"").toUpperCase();b=a+", "+document.URL}else{if(e.hasClass("metrics_external")){d="External Links";a=decodeURIComponent(e.get("href"));f=a.replace(/^(.*URL=)https?:\/\/(www.)?([^\/]*)(.*)$/,"$3");b=a.replace(/.*&URL=/,"")}else{if(e.hasClass("metrics_tag")){d="Tag Cloud - "+document.URL;f=e.get("text");b=e.get("href")}else{if(e.hasClass("metrics_mailto")){d="Social";f="Mail to Shell";a=e.get("href").replace(/^mailto:/,"");b=a+", "+document.URL}else{if(e.hasClass("metrics_follow")){d="Social";f=e.get("href");b=document.URL}else{if(e.hasClass("metrics_tools")){d="Social";f=e.get("text");b=document.URL}else{if(e.hasClass("metrics_other")){d="Other";f=e.get("text");b=document.URL}else{if(e.hasClass("metrics_search")){d="Internal Search";b=document.URL;c=function(g){f=e.getPrevious().getElement("input").get("value");f=f.replace(/^\s+|\s+$/g,"");shell.metrics.trackGAEvent(d,f,b);return true}}}}}}}}}d=d.replace(/^\s+|\s+$/g,"");f=f.replace(/^\s+|\s+$/g,"");b=b.replace(/^\s+|\s+$/g,"");if(typeof c==="undefined"){c=this.getHandler(d,f,b)}e.addEvent("click",c);e.addEvent("keypress",c)},setupSageEventHandlers:function(c){var b,d,a;if(!c){return}if(c.hasClass("metrics_tag")){d=c.get("text");b=3}else{if(c.hasClass("metrics_download")){d=c.get("href");b=1}else{if(c.hasClass("metrics_external")){d=decodeURIComponent(c.get("href").replace(/.*&URL=/,""));b=2}else{return}}}a=function(e){shell.metrics.trackSageEvent("Links",b,d);return true};c.addEvent("click",a);c.addEvent("keypress",a)},setupGALinkHandler:function(d){if(d&&this.isGAEnabled&&d.hasClass("metrics_download")==false){var b=d.get("href");var a=this.domainRegex.exec(b);if(a&&a.length==3&&(a[1]!=window.location.protocol||a[2]!=window.location.host)){var c=function(f){try{_gaq.push(["_link",$(this).get("href")]);f.stop()}catch(e){}};d.addEvent("click",c);d.addEvent("keypress",c)}}},setupGAFormHandler:function(c){if(c&&this.isGAEnabled){var d=c.get("action");var a=this.domainRegex.exec(d);if(a&&a.length==3&&(a[1]!=window.location.protocol||a[2]!=window.location.host)){var b=function(e){_gaq.push(["_linkByPost",this])};c.addEvent("submit",b)}}}});window.addEvent("domready",function(){shell.metrics=new shell.Metrics();shell.metrics.setupMetrics()});
