$(document).ready(function() {
	prepare_links();
	prepare_print_icon();
});

function prepare_links() {
  // order matters for priority
  // add pdf icon to left of pdf links and open in a new window
  $('a[href$=".pdf"]').filter(function(){var t = $(this).text(); return t && $.trim(t) != "";}).addClass("icon_pdf").click(function() {
      window.open($(this).attr('href'), 'pdfWindow');

      return false;
  });

  // add external icon to any link that are not on this domain and open in a new window
  $('a[href^="http://"], a[href^="https://"]').filter(function(){var link = $(this); return !(/https?:\/\/(www\.)?grasshoppersdistribution\./).test(link.attr('href')) && link.attr('class').indexOf('icon') == -1 && link.attr('rel') != 'external';}).addClass("icon_external").click(function() {
      window.open($(this).attr('href'), 'externalWindow');

      return false;
  });
	
	$('a[rel="external"]').click(open_window);
}


function open_window() {
	var new_window = window.open($(this).attr("href"));
	new_window.focus();
	
	// stop event propagation
	return false;
}

function prepare_print_icon() {
	var div = $('#share');
	
	if (div.length != 1) {
		return false;
	}
	div.prepend('<a id="print" href="#" title="Print Page">Print Page</a>');
	
	$('#print').click(function() {
		window.print();
		return false;
	});
}



