jQuery(function() {
	jQuery('.bubbleInfo').each(function() {
		// options
		var distance = -30;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = jQuery('.trigger', this);
		var popup = jQuery('.popup', this).css('opacity', 0);
		var $bubble = jQuery(this);

		// set the mouseover and mouseout on both element
		jQuery([trigger.get(0), popup.get(0)]).mouseover(function() {

			var position = { "top": 0, "left": 0};
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				//top: -100,
				//left: -33,
				popup.css({
					top: position.top,
					left: position.left,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
        .animate({
        	top: '-=' + distance + 'px',
        	opacity: 1
        }, time, 'swing', function() {
        	// once the animation is complete, set the tracker variables
        	beingShown = false;
        	shown = true;
        });
			}
		}).mouseout(function() {
			// 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({
					top: '-=' + distance + 'px',
					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 doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});


	function calculatePosition($refEle, $rollerEle, dialogWidth) {
		var buttonOffset = $refEle.offset();
		var buttonScrolltop = -(jQuery(document).scrollTop());
		var finalLeft = buttonOffset.left;
		var finalTop = buttonOffset.top + buttonScrolltop;
		return { "left": finalLeft, "top": finalTop };
	}

});

 function BSB_Controls_OpenEmailPopUp() {
 	if (document.location.href != "") {
 		window.open(BSB_Controls_TargetURL + '&ref=' + BSB_Controls_CurrentURL, null, 'status=yes, toolbar=no,width=1000,height=10000, scrollbars=yes,menubar=yes, resizable=yes,left=0,top=0');
 		return false;
 	}
}

//Script for display program and division description in modal popup as iframe - Start
function viewPopupWindow(lnkHref, title, width, height, currentobject, doClose) {
    bsbModal.show(lnkHref, false, height, width, false, '', title, currentobject, doClose);
};

(function (window, jQuery) {
    bsbModal = { //global scope
        load: function () {
            //This method prevents the popup from flashing before closing, also redirects the parent window.
            //parent and parent.parent needs to be assign to a varaible for Opera compatibility issues.        
            try {
                if (parent.location.href !== undefined) {

                    var windowTop = parent;
                    var parentTop = windowTop.parent;

                    if (typeof (parentTop.$find) != "undefined") {
                        if (location.href.indexOf('popUp') == -1 || windowTop.location.href.indexOf("popUp") > -1) {
                            var popup = windowTop.jQuery("#iPopUp");
                            var refresh = popup.dialog("option", "refresh");
                            var closingUrl = popup.dialog("option", "closingUrl");
                            if (closingUrl == "")
                            { closingUrl = location.href; }
                            if (popup.dialog('isOpen') === true) {
                                popup.dialog("option", {
                                    close: function (event, ui) { bsbModal.closePopUp(refresh, closingUrl); }
                                }).dialog('close');
                            }
                        }
                        else { windowTop.jQuery("#iPopUp").dialog({ title: document.title }); }
                    }
                }
            }
            catch (err) { return false; }
        },
        show: function (url, showReturn, height, width, refresh, closingUrl, titleHead, currentobject, doClose) {
            var $modal = jQuery(".displayDescription");
			if ($modal[0].isLoading) { $modal.parent().find('.dnnLoading').remove(); }
            var windowTop = parent; //needs to be assign to a varaible for Opera compatibility issues.
            $modal.dialog({
                modal: false,
				draggable: false,
                position: { my: "left top", at: "left bottom", of: currentobject, collision: "none" },
                width: width,
                height: height,
                resizable: true,
                closeOnEscape: true,
                zIndex: 100000,
                refresh: refresh,
                closingUrl: closingUrl,
                title: titleHead,
				dialogClass:"dnnFormPopup",
                close: function (event, ui) { bsbModal.closePopUp(refresh, closingUrl); }
            });
            jQuery('.ui-dialog-titlebar > .dnnToggleMax').remove();

            var showLoading = function () {
                $modal.hide();
                var loading = jQuery("<div class=\"dnnLoading\"></div>");
                loading.css({ width: $modal.width(), height: $modal.height() });
                $modal.before(loading);
                $modal[0].isLoading = true;
                if (doClose == 1) {
                    $modal.dialog("close");
                }
            };
            var hideLoading = function () {
                $modal.prev(".dnnLoading").remove();
                $modal[0].isLoading = false;
                $modal.show();
            };
            showLoading();
            $modal[0].src = url;
            $modal.bind("load", function () {
                hideLoading();
            });
            if (showReturn.toString() == "true") {
                return false;
            }
        },
        closePopUp: function (refresh, url) {
            var windowTop = parent; //needs to be assign to a varaible for Opera compatibility issues.
            if (typeof refresh === "undefined") {
                refresh = true;
            }
            if ((typeof url === "undefined") || (url == "")) {
                url = windowTop.location;
            }
            if (refresh.toString() == "true") {
                windowTop.location.href = url;
                jQuery(this).hide();
            }
            else {
                jQuery(this).remove();
                if ($(document).height() > $(window).height()) { jQuery(document).find('html').css('overflow-y', 'scroll'); }
            }
        }
    };
    bsbModal.load();
} (window, jQuery));
//Script for display program and division description in modal popup as iframe - End