var _gaq = _gaq || [];
var utmb = get_utm_value(document.cookie, '__utmb=', ';');
var utmc = get_utm_value(document.cookie, '__utmc=', ';');
var pageview_count = get_utm_value2(utmb, utmc);
//alert("Type "+pageview_count);
if(pageview_count!=1)
{
//alert("Welcome to Pittsburgh.Net!");
//pageTracker._setCustomVar(3, "visitor-type", "justlooking", 2);
//_gaq.push(["_setCustomVar", 1, "visitor-type", "justlooking", 2]);
}
//This function extracts the "_utmb" and "_utmc" string from the cookies set by Google Analytics
//This function was originally written by the Google Analytics team (urchin.js)
function get_utm_value(l,n,s)
{
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i, i2, i3, c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1)
{
i2=l.indexOf(s,i);
if (i2 < 0)
{
i2=l.length;
}
c=l.substring((i+i3),i2);
}
return c;
}
//This function extracts the "pageview count" value from the _utmb cookie
function get_utm_value2(utmb,utmc)
{
var i, j, k;
var utmc=utmc+'.';
i=utmc.length;
j=utmb.indexOf(".", i);
k=utmb.substring(i,j);
return k;
}

/****************************************************
     Author: Brian J Clifton
     Url: http://www.advanced-web-metrics.com/scripts
     This script is free to use as long as this info is left in
     
     Combined script for tracking external links, file downloads and mailto links
     
     All scripts presented have been tested and validated by the author and are believed to be correct
     as of the date of publication or posting. The Google Analytics software on which they depend is 
     subject to change, however; and therefore no warranty is expressed or implied that they will
     work as described in the future. Always check the most current Google Analytics documentation.

     Thanks to Nick Mikailovski (Google) for intitial discussions & Holger Tempel from webalytics.de
     for pointing out the original flaw of doing this in IE.
	
	****************************
	http://sites.google.com/site/captthudcodescraps/automatic-ga-link-tracker
	 Hacked on and probably mangled by Ed Cramer, summer 2010
	 captthud@captthud.net
	 
	 I want to track PDF downloads with this, but I don't want to use the actual path of the PDF file
	 for my statistics. I'd like the script to post information about the parent page that the user
	 found the PDF on. 
	 
	 The original code used the "traditional" tracking code snippet, and I'd prefer the "asyncrhonous"
	 code because it's supposed to be faster. I've changed a lot of the formatting and I think
	 I've removed the bug fix for IE6/7.
	 
	 Put  
		<script type="text/javascript" src="/path_to_the_script/addLinkerEvents-ga.js"></script>
	in your header and then call
		<script> addLinkerEvents(); </script>
	at the end of the html body. Browser debuggers (Firebug, dev tools in Chrome and IE) are amazing, use them!

	 
****************************************************/
// Only links written to the page (already in the DOM) will be tagged
// This version is for ga.js (last updated Jan 15th 2009)


function addLinkerEvents() {
	var as = document.getElementsByTagName("a");
	var thisHostName = window.location.host;
	var extTrack = [thisHostName];
	// List of local sites that should not be treated as an outbound link. Include at least your own domain here
	
	var extDoc = [".doc",".xls",".exe",".zip",".pdf",".js"];
	//List of file extensions on your site. Add/edit as you require
	
	/*If you edit no further below this line, Top Content will report as follows:
		/ext/url-of-external-site
		/downloads/filename
		/mailto/email-address-clicked
		
		Haha, like I can let things be - time to break stuff! (Ed)
	*/
	
	for(var i=0; i<as.length; i++) 
	{
		var flag = 0;
		var tmp = as[i].getAttribute("onclick");

		
		/* I removed this because I don't know what it's for. Classy, right? (Ed)
		
		// IE6-IE7 fix (null values error) with thanks to Julien Bissonnette for this
		if (tmp != null) 
		{
		  tmp = String(tmp);
		  if (tmp.indexOf('urchinTracker') > -1 || tmp.indexOf('_trackPageview') > -1) 
			continue;
    	}
		*/
		
		// Tracking outbound links off site - not the GATC
		for (var j=0; j<extTrack.length; j++) 
		{					
			if (as[i].href.indexOf(extTrack[j]) == -1 && as[i].href.indexOf('google-analytics.com') == -1 ) 
			{
				flag++;
			}
		}
		
		if (flag == extTrack.length && as[i].href.indexOf("mailto:") == -1)
		{
			as[i].onclick = function()
			{ 
				var splitResult = this.href.split("//");					 //removed... Looks like it's part of the IE fix from before (Ed)
				_gaq.push(['_trackPageview', '/external/' +splitResult[1]]); //+ ";" +((tmp != null) ? tmp+";" : "");
			};
				//alert(as[i] +"  ext/" +splitResult[1])
		}		

		// Tracking electronic documents - doc, xls, pdf, exe, zip
		for (var j=0; j<extDoc.length; j++) 
		{
			if (as[i].href.indexOf(extTrack[0]) != -1 && as[i].href.indexOf(extDoc[j]) != -1) 
			{
				as[i].onclick = function()
				{ 
					var parentURL = this;
					parentURL = parentURL.ownerDocument;
					parentURL = parentURL.URL;	// I don't know why I can't put all of these on one line.
												// this.ownerDocument.URL would have been nice, but it doesn't work.
												// IE8 handles local variables differently, "this" isn't automatically available.
					parentURL = parentURL.split(extTrack[0]);
					var realURLcomponents = this.href.split("/");														//removed... Looks like it's part of the IE fix from before (Ed)
					_gaq.push(['_trackPageview', parentURL[1] + '/' + realURLcomponents[realURLcomponents.length -1]]); //+ ";" +((tmp != null) ? tmp+";" : "");
				}
				//alert(as[i] +"  downloads" +splitResult[1])
				break;
			}
		}


		// added to track mailto links 23-Oct-2007
		// updated 31-Oct-2008 to remove break command - thanks to Victor Geerdink for spotting this
		if (as[i].href.indexOf("mailto:") != -1) 
		{
			as[i].onclick = function()
			{
				var splitResult = this.href.split(":");						//removed... Looks like it's part of the IE fix from before (Ed)
				_gaq.push(['_trackPageview', '/mailto/' +splitResult[1]]); //+ ";"+((tmp != null) ? tmp+";" : "");
			}
			//alert(as[i] +"  mailto/" +splitResult[1])
		}
	}
}


