$(function() {
			$('.date_has_event').each(function () {
				// options
				var distance = 20;
				var time = 250;
				var hideDelay = 50;
		 
				var hideDelayTimer = null;
		 
				// tracker
				var beingShown = false;
				var shown = false;
		 
				var trigger = $(this);
				var popup = $('.events ul', this).css('opacity', 0);
		 		
		 		$([trigger.get(0), popup.get(0)]).click(function () {
			 		var offsetWidth = this.offsetWidth;
			 		var offsetHeight = this.offsetHeight; 
			 		var offsetTop = this.offsetTop;
			 		var offsetLeft = this.offsetLeft;
					// stops the hide event if we move from the trigger to the popup element
					if (hideDelayTimer) clearTimeout(hideDelayTimer);
		 			//alert(this.offsetWidth + " " + this.offsetHeight);
					// dont trigger the animation again if were being shown, or already visible
					if (beingShown || shown) {
						
						// reset the timer if we get fired again - avoids double animations
						if (hideDelayTimer) clearTimeout(hideDelayTimer);
			 
						// store the timer so that it can be cleared in the mouseover if required
						hideDelayTimer = setTimeout(function () {
							hideDelayTimer = null;
							popup.animate({
								bottom: 0,
								left: 0,
								opacity: 0
							}, time, 'swing', function () {
								// once the animate is complete, set the tracker variables
								shown = false;
								// hide the popup entirely after the effect (opacity alone doesnt do the job)
								popup.css('display', 'none');
							});
						}, hideDelay);
					
					} else {
						beingShown = true;
		 
						// reset position of popup box
						popup.css({
							top: -46,
							left: 0,
							height:'100px',
							width:'150px',
							overflow: 'auto',
							display: 'block' // brings the popup back in to view
						})
		 
						// (were using chaining on the popup) now animate its opacity and position
						.animate({
							//bottom: '+=' + distance + 'px',
							//top: '=' + 0 + 'px',
							//top: offsetTop,
							left: offsetWidth-4,
							opacity: 1
						}, time, 'swing', function() {
							// once the animation is complete, set the tracker variables
							beingShown = false;
							shown = true;
						});
					}
				});
		 	});
		});

