// Basic helper javascript for the G2K website
function g2k_download_handler(e) { gaq.push(['_trackPageview', $(this).attr('href')]); }
function g2k_mailto_handler(e) { gaq.push(['_trackPageview', '/mailto/'+$(this).attr('href').substring(7).replace(/@/g, '-at-')]); }
function g2k_external_handler(e) { gaq.push(['_trackPageview', '/external/'+$(this).attr('href').substring(5)]); }
$(function() {
	$('a.emlink').each(function() {
		rev_email = $(this).text();
		email=""; for (i = rev_email.length-1; i >=0; i--) { email+=rev_email.charAt(i) }
		$(this).attr('href', 'mailto:'+email);
		$(this).text(email);
		$(this).css('unicodeBidi','');
		$(this).css('direction', 'ltr');
	});
	$('a').each(function() { // Set up analytics
		var url = $(this).attr('href');
		try {
			// Check if it's a file download
			if (url.match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/)) {
				$(this).click(g2k_download_hander); return; }
			if (this.protocol == 'mailto:') {
				$(this).click(g2k_mailto_handler); return; }
			// Check if it's an external or a mailto link
			if (url.indexOf(':') != -1 && url.indexOf(':') < 10 && this.hostname != location.host) {
				$(this).click(g2k_external_handler); return; }
		} catch(e){}
	});
	// Allow form elements to contain default text that clears when clicked on:
	$(".defaultText").focus(function() {
		if ($(this).val() == $(this).attr("title")) {
			$(this).removeClass("defaultTextActive");
			$(this).val("");
		}
	});
	$(".defaultText").blur(function() {
		if ($(this).val() == "" || $(this).val() == " ") {
			$(this).addClass("defaultTextActive");
			$(this).val($(this).attr("title"));
		}
	});
	$(".defaultText").blur();
});

