function trackClick(url) {
	if(url.search("artisanintermediary") == -1 || url.search("pdf") != -1) {
		_gaq.push(['_trackPageview',url]);
		window.open(url,'_blank');
	} else {
		window.location = url;
	}
}

function checkHighlight(fundname) {
	var i = 0;
	$("#downloadsTable tbody tr").each(function(){
		if($(this).children("th").eq(0).text()==fundname) {
			if($(this).find("input").is(':checked')) {
				i++;
			}
		}
	});
	if(!i) {
		$("#downloadsTable tbody tr").each(function(j){
			if($(this).children("th").eq(0).text()==fundname) {
				$(this).removeClass("highlighted");
			}
		});
			
	}
}

$(function(){
	$("#downloadsTable input:checked").each(function() {
		var fundname = $(this).parent().siblings("th").eq(0).text();
		$("table tbody tr").each(function(){
			if($(this).children("th").eq(0).text()==fundname) {
				$(this).addClass("highlighted");
			}
		});
	});
	
	$("a[rel*='external'],a[href$='.pdf'],a[href$='.csv'],a[href$='.vcf'],a[href$='.vcard'],a[href^='http://'],a[href^='mailto:'],a[href$='mp3']").attr("target","_blank").click(function(){
		_gaq.push(['_trackPageview', $(this).attr('href')]);
		//alert("The following link or file was successfully tracked: \n" + $(this).attr("href"));
	});
	$('a[rel*="tooltip"]').cluetip({ dropShadow:false,cursor:'pointer',waitImage:false, cluetipClass: 'rounded',arrows: true, showTitle: false,width:500,clickThrough:false,attribute: 'href', fx: { open: 'fadeIn', openSpeed:200 }});
	$('a[rel*="maptip"]').cluetip({  dropShadow:false,positionBy:'bottomTop', cursor:'pointer',waitImage:false, cluetipClass: 'rounded',arrows: true, showTitle: false,width:500,clickThrough:false,attribute: 'href', fx: { open: 'fadeIn', openSpeed:200 }});
	
	var hoverConfig = {    
	     over: dropDown, timeout: 100, out: liftUp, interval:0
	};
	
	function dropDown() {
		$(this).addClass("hover").children("ul").slideDown(100).parent().siblings("li").children("ul").hide();
	}
	function liftUp() {
		$(this).removeClass("hover").children("ul").slideUp(100);
	}
	
	$("#navigation ul>li").hoverIntent( hoverConfig );

	$("table input:checkbox").change(function(){
		var fundname = $(this).parent().siblings("th").eq(0).text();
		
		if($(this).is(':checked')) {
			$(this).parent().parent().addClass("selected");
			$("#downloadsTable tbody tr").each(function(){
				if($(this).children("th").eq(0).text()==fundname) {
					$(this).addClass("highlighted");
				}
			});
		} else {
			$(this).parent().parent().removeClass("selected");
			checkHighlight(fundname);
		}
	});
	$("#tableFilters select, .newsnav select").change(function(){
		$(this).parents("form").submit();
	});
	$('a[href="#"]').click(function(){ return false; });
	$(".playMp3").colorbox({opacity:0.7,iframe:true,innerWidth:545,innerHeight:45,scrolling:false});
	$('a[href="#print"]').click(function(){
		_gaq.push(['_trackPageview', window.location.pathname + "#print"]);
		window.print();
		return false;
	});
	
	$("a[href^='/historical/']").click(function(){
		var w = 480;
		var h = 600;
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var targetWin = window.open ($(this).attr("href"), "retrieval", 'toolbar=1, status=0, menubar=1, scrollbars=1, resizable=1, width='+w+', height='+h+', top='+top+', left='+left);
		return false;
	});
	$("a[href^='#risk_disclosure'],a[href='#index_definitions'],a[href='#expense_ratio_disclosure'],a[href^='#docs_saved'],a[href^='#email_sent'],a[href^='#index_availability'],a[rel*='colorbox']").colorbox({
		opacity:0.5,
		speed:300,
		inline:true,
		width: 540,
		initialWidth:40,
		initialHeight:30,
		maxHeight:"75%",
		rel:'nofollow',
		onLoad:function(){ _gaq.push(['_trackPageview',window.location.pathname + $(this).attr("href")]); }
	});
	if($(".half-left").height()<$(".half-right").height()) {
		$(".half-left").css("height",$(".half-right").height());
	} else {
		$(".half-right").css("height",$(".half-left").height());
	}
	// $("a[href^='/historical/']").colorbox({
	// 	width: 450,
	// 	maxHeight: "95%"
	// });
});

