jQuery.noConflict();

var options = { path: '/', expires: 30 };

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

jQuery(document).ready(function() {
	/*********
		Convert span with class="email" to clickable and Google Analytics tracked link
		
		Input: <span class="email">email @ domain . com</span>
		or:    <span class="email">email(at)domain(dot)com</span>
		or combination of signs and at/dot in text.
		
		Output <a href='mailto:email@domain.com' onclick='...'>email@domain.com</a>

		Optional title attribute can be used for the link text.
		Input: <span class="email" title="email us">email @ domain . com</span>
		Output <a href='mailto:email@domain.com' onclick='...'>email us</a>
		
		26 Nov 2009: Updated replace strings to be case insensitive and not limited to first replacement.
	*********/
	jQuery(".email").each(function() {
		var email = jQuery(this).text().toLowerCase();
		email = email.replace(/\(/g, " ");
		email = email.replace(/\)/g, " ");
		if ((email.indexOf("@") != -1) || (email.indexOf(" at ") != -1) || (email.indexOf(" dot ") != -1)) {
			email = email.replace(/\s+dot\s+/gi, ".");
			email = email.replace(/\s+at\s+/gi, "@");
			var parts = email.split("@");
			if (parts.length == 2) {
				if (jQuery(this).attr('title').length > 0) var text = jQuery(this).attr('title');
				else var text = email;
				var domain = parts[1].split(".");
				email = parts[0].trim() + "@" + domain[0].trim() + "." + domain[1].trim();
				jQuery(this).replaceWith("<a href='mailto:" + email + "' onclick='javascript: pageTracker._trackPageview(\"/email/" + email + "\");'>" + text + "</a>");
			}
		}
	});
	
	/********
	 Tag external links
	 ********/	
	 jQuery('.typography a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).addClass("external");
	
	/********
	 Add Google Analytics tracking to document links
	 ********/	
	jQuery("a").click(function() {
		if ( jQuery(this).attr("href").match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i) ) {
			//alert(jQuery(this).attr("href"));
			pageTracker._trackPageview(jQuery(this).attr("href"));
		}
	});
}); 
