$.fn.reverse = Array.prototype.reverse;

var $mainContent, $mainContentText;
var $overlay = $('<div class="overlay"></div>');
var $overlayBox = $('<div class="overlay_box"></div>');
var $overlayContent = $('<div class="overlay_content"></div>');
var $closeOverlay = $('<div class="close_overlay"></div>');
var $overlayLeft = $('<div class="content_scroller prev_content"></div>');
var $overlayRight = $('<div class="content_scroller next_content"></div>');

function flashDone() {
	$("#intro_flash").remove();
	readyBoxInteractions();
}

function flashReady() {
	$(".box_wrapper .box").unbind("mouseenter mouseleave click");
	//set an animation timeout for the text boxes
	window.setTimeout(function() {
		$(".box .internal").fadeIn(1000).fadeOut(4000);
		window.setTimeout(function() {
			readyBoxInteractions();
		}, 5000);
	}, 4400);
}

function slideBetween($fromDiv, $toDiv, duration) {
	if (duration===null || duration===undefined) {
		duration = 1000;
	}
	
	var $link = $toDiv.find("a"), $gallery = $toDiv.find(".virtual_tour_image");
	var $image = $gallery.find("img"), $title = $toDiv.find(".virtual_tour_title");
	var $link2 = $fromDiv.find("a"), $gallery2 = $fromDiv.find(".virtual_tour_image");
	var $image2 = $gallery2.find("img"), $title2 = $fromDiv.find(".virtual_tour_title");
	
	if ($title.length<1) {
		$title = $toDiv.find(".virtual_tour_link");
	}
	
	if ($title2.length<1) {
		$title2 = $fromDiv.find(".virtual_tour_link");
	}
	
	var props = {
		"margin-left": $toDiv.css("margin-left"),
		"margin-right": $toDiv.css("margin-right"),
		"margin-top": $toDiv.css("margin-top")
	};
	
	var aProps = {
		"border-top-color": $link.css("border-top-color"),
		"border-left-color": $link.css("border-left-color"),
		"border-bottom-color": $link.css("border-bottom-color"),
		"border-right-color": $link.css("border-right-color"),
		"width": $link.width()
	};
	
	var galleryProps = {
		height: $gallery.height()
	};
	
	var imageProps = {
		width: $image.width()
	};
	
	var titleProps = {
		width: $title.width(),
		"font-size": $title.css("font-size")
	};
	
	var props2 = {
		"margin-left": $fromDiv.css("margin-left"),
		"margin-right": $fromDiv.css("margin-right"),
		"margin-top": $fromDiv.css("margin-top")
	};
	
	var aProps2 = {
		"border-top-color": $link2.css("border-top-color"),
		"border-left-color": $link2.css("border-left-color"),
		"border-bottom-color": $link2.css("border-bottom-color"),
		"border-right-color": $link2.css("border-right-color"),
		"width": $link2.width()
	};
	
	var galleryProps2 = {
		height: $gallery2.height()
	};
	
	var imageProps2 = {
		width: $image2.width()
	};
	
	var titleProps2 = {
		width: $title2.width(),
		"font-size": $title2.css("font-size")
	};
	
	var zIndex = $fromDiv.css("zIndex");
	var zIndex2 = $toDiv.css("zIndex");
	
	$fromDiv.animate(props, duration);
	$link2.animate(aProps, duration);
	$gallery2.animate(galleryProps, duration);
	$image2.animate(imageProps, duration);
	
	if ($title2.text()!="") {
		$title2.animate(titleProps, duration);
		
		if ($fromDiv.find(".virtual_tour_description").text()!="") {
			$fromDiv.find(".virtual_tour_description").animate(titleProps, duration);
		}
		
		if ($fromDiv.find(".virtual_tour_link").text()!="") {
			$fromDiv.find(".virtual_tour_link").animate(titleProps, duration);
		}
	}
	
	$toDiv.animate(props2, duration);
	$link.animate(aProps2, duration);
	$gallery.animate(galleryProps2, duration);
	$image.animate(imageProps2, duration);
	
	if ($title.text()!="") {
		$title.animate(titleProps2, duration);
		
		if ($toDiv.find(".virtual_tour_description").text()!="") {
			$toDiv.find(".virtual_tour_description").animate(titleProps2, duration);
		}
		
		if ($toDiv.find(".virtual_tour_link").text()!="") {
			$toDiv.find(".virtual_tour_link").animate(titleProps2, duration);
		}
	}
	
	window.setTimeout(function() {
		$fromDiv.css({zIndex: zIndex2});
		$toDiv.css({zIndex: zIndex});
	}, duration/2);
}

function readyBoxInteractions() {
	$(".box_wrapper .box").unbind("mouseenter mouseleave click").click(function() {
		var $box = $(this);
		
		$box.toggleClass("selected");
		
		if (!$(this).hasClass("selected")) {
			$mainContent.fadeOut("slow");
			
			return false;
		}
		
		$(".box_wrapper .box.selected").not($box).each(function() {
			//var height = $(this).height();
			$(this).removeClass("selected").find(".internal").stop(true, true).fadeOut(500);/*.animate({
				top: height
			}, 500);*/
		});
		
		if ($mainContent.is(":visible")) {
			$mainContentText.fadeOut("slow", function() {
				$mainContentText.load($box.find(".internal").attr("href") + " .content_text", function() {
					$mainContent.removeClass("loading");
					$mainContentText.fadeIn("slow");
					
					//do custom scrollbars for the new content
					handleVirtualTours($mainContent.find(".content_text"));
					replaceCustomScrollbars($mainContent.find(".content_text"));
				});
			});
		} else {
			$mainContentText.hide();
			$mainContent.addClass("loading").fadeIn("slow");
			
			$mainContentText.load($box.find(".internal").attr("href") + " .content_text", function() {
				$mainContent.removeClass("loading");
				$mainContentText.fadeIn("slow");
				
				//do custom scrollbars for the new content
				handleVirtualTours($mainContent.find(".content_text"));
				replaceCustomScrollbars($mainContent.find(".content_text"));
			});
		}
		
		return false;
	}).hover(function() {
		if (!$(this).hasClass("selected")) {
			var $box = $(this);
			
			$(this).find(".internal").fadeIn(500);/*.animate({
				top: 0
			}, 500);*/
		}
	}, function() {
		var height = $(this).height();
		
		if (!$(this).hasClass("selected")) {
			$(this).find(".internal").fadeOut(500);/*.animate({
				top: height
			}, 500);*/
		}
	});
}

function replaceCustomScrollbars($div) {
	$div.each(function() {
		$(this).css("overflow", "hidden");
		
		var $scroll = $(this);
		var $scrollBox = $('<div class="scroll_box"></div>');
		var $scrollWrap = $('<div class="scroll_wrap"></div>');
		var $scrollArea = $('<div class="scroll_area"></div>');
		var $scrollBar = $('<div class="scroll_bar"></div>');
		
		$scrollBox.attr("tabindex", "0");
		
		$scrollArea.append($scrollBar);
		$(this).wrapInner($scrollWrap);
		$(this).wrapInner($scrollBox);
		$(this).append($scrollArea);
		
		$scrollBox = $(this).find(".scroll_box");
		$scrollWrap = $(this).find(".scroll_wrap");
		
		calcHeight();
		function calcHeight() {
			$scrollBar.height($scroll.height()/$scrollWrap.height() * $scrollArea.height());
			
			if ($scrollWrap.height()+20<$scrollBox.height()) {
				$scroll.addClass('noscroll');
			} else {
				$scroll.removeClass('noscroll');
			}
		}
		
		calcPosition();
		function calcPosition() {
			var availableSpace = ($scrollWrap.outerHeight() - $scrollBox.innerHeight() + 10);
			var availableScroll = ($scrollArea.height() - $scrollBar.height());
			
			$scrollBar.css("top", ($scrollBox.scrollTop() / availableSpace) * availableScroll);
		}
		
		function scrollToPos() {
			var availableSpace = ($scrollWrap.outerHeight() - $scrollBox.innerHeight() + 10);
			var availableScroll = ($scrollArea.height() - $scrollBar.height());
			
			$scrollBox.scrollTop(($scrollBar.position().top / availableScroll) * availableSpace);
		}
		
		function moveTo(y) {
			var availableScroll = ($scrollArea.height()-$scrollBar.height());
			var newY = Math.min(Math.max(0, y), availableScroll);
			
			$scrollBar.css("top", newY);
			scrollToPos();
		}
		
		$div.data({calcPosition: calcPosition, scrollToPos: scrollToPos, moveTo: moveTo, calcHeight: calcHeight});
		
		$scrollBox.mousewheel(function(e, delta) {
			$scrollBox.scrollTop($scrollBox.scrollTop()+(-delta*20));
			calcHeight();
			calcPosition();
			
			return false;
		});
		
		$(window).resize(function() {
			calcHeight();
			calcPosition();
		});
		
		$scrollArea.click(function(e) {
			//jump the scrollbar to the specified area, centering it
			moveTo(e.pageY - $(this).offset().top - ($scrollBar.height()/2));
		});
		
		$scrollBar.mousedown(function(e) {
			$scrollBar.data("drag", {
				origX: e.pageX,
				origY: e.pageY
			});
			
			return false;
		});
		
		$(document).mousemove(function(e) {
			if ($scrollBar.data("drag")) {
				var drag = $scrollBar.data("drag");
				
				moveTo($scrollBar.position().top + e.pageY - drag.origY);
				
				$scrollBar.data("drag", {
					origX: e.pageX,
					origY: e.pageY
				});
			}
		}).mouseup(function() {
			$scrollBar.removeData("drag");
		});
	});
}

function handleVirtualTours($searchDiv) {
	$searchDiv.find(".virtual_tours").each(function() {
		//ensure there are at least four images to play with
		var $gallery = $(this);
		var $galleryWrap = $gallery.find(".virtual_tour_images, .gallery_images");
		var $galleryImages = $gallery.find(".virtual_tour, .gallery_image");
		
		if ($galleryImages.length<3) {
			return false;
		}
		
		$gallery.removeClass("virtual_tours").addClass("fancy_virtual_tours");
		$($galleryImages.get(1)).addClass("selected_block");
		
		$gallery.swipe({
			swipe: function(e, dir) {
				//based on the direction of the swipe
				switch (dir) {
					case "left":
						scrollRight();
						break;
					case "right":
						scrollLeft();
						break;
				}
			},
			threshold:200
		});
		
		//animate left and animate the next selected element in
		var $rightScroller = $('<div class="virtual_tours_scroller_right virtual_tours_scroller"></div>');
		var $leftScroller = $('<div class="virtual_tours_scroller_left virtual_tours_scroller"></div>');
		
		$gallery.append($rightScroller, $leftScroller);
		
		var animating = false;
		
		$rightScroller.click(scrollRight);
		$leftScroller.click(scrollLeft);
		
		$gallery.data("scrollRight", scrollRight);
		$gallery.data("scrollLeft", scrollLeft);
		
		function scrollRight() {
			if (animating) {
				return false;
			}
			
			animating = true;
			
			var $selectedBlock = $galleryImages.filter(".selected_block");
			var $nextBlock = $selectedBlock.next();
			
			if ($nextBlock.length>0) {
				slideBetween($nextBlock, $selectedBlock, 500);
				$galleryWrap.animate({left: $galleryWrap.position().left - 220 }, 500, function() {
					$nextBlock.addClass("selected_block");
					$selectedBlock.removeClass("selected_block");
					
					animating = false;
				});
			} else {
				animating = false;
			}
			
			return false;
		}
		
		function scrollLeft() {
			if (animating) {
				return false;
			}
			
			animating = true;
			
			var $selectedBlock = $galleryImages.filter(".selected_block");
			var $prevBlock = $selectedBlock.prev();
			
			if ($prevBlock.length>0) {
				slideBetween($prevBlock, $selectedBlock, 500);
				$galleryWrap.animate({left: $galleryWrap.position().left + 220}, 500, function() {
					$prevBlock.addClass("selected_block");
					$selectedBlock.removeClass("selected_block");
					
					animating = false;
				});
			} else {
				animating = false;
			}	
			
			return false;
		}
	});
	
	//handle gallery images in the same fashion
	$searchDiv.find(".virtual_tour a, .gallery_image a").click(function() {
		//for awards, ignore the click
		var exceptions = {"award_virtual_tour":null, "latest_news_virtual_tour":null, "chartwell_news_virtual_tour":null};
		var $tour = $(this).parents(".virtual_tours, .fancy_virtual_tours").first();
		
		if (!$tour.attr("id") || !exceptions.hasOwnProperty($tour.attr("id"))) {
			loadOverlayContent($(this));
			return false;
		}
	});
	
	/*if ($.browser.msie) {
		$searchDiv.find(".virtual_tour a .virtual_tour_image, .gallery_image a .virtual_tour_image").click(function(e) {
			e.stopPropagation();
			
			$(this).parents("a").first().trigger("click");
			return false;
		});
	}*/
}

function loadOverlayContent($link) {
	var href = $link.attr("href");
	
	window.location.hash = href.substring(href.indexOf("#"));
	
	//show the overlay
	$overlayContent.html("").addClass("loading");
	$overlayBox.css({zIndex: -1, width: "auto", height: "auto", marginLeft: "0", marginTop: "0"});
	$overlay.fadeIn("slow", function() {
		$closeOverlay.hide();
		$overlayLeft.hide();
		$overlayRight.hide();
		
		var origWidth = $overlayBox.width();
		var origHeight = $overlayBox.height();
		
		$overlayLeft.unbind("click").bind("click", function() {
			$closeOverlay.add($overlayLeft, $overlayRight).fadeOut("fast");
			$overlayContent.fadeOut("fast", function() {
				$overlayBox.animate({width: origWidth, height: origHeight, marginLeft: -origWidth/2, marginTop: -origHeight/2}, 1000, function() {
					loadOverlayContent($link.parent().prev().find("a"));
					
					var $parentTour = $link.parents(".fancy_virtual_tours");
					
					if ($parentTour.length>0 && typeof $parentTour.data("scrollLeft") == "function") {
						$parentTour.data("scrollLeft")();
					}
				});
			});
		});
		
		$overlayRight.unbind("click").bind("click", function() {
			$closeOverlay.add($overlayLeft, $overlayRight).fadeOut("fast");
			$overlayContent.fadeOut("fast", function() {
				$overlayBox.animate({width: origWidth, height: origHeight, marginLeft: -origWidth/2, marginTop: -origHeight/2}, 1000, function() {
					loadOverlayContent($link.parent().next().find("a"));
					
					var $parentTour = $link.parents(".fancy_virtual_tours");
					
					if ($parentTour.length>0 && typeof $parentTour.data("scrollRight") == "function") {
						$parentTour.data("scrollRight")();
					}
				});
			});
		});
		
		//if the href is an image, then just display it inline
		if ($link.attr("href").match(/.(png|jpg|gif)$/i)) {
			$overlayContent.removeClass("loading").html('<img src="' + $link.attr("href") + '" alt="" />');
			
			$overlayContent.find("img").load(function() {
				var newWidth = $overlayContent.outerWidth();
				var newHeight = $overlayContent.outerHeight();
				
				$overlayBox.css({zIndex: "auto", width: origWidth, height: origHeight, marginLeft: -origWidth/2, marginTop: -origHeight/2})
				.animate({width: newWidth, height: newHeight, marginLeft: -newWidth/2, marginTop: -newHeight/2}, 1000, function() {
					$overlayContent.show();
					$closeOverlay.fadeIn("slow");
					
					//decide if we need to a left or right button
					if ($link.parent().next().length>0) {
						$overlayRight.fadeIn("slow");
					}
					
					if ($link.parent().prev().length>0) {
						$overlayLeft.fadeIn("slow");
					}
				});
			});
		} else {
			$.get($link.attr("href"), function(data) {
				$overlayContent.removeClass("loading").html(data);
				
				var newWidth = $overlayContent.outerWidth();
				var newHeight = $overlayContent.outerHeight();
				
				$overlayBox.css({zIndex: "auto", width: origWidth, height: origHeight, marginLeft: -origWidth/2, marginTop: -origHeight/2})
				.animate({width: newWidth, height: newHeight, marginLeft: -newWidth/2, marginTop: -newHeight/2}, 1000, function() {
					$overlayContent.show();
					$closeOverlay.fadeIn("slow");
					
					//decide if we need to a left or right button
					if ($link.parent().next().length>0) {
						$overlayRight.fadeIn("slow");
					}
					
					if ($link.parent().prev().length>0) {
						$overlayLeft.fadeIn("slow");
					}
				});
			}, "text");
		}
	});
}

$(document).ready(function() {
	if ($.browser.msie && $.browser.version<8) {
		$("a, input").live("focus", function() {
			$(this).addClass("focus");
		}).live("blur", function() {
			$(this).removeClass("focus");
		});
	}

	$("#chartwell_care_offers_images").cycle();
	
	readyBoxInteractions();
	
	if ($(".page_welcome").length>0) {
		if ($.browser.msie && $.browser.version<9) {
			window.setTimeout(function() {
				animLights();
			}, 2000);
		} else {
		
		//extract the background image for the body
		var bgFile = $("body").css("background-image").match(/url\(\"?([^\"]+)\"?\)/);
		
		if (bgFile && bgFile.constructor == [].constructor && bgFile.length>1) {
			var bgFilename = bgFile[1];
			var cacheImg = new Image();
			cacheImg.src = bgFilename;
			
			//wait until the image has fully loaded
			cacheImg.onload = function() {
				//then animate our boxes
				
				//make sure the flash loads afer the background
				//$("#intro_flash").show();
				var cacheImgs = ["/images/light_bars.gif", "/images/light1.png", "/images/chartwell-overs.png"];
				var loaded = [false, false, false];
				
				for (var i=0; i<cacheImgs.length; i++) {
					(function(i) {
						var img = new Image();
						img.src = cacheImgs[i];
						
						img.onload = function() {
							loaded[i] = true;
							checkLoaded();
						};
					})(i);
				}
				
				function checkLoaded() {
					for (var j=0; j<loaded.length; j++) {
						if (!loaded[j]) {
							return false;
						}
					}
					
					animLights();
				}
			};
			}
		}
		
		window.setInterval(function() {
			//get the current animating title and fade it out
			var $currentAnimating = $("#content").find("h1.animating");
			
			if ($currentAnimating.length<1) {
				$currentAnimating = $("#content").find("h1:first-child");
			}
			
			$currentAnimating.fadeOut("slow", function() {
				$(this).removeClass("animating");
			
				//get the next title and fade it in
				var $nextAnimating = $currentAnimating.next();
				
				if ($nextAnimating.length<1) {
					$nextAnimating = $("#content").find("h1:first-child");
				}
				
				$nextAnimating.fadeIn("slow").addClass("animating");
			});
		}, 5000);
	}
	
	function animLights() {				
		//fade the boxes in, then animate the lines
		$(".box .internal").hide().fadeIn(1000, function() {
			$(".light").each(function() {
				$(this).animate({left: - $(this).width() }, 4000);
			});
		}).delay(4000).fadeOut(2000);
		
		window.setTimeout(function() {
			readyBoxInteractions();
		}, 7000);
	}
	
	$(".box_wrapper .box .internal").click(function(e) {
		e.preventDefault();
	});
	
	//fix the half width rounding issue
	$(window).resize(function() {
		$("body").width(Math.floor($(window).width()/2.0)*2);
	});
	
	$(window).resize();

	//remove the placeholder text for the search box if the box is clicked on
	var placeholder = "search our site...";
	var $searchText = $("#search_text");
	var $searchSubmit = $("#search_submit");
	
	$searchText.val(placeholder);
	
	$searchText.focus(function() {
		if ($searchText.val()==placeholder) {
			$searchText.val("");
		}
	});
	
	$searchText.blur(function() {
		if ($searchText.val()=="") {
			$searchText.val(placeholder);
		}
	});
	
	$searchSubmit.click(function() {
		if ($searchText.val()==placeholder) {
			$searchText.focus();
			return false;
		}
	});
	
	//use ajax to grab the content for the fancy boxes
	$mainContent = $('<div id="ajaxContent"></div>');
	$mainContent.hide();
	$("#content").append($mainContent);
	
	$mainContentText = $('<div id="ajaxContentText"></div>');
	$mainContentText.hide();
	$mainContent.append($mainContentText);
	
	var fadeOutTimeout;
	
	//virtual tour scroller
	//override the links for the virtual tours and videos and open them in a lightbox
	$overlayBox.append($overlayContent, $closeOverlay, $overlayLeft, $overlayRight);
	$overlay.append($overlayBox).hide();
	$(document.body).append($overlay);
	
	$closeOverlay.click(function() {
		$closeOverlay.hide();
		$overlayLeft.hide();
		$overlayRight.hide();
		$overlayContent.hide().html("");
		$overlay.fadeOut("slow");
	});
	
	handleVirtualTours($(".content_text"));
	
	//highlight the selected page on the nav and submenu selected page
	var $pageLink = $("#wrapper #header #ddmenu ul ul li[data-category=" + subcategoryid + "][data-page=" + pageid + "]");
	$pageLink.addClass("selected");
	
	if ($pageLink.length>0) {
		$("#wrapper #header #ddmenu ul li[data-category=" + categoryid + "][data-page=" + subcategorypageid + "]").addClass("selected");
		$("#wrapper #header #ddmenu > li[data-category=1][data-page=" + categorypageid + "]").addClass("selected");
	} else {
		var $pageLink = $("#wrapper #header #ddmenu ul li[data-category=" + categoryid + "][data-page=" + pageid + "]");
		$pageLink.addClass("selected");
		
		if ($pageLink.length>0) {
			$("#wrapper #header #ddmenu > li[data-category=1][data-page=" + categorypageid + "]").addClass("selected");
		} else {
			$("#wrapper #header #ddmenu > li[data-category=1][data-page=" + pageid + "]").addClass("selected");
		}
	}
	
	//replace the content scrollbars with custom nice looking scrollbars
	replaceCustomScrollbars($(".content_text"));
	
	/* Page tabs */
	$(".tab_panel").each(function() {
		var $tabPanel = $(this);
		var $tabs = $tabPanel.find(".tab");
		var $tabLinks = $tabs.find("a");
		var $tabContent = $tabPanel.find(".tab_content");
		
		//if no hash is given, then use the first tab as the default
		if (typeof window.location.hash == "string" && window.location.hash!=="") {
			var $defaultTab = $tabPanel.find(".tab a[href$=" + window.location.hash + "]").parent(".tab");
			var $defaultTabContent = $tabPanel.find("#tab_" + window.location.hash.substring(1));
		} else {
			var $defaultTab = $tabPanel.find(".tab:first-child");
			var $defaultTabContent = $tabPanel.find('.tab_content:first-child');
		}
		
		$defaultTab.addClass("selected");
		$defaultTabContent.addClass("selected");
		
		//when a new tab is requested, fade out the content for the existing tab and fade in the new one
		$(this).find(".tab a").click(function() {
			var href = $(this).attr("href");
			var hashoffset = href.indexOf("#");
			
			$tabs.removeClass("selected");
			$(this).parent(".tab").addClass("selected");
			
			if (hashoffset>=0) {
				var hashPart = href.substring(hashoffset+1);
				var $newTabContent = $tabPanel.find("#tab_" + hashPart);
				
				if (!$newTabContent.hasClass("selected")) {
					var $currSelected = $tabPanel.find(".tab_content.selected");
					
					$newTabContent.addClass("selected");
					
					if ($currSelected.length>0) {
						$currSelected.removeClass("selected").hide();//.fadeOut("slow");
						
						window.setTimeout(function() {
							$tabPanel.find(".tab_content").hide();
							//$newTabContent.fadeIn("slow");
							$newTabContent.show();
						}, 500);
					} else {
						$newTabContent.show();//.fadeIn("slow");
					}
				}
			}
		});
	});
	
	$(".tab.selected a").each(function() {
		var href = $(this).attr("href");
		var hashoffset = href.indexOf("#");
		
		if (hashoffset>=0) {
			var hashPart = href.substring(hashoffset+1);
			var $newTabContent = $(this).parents(".tab_panel").first().find("#tab_" + hashPart);
			
			$(".tab_content").hide();
			$newTabContent.show();
		}
	});
	
	/* Chartwell Care tabs */
	var $chartwell_care_includes = $("#chartwell_care_includes");
	$chartwell_care_includes.find("a").click(function() {
		if (!$(this).hasClass("selected")) {
			var $newSelected = $(this);
			
			$("#chartwell_care_tabs .chartwell_care_tab.selected").stop(false, true).fadeOut("slow", function() {
				$(this).removeClass("selected");
				$("#chartwell_care_includes a.selected").removeClass("selected");
				$newSelected.addClass("selected");
				
				$("#chartwell_care_tabs #" + $newSelected.attr("href").substring($newSelected.attr("href").indexOf("#")+1)).stop(false, true).fadeIn("slow", function() {
					$(this).addClass("selected");
					
					var $content = $chartwell_care_includes.parents(".content_text").first();
					
					if ($content.data("calcHeight") && $content.data("calcPosition")) {
						$content.data("calcHeight")();
						$content.data("calcPosition")();
					}
				});
			});
		}
		
		return false;
	});
});

