jQuery(document).ready(function($){

		// <AREA> tags are invisible elements inside the DOM, 

		// therefore to attach correctly a bubble popup to them, 

		// we need to display and position <AREA> tags...


		$('area').css({ display: 'block'});

		$('area').offset({ top: $('#mapimage').offset().top, left: $('#mapimage').offset().left });



		//create bubble popups for each area tag and disable mouse events...



		$('area').CreateBubblePopup({ innerHtmlStyle: 	  	{ color:'#FFFFFF', 'text-align':'left' },
									  position: 'top',
									  align: 'center',		
									  width: '280px',
									  closingDelay: 500000,
									  tail: {align:'center',hidden:true},
									  themeName: 	  	 	'all-black',

									  themePath: 	  	 	'/jquerybubblepopup-theme',

									  manageMouseEvents:	false 

								   });



		// all popups of <AREA> tags are invisible

		$('area').data('visible', false);

		

		//set a timer

		var timer;

		

		// add a customized mouseover event for each <AREA> tag...

		$('area').mouseover(function(){

		

				clearTimeout(timer);

		

				if( !$(this).data('visible') ){

				

					// all popups must be invisible, but only this one is visible

					$('area').data('visible', false);

					$(this).data('visible', true);

					

					//hide all popups, update the innerHtml and show this popup

					$('area').HideAllBubblePopups();

					$('#1').SetBubblePopupInnerHtml('<p><img src=http://theamishvillage.net/wp-content/themes/amish/images/map-1.png alt=1 class=mapnumber><strong style=font-size:14px;>The Amish House</strong><p></p>  <p>Our local guides conduct group tours through this authentic Amish farmhouse, which dates back to 1840. These tours are a great way to gain insight into the Pennsylvania Amish culture, history and current way of life.</p>' );
					$('#2').SetBubblePopupInnerHtml('<p><img src=http://theamishvillage.net/wp-content/themes/amish/images/map-2.png alt=2 class=mapnumber><strong style=font-size:14px;>Windmill &amp; Water Wheel</strong><br><br> The windmill and water wheel in the Village operate a pump that provides water to animals in the barn area. Because the Amish live without electricity, this same system is used on most Amish farms today.</p>' );
					$('#3').SetBubblePopupInnerHtml('<p><img src=http://theamishvillage.net/wp-content/themes/amish/images/map-3.png alt="3" class="mapnumber"><strong style=font-size:14px;>Amish Barn and Farm Animals</strong><br><br> Like all Amish farms, ours is complete with a barn and a variety of animals. You can get right up close to goats, horses and the areas "local celebrity," Mrs. Pig and her piglets.</p>' );
					$('#4').SetBubblePopupInnerHtml('<p><img src="http://theamishvillage.net/wp-content/themes/amish/images/map-4.png" alt="4" class="mapnumber"><strong style=font-size:14px;>Amish Schoolhouse</strong><br><br> Built by Amish craftsmen, this authentically-furnished Amish one-room schoolhouse is a genuine example of how Amish children are educated today.</p>  ' );
					$('#5').SetBubblePopupInnerHtml('<p><img src="http://theamishvillage.net/wp-content/themes/amish/images/map-5.png" alt="5" class="mapnumber"><strong style=font-size:14px;>Smokehouse</strong><br><br> Taste the flavor of the Pennsylvania Dutch Country inside a working smokehouse and store. Amish-made jellies and jams are available as well as other local Lancaster County favorites.</p>' );
					$('#6').SetBubblePopupInnerHtml('<p><img src="http://theamishvillage.net/wp-content/themes/amish/images/map-6.png" alt="6" class="mapnumber"><strong style=font-size:14px;>Blacksmith Shop</strong><br><br> An important part of Amish life, this blacksmith shop is furnished with all the tools used by Amish craftsmen for almost 300 years.</p>' );
					$('#7').SetBubblePopupInnerHtml('<p><img src="http://theamishvillage.net/wp-content/themes/amish/images/map-7.png" alt="7" class="mapnumber"><strong style=font-size:14px;>Amish Village Store</strong><br><br> Find the perfect souvenir to take home to remind you of your visit to Pa Amish Country. Authentic Pennsylvania Amish crafts and handmade goods are featured.</p>' );
					$('#8').SetBubblePopupInnerHtml('<p><img src="http://theamishvillage.net/wp-content/themes/amish/images/map-8.png" alt="8" class="mapnumber"><strong style=font-size:14px;>Outdoor Picnic Grounds</strong><br><br> Relax and "set a while" at our beautiful picnic grounds. The perfect place for an afternoon lunch or snack, you will enjoy the opportunity to stretch out your legs and enjoy the fresh country air and beautiful Lancaster County scenery.</p>' );					

					//$(this).SetBubblePopupInnerHtml( $(this).attr('alt') );

					$(this).ShowBubblePopup();

					

					//get <IMG> position and <AREA> coordinates...

					var img_position = $('#mapimage').offset();

					var img_top = parseInt(img_position.top);

					var img_left = parseInt(img_position.left);

					var area_x = parseInt($(this).attr('coords').split(',')[0]);

					var area_y = parseInt($(this).attr('coords').split(',')[1]);

					var bubble_width  = parseInt($('#'+$(this).GetBubblePopupID()).outerWidth(false));

					var bubble_height = parseInt($('#'+$(this).GetBubblePopupID()).outerHeight(false));

				

					//move the bubble popup to the <AREA> coordinates...

					$('#'+$(this).GetBubblePopupID()).css({ top: (area_y+img_top-bubble_height+110)+'px', left: (area_x+img_left-Math.abs(bubble_width/2)+50)+'px' });

				

				};

		});



		//if the mouse leaves the <AREA>, wait 3 seconds then hide all bubble poups...

		$('area').mouseleave(function(){



			if( $(this).data('visible') ){

				var seconds_to_wait = 500000;

				function doCountdown(){

					timer = setTimeout(function(){

						seconds_to_wait--;

						if(seconds_to_wait > 0){

							doCountdown();

						}else{

							clearTimeout(timer);

							$('area').HideAllBubblePopups();

							$('area').data('visible', false);

						};

					},0);

				};

				doCountdown();

			};

			

		});



});

