$(document).ready(function(){
	if (user.jsSupportLevel==0){return;}
	$("html").addClass("js").addClass("jsSupportLevel"+user.jsSupportLevel);
	$("a[href^='http://' ]").not("[href^='http://"+window.location.host+"']").each(function(){
		if ($("img",this).length>0 && $(this).hasClass('pop')){
			this.title= "Link opens in a new window";
			$(this).click(function(){
			    window.open(this.href);
				return false;
			});
		} else if ($("img",this).length>0){
			// ignore if anchor contains an image
		} else {
			if (this.title&&this.title.length){
				this.title+= " (opens in a new window)";
			} else {
				this.title= "Link opens in a new window";
			}
			$(this).append('<img class="external" alt="external link" src="/global/images/misc/external.gif" />').click(function(){
			    window.open(this.href);
				return false;
			});
			$(this).data('hasexternalicon',true)
		}
	});
	$("a[href$='.pdf']").each(function(){
		if (!$(this).data('hasexternalicon')) {
			if (this.title && this.title.length) {
				this.title += " (opens in a new window)";
			}
			else {
				this.title = "Link opens in a new window";
			}
			$(this).append('<img class="external" alt="external link" src="/global/images/misc/external.gif" />').click(function(){
				window.open(this.href);
				return false;
			});
		}
	});
	$("a[href*='/Global/']").click(function(event){
		if (!window.pageTracker || !pageTracker._trackPageview || !event.target || !event.target.href){return}
		try {
			var url = event.target.href.toString().split('/Global/')[1];
			pageTracker._trackPageview('/x-internal-asset/Global/'+url);
			//if (window.console && console.log) console.log('tracking url:/Global/'+url)
		} catch (e) {}
	});
	$('div.navbar ul a[text="© 2009 Map of Medicine. All rights reserved."]').hide();
	(function(){
		if (!document.getElementsByTagName){return;}
		var existentimg = new Image;
		existentimg.onload = function(){
			$('html').addClass('img');
			var nonexistentimg = new Image;
			nonexistentimg.onload = function(){
				$('html').removeClass('img');
			}
			nonexistentimg.src="/void.gif";
		}
		if (document.images.length)
		existentimg.src = document.images[0].src; 
	})();
	/*
	(function(){
		$('body').click(function(event){
			var target = event.target;
			if(target.nodeName == "a" && target.className.match("track")){
				console.log('some message')
			}else{
				console.log('ignored')
			}
		})
	})();
	*/
})
