if(typeof(console) != "object") {var console = new Object(); console.log = function() {} };

var path = top.location.pathname;
if (document.all) {path = path.replace(/\\/g,"/");}
path = path.substr(0,path.lastIndexOf("/")+1);

function pageTrack(wPage) {
	var cPage = path + wPage;
	trackitem(cPage)
}

function trackitem(wtrack) {
	console.log("tracking :" + wtrack);
	try {
		if (typeof(pageTracker) == 'object') {
			console.log("success");
			pageTracker._trackPageview(wtrack);			
		}
	} catch(err) {}
}

$(document).ready(function()
{
	trackOutbound();
});


function trackOutbound(prefix) {
	console.log("tracking outbound");
	if (prefix == null) {
		prefix = "";
	}
	else {
		prefix += " ";
	}
		
	/* Begin JQuery link tracking */
	// allows for link tracking to include a defined prefix for any given page
	if (typeof(trackingPrefix) != "string") {trackingPrefix = "";}	else {	trackingPrefix = "/" + trackingPrefix;	}	
	
	// find all A and AREA links to external sites, and enable onclick tacking
	//var allLinks = $("A[@href^=http://]:not([@href^=http://www.visitphilly.com]),AREA[@href^=http://]:not([@href^=http://www.visitphilly.com])");
	var allLinks = $(prefix + "A[href^='http://']:not([href*='www.visitphilly.com']):not([href$='.pdf']):not([href$='.mp3'])," + prefix + "AREA[href^='http://']:not([href*='www.visitphilly.com']):not([href$='.pdf']):not([href$='.mp3'])");
	allLinks.each(function(i){
			var thisHref = $(this).attr("href");
			thisHref = thisHref.replace("http://", "");			// remove http
			if (thisHref.charAt(thisHref.length - 1) == "/")	// trim ending slash
				thisHref = thisHref.substr(0,thisHref.length - 1);
			console.log(thisHref);
			$(this).click(function() { 
				trackitem('/outbound/' + thisHref)							   
			})
	});
	
	var allPdf = $(prefix + "a[href$='.pdf']," + prefix + "a[href$='.mp3']");
	allPdf.each(											 
		function(i){
			var thisHref = $(this).attr("href");
			thisHref = thisHref.replace("http://c0526532.cdn.cloudfiles.rackspacecloud.com/", "");	
			thisHref = thisHref.replace("http://www.visitphilly.com/", "");			
			console.log(thisHref);
			$(this).click(function() { 			
				trackitem('/downloads/' + thisHref)
			})
	
	});	
	
}

/* End JQuery link tracking */	

