//Customize Slider
$(window).load(function() {
	$('#slider').nivoSlider({
		effect: 'sliceDown', //specify sets like: 'fold,fade,sliceDown'
		animSpeed: 200,	//slide transition speed
		pauseTime: 5000,
		directionNav: false,
		controlNav: false
	});
});

//Popup Function
$(function () { 
	$('#bubbleInfo').each(function() {
		//options
		var distance = 0;
		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: 150,
					left: 0
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, 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);
		});
	});
});
