// Written By: Paul Lyon (plyon@topfloortech.com)
// Company: Topfloor Technologies
// July 8th, 2008
//
// Description:
// 
// This script will automatically apply tracking to Downloads and forms.
// Files that will be tracked will have the file extension of zip, pdf, xls,
// doc, csv, txt, ppt, xml, rtf, and exe. Additional file extensions that 
// need tracking can be, by adding the file extension to the regex_files_types. 
// For insite tracking to work, the arr must be appended with the URL as 
// the index and the action key as the value.

//var regex_files_types = /.+\.(zip|pdf|xls|doc|csv|txt|ppt|xml|rft|exe)$/; 
var regex_files_types = /.+\.(7z|aac|avi|csv|doc|exe|flv|gz|mp(3|4|e?g)|mov|pdf|ppt|rar|sit|tar|txt|wma|wmv|xls|xml|zip)$/;

$("document").ready(function() {
	// Process Insite Metrics
	if((typeof tft_im_files != "undefined") && (typeof tft_im_files != "null")){
		$("a").click(function() {
			// Work around to $(this).attr("href") - will only return the path
			var deep_link = $(this).attr("protocol") + "//" + $(this).attr("host") + $(this).attr("pathname"); 
			deep_link = deep_link.replace(/\:80/, "/");
			var action_key = tft_im_files[$(this).attr("pathname")];
			if(typeof action_key != 'undefined' && action_key != '' && typeof action_key != "null") {
				var src = "http://www.topfloortech.com/insitemetrics/uRMJ/uniformv2.php?actk=" + action_key;
				var img = new Image(0,0);
			  img.src = src;
				window.open(deep_link,'resizable,scrollbars');
				return false;
			}
			return true;
		});
	}
}); // end of ready