//****************************************************************************
// CountryWindow code from http://jqueryfordesigners.com/demo/coda-bubble.html
//
// Assumes: div class of regionpopup: the div containing a single image and popup info
//          img class of trigger: the image that when moused over, invokes the popup
//          popup: the table containing the popup info.
//          
//****************************************************************************
function InitCountryWindow()
{
$('.regionpopup').each(function () {
			var distance = 0;
			var time = 0;					// time needed to SHOW and HIDE the window
            var hideDelay = 250;			// time before window disappears when mouse moves away

            var hideDelayTimer = null;

            var beingShown = false;		// in the process of animation?
            var shown = false;			// is currently being shown?
			
			// fetch the region this popup is for
			var regionindex = $(this).attr("regionindex");
			// fetch the area map trigger for this region
			var trigger = $(".countrytrigger[regionindex='" + regionindex + "']");
            var info = $(this);					

			// hide the main div
			$(this).addClass("hidecountry");
			
			// with BOTH the countrytrigger and popup objects, set the MOUSE OVER function
            $([trigger.get(0), info.get(0)]).mouseover(function () {
				
                if (hideDelayTimer) clearTimeout(hideDelayTimer);  // if timer active, kill it.
                
				// if we're currently being shown, just let that process continue
				if (beingShown || shown) {
                    return; // don't re-trigger the animation again
                } else {
                    // init: reset position of info box
                    beingShown = true;

					// set the position of the popup box
                    info.css({
                        //top: 50,
                        //left: 53,
                        display: 'block'
						// now animate the popup to a position 'distance' away from initial position
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1  
						// upon completion of animation, set vars.
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;  // return FALSE from the mouse over
				// with BOTH the trigger and popup objects, set the MOUSE OUT function
            }).mouseout(function () {
				
                if (hideDelayTimer) clearTimeout(hideDelayTimer); // if timer active, kill it.
               	// wait 'hideDelay' then invoke the following function:
				hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
					// now animate the popup to a position 'distance' away from initial position
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
						// upon completion of animation, set vars.
                    }, time, 'swing', function () {
                        shown = false;
						// turn off the display of the popup
                        info.css('display', 'none');
                    });

                }, hideDelay);

				// return FALSE from the mouse out
                return false;
            });
			
			// set the close window link to close the div via the mouseout function
			$("#closeregion",this).bind("click", function(){
				 //info.trigger("mouseout");
				 shown = false;
				 beingShown=false;
				 info.css('display', 'none');
				 info.addClass("hidecountry");
			});
        });
}