$(document).ready(function(){
	// Popup Boxes
jQuery.popup_container_zindex = 10;
	jQuery('.popup').one('click', function() {
		var link = jQuery(this).attr("href");
		jQuery(this).after('<div class="popup_message" style="display:none;"></div>');
		// Look to see if the link is to a box in this page or not
		if (link.match(/^#/i)) {
			var message = jQuery(link).html();
			jQuery(this).next('.popup_message').html(message).append('<p class="close"><a href="#">Close</a></p>');
		} else {
			var message = jQuery(this).attr('rel');
			// See if a target box ID is specified in the rel attribute of the link, and only load that box if it is
			if (message) {
				jQuery(this).next('.popup_message').load(link+' #'+message, function() {
					jQuery(this).append('<p class="close"><a href="#">Close</a></p>');
				});
			} else {
				jQuery(this).next('.popup_message').load(link, function() {
					jQuery(this).append('<p class="close"><a href="#">Close</a></p>');
				});
			}
		}
		return false;
	}).click(function(e) {
		var offset = jQuery(this).parent().offset();
		var height = jQuery(this).next('.popup_message').outerHeight();
		var width = jQuery(this).next('.popup_message').outerWidth();
		var pageWidth = jQuery(document).width();
		var scrollHeight = e.pageY - jQuery(document).scrollTop();
jQuery.popup_container_zindex = jQuery.popup_container_zindex + 1;
		
		// make sure the popup will not go beyond the left or right edges of the page, and center it above the click location if not
		if ((e.pageX + (width/2) + 15) > pageWidth) {
			var left = pageWidth - width - offset.left - 15;
		} else if ((e.pageX - (width/2) - 15) < 0) {
			var left = 0;
		} else {
			var left = e.pageX - offset.left - (width/2);
		}
		
		// the popup should show up above the click location unless there isn't enough room in the window
		if (scrollHeight - height - 20 < 0) {
			var top = e.pageY - offset.top + 20;
		} else {
			var top = e.pageY - offset.top - height - 20;
		}
		
		jQuery(this).next('.popup_message').css({
			left: left,
			top: top
		}).toggle().parent().css({
			'z-index': jQuery.popup_container_zindex
		});
		return false;
	}).parent().addClass('popup_container');
	
	jQuery(".popup_message .close a").live('click', function() {
		jQuery(this).parent().parent().toggle();
		return false;
	});

	// END menu interaction (ADDITION FOPR THE POP-UP BOXES)

});

