//Customize Superfish
jQuery(function() {
	jQuery('ul.sf-menu').superfish({
		autoArrows: false,
		dropShadows: false,
		animation: {opacity:'show'},
		speed: 'fast'
	});
});

//Subnav Link RollOvers
$(document).ready(function() {
	$('td[id=sub_nav_hover]').hover(
		function() {
			$(this).css("background-color","#dadada");
		},
		function() {
			$(this).css("background-color","#ffffff");
		}
	);
});

//------------------INDEX PAGE STUFF------------------//

//Customize Slider
$(window).load(function() {
	$('#slider').nivoSlider({
		effect: 'sliceDown',
		animSpeed: 200,
		pauseTime: 4000,
		directionNav:false,
		controlNavThumbs:true,
    	controlNavThumbsFromRel:true
	});
});

//Info Popup
$(function () { 
	$('#bubbleInfo').each(function() {
		//options
		var distance = 10;
		var time = 250;
		var hideDelay = 500;
		var hideDelayTimer = null;
		
		//tracker
		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var popup = $('#popup', this).css('opacity', 0);
		
		//set the mouseover and mouseout on both elements
		$([trigger.get(0), popup.get(0)]).mouseover(function() {
			//stops the hide event if we move from the trigger to the popup
			if (hideDelayTimer)
				clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				return;
			}
			else {
				beingShown = true;
				
				//reset position of popup box
				popup.css({
					display: 'block',
					top: 0,
					left: 172
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 0.95
				}, time, 'swing', function() {
					//when animation done, set tracker variable
					beingShown = false;
					shown = true;
				});
			}
		}).mouseout(function(){
			//reset timer if popup shown again - avoids double animation
			if (hideDelayTimer) 
				clearTimeout(hideDelayTimer);
			
			//store the timer so it can be cleared in the mouseover
			hideDelayTimer = setTimeout(function() {
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function() {
					//when animation complete, set tracker variable
					shown = false;
					//hide popup completely
					popup.css('display','none');
				});
			}, hideDelay);
		});
	});
});
