(function($) {
	$("body").addClass("jsEnabled");
	
	$('a').each(function(){
		var href = $(this).attr('href');
		if(href.indexOf('.pdf') != -1){
			$(this).attr("target", "_blank");
		}
	});
	
	//Homepage Slideshow setup 
	$("#animation").cycle({
		fx: 'fade',
		timeout: 2500
	});
	
	//Tool Tip
	$("#locationsList li a").each(function() {
		
		var $this = $(this);
		var toolTip = $this.next(".tooltip");
		
		$this.hoverIntent(
			function() {
				$(".tooltip").hide();
				
				var offset = $this.offset();
				var documentSize = $(window).width();
				var toolTipWidth = toolTip.width() + 20;
				var toolTipY = offset.top - 10; 
				var toolTipX = offset.left + 135; 
				
				toolTip.appendTo("body");
				
				if ( toolTipX + toolTipWidth >= documentSize ) {
					
					toolTip
						.css({
							top: toolTipY, 
							left: toolTipX - (toolTipWidth + 170)
						})
						.show()
						.addClass("reversed");
				
				} else {
				
					toolTip
						.css({
							top:  toolTipY,
							left: toolTipX
						})
						.show();
				}
			}, function() {
				toolTip.hide().insertAfter($this);
				toolTip.removeClass("reversed");
			}
		);
	});	
	
	//FAQ Slide Down
	$("#faqSection p").hide();
	
	$("#faqSection h2").toggle(
		function(){
			$(this).next().slideDown();
		}, function(){
			$(this).next().hide();
		}
	);
	
	// Make legends into H2s for easier styling, while maintaining semantic markup.
	$("legend").each(function(){
		var $this = $(this); 
		var legendText = $this.text();
		$this.parent("fieldset")
			.before("<h2>" + legendText + "</h2>")
			.end()
			.remove();
	});
	
	//Add zebra-striping to tables
	if ( !$("table").hasClass("noStripe") ) {
		$("table tr:odd").addClass("odd");
	}
	
	//Automatically selects focused field text and adds class for styling
	$('input[type="text"]').focus(function(){
		$(this).select().addClass("focused");
	});
	$('input[type="text"]').blur(function(){
		$(this).removeClass("focused");
	});
	
})(jQuery); 
