function stateGrab(whichState){
	$("#state").load('state-grabber.php?s='+whichState);
}

$(function () {
	
	// ===== ARCHERY BUTTONS ==============================
	$('.sub-nav').each(function () {
		var time = 200;
		var hideDelay = 200;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.button-over', this).css('opacity', 0);
		
		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;
				
				info.css({
					top: 0,
					left: -5,
					width: '160px',
					'text-align': 'center',
					display: 'block',
					'z-index': 5000
				}).animate({
					height: '215px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}
			
			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					height: 0,
					opacity: 0
				}, time, 'swing', function () {
					beingShown = false;
					shown = false;
					info.css('display', 'none');
				});
			
			}, hideDelay);
			
			return false;
		});
	});
	
	// ===== FOOTER BUTTONS ===============================
	$('#news_button').click(function () {
		$('#news_items').slideToggle();
	});
	
	$('#resources_button').click(function () {
		$('#resources_items').slideToggle();
	});
	
	$('#customer_service_button').click(function () {
		$('#customer_service_items').slideToggle();
	});
	
	// ===== ROLLOVER IMAGES ==============================
	$('.rollover').hover(
		function(){
			if($(this).attr("src").indexOf("-over.jpg") == -1) {
				var newSrc = $(this).attr("src").replace(".jpg","-over.jpg");
				$(this).attr("src",newSrc);
			}
			if($(this).attr("src").indexOf("-over.gif") == -1) {
				var newGif = $(this).attr("src").replace(".gif","-over.gif");
				$(this).attr("src",newGif);
			}
		},
		function(){
			if($(this).attr("src").indexOf("-over.jpg") != -1) {
				var oldSrc = $(this).attr("src").replace("-over.jpg",".jpg");
				$(this).attr("src",oldSrc);
			}
			if($(this).attr("src").indexOf("-over.gif") != -1) {
				var oldGif = $(this).attr("src").replace("-over.gif",".gif");
				$(this).attr("src",oldGif);
			}
		}
	);
	
	$('.rollover').mousedown(
		function(){
			if($(this).attr("src").indexOf("-over.gif") != -1){
				var newDown = $(this).attr("src").replace("-over.gif","-down.gif");
				$(this).attr("src",newDown);
			}
		}
	);
	$('.rollover').mouseup(
		function(){
			if($(this).attr("src").indexOf("-down.gif") != -1){
				var oldUp = $(this).attr("src").replace("-down.gif",".gif");
				$(this).attr('src',oldUp);
			}
		}
	);
	
	$('.subsignature').hover(
		function(){
			if($(this).attr("src").indexOf("-over.gif") == -1) {
				var newGif = $(this).attr("src").replace(".gif","-over.gif");
				$(this).attr("src",newGif);
			}
		},
		function(){
			if($(this).attr("src").indexOf("-over.gif") != -1) {
				var oldGif = $(this).attr("src").replace("-over.gif",".gif");
				$(this).attr("src",oldGif);
			}
		}
	);
	
	$(window).bind('load', function() {
		$('.rollover').each(function(key, elm) {
			$(this).attr('src', $(this).attr('src').replace('.jpg', '-over.jpg'));
			$(this).attr('src', $(this).attr('src').replace('-over.jpg', '.jpg'));
			$(this).attr('src', $(this).attr('src').replace('.gif', '-over.gif'));
			$(this).attr('src', $(this).attr('src').replace('-over.gif', '.gif'));
		});
	});
	
});