var curHashVal=0;

$(document).ready(function() {
	//Look for arial narrow and use it if possible - if not, bump down the font size
	var d=new Detector();
	if(!d.test("Arial Narrow")) {
		$("body").css({"fontSize": ".75em", "fontFamily": "Arial, Helvetica, sans-serif"});
	}
	
	//FAQ Functions
	$(".question")
		.css("cursor", "pointer")
		.click(function() {
			$(".question").not($(this)).removeClass("active");
			$answer=$(this).next(".answer");
			$(".answer").not($answer).slideUp();
			$(this).toggleClass("active");
			$answer.slideToggle();
			clickedID=$answer.attr("id").replace("answer_","");
			curHashVal=clickedID;
			window.location.hash=clickedID;
		});
	
	$(".answer").hide();
	
	$("#faqChooser li")
		.css("cursor", "pointer")
		.click(function() {
			$("#faqChooser li").removeClass("active");
			$(this).addClass("active");
			
			clickedID=$(this).attr("id");
			clickedClass="." + clickedID;
			
			$(".answer").hide();
			$(".question").removeClass("active");
			
			if(clickedID=="all") {
				$(".question").show();
			} else {
				$(".question").hide();
				$(clickedClass).show();
			}
		});
	if(window.location.hash != "") {
		selectedID=window.location.hash.replace("#", "");
		curHashVal=selectedID;
		$("#answer_"+selectedID).show();
		$question=$("#answer_"+selectedID).prev(".question");
		$question.addClass("active");
		$("#innerContent").scrollTo($question);
	}
	setInterval(function(){
		if(curHashVal!=window.location.hash.replace("#","")){ //changed
			selectedID=window.location.hash.replace("#", "");
			$(".answer").slideUp();
			$(".question").removeClass("active");
			$("#answer_"+selectedID).slideDown(function() {
				$("#innerContent").scrollTo($(this).prev(".question"), 400);
			});
			$question=$("#answer_"+selectedID).prev(".question");
			if($question.is(":not(:visible)")) {
				$("#faqChooser li#all").click();
			}
			$question.addClass("active");
			curHashVal = selectedID;
		}
	}, 200);
	
	//For the multiple #id.class IE6 bug
	$(".wide").css({width: 583, padding: "0 30px"});
		
	//Extra GA link tracking
	$("a[href^=http://]").click(function() {
		if(!$(this).attr("href").match(/potableaqua.com/)) {
			extUrl=$(this).attr("href").replace("http://", "");
			if(typeof(pageTracker)!="undefined") {
				pageTracker._trackPageview("/external-links/"+extUrl);
			}
		}
	});
	
	$("a[href$=pdf]").click(function() {
		if(typeof(pageTracker)!="undefined") {
			pageTracker._trackPageview($(this).attr("href"));
		}
	});
});

if(typeof(console)=="undefined") {
	console={
		log: function(data) {
			alert(data);
		}
	};
}
