var timeout = null;

// Track Mouse:
function trackMouse(e, ttDiv, offX, offY) {
 $(ttDiv).css("left", e.pageX + offX)
 $(ttDiv).css("top", e.pageY + offY); }
	
// Position Tool-Tip:
function ttPosition(ttDiv, offX, offY) {
 $(ttDiv).css("left", offX);
 $(ttDiv).css("top", offY); } 
	
// Center:
function centerFloaty(targetDiv) {
 $(targetDiv).css("left", "50%");
 $(targetDiv).css("top", "50%");

 $(targetDiv).css("margin-left", (0 - $(targetDiv).width() / 2));
 $(targetDiv).css("margin-top", (0 - $(targetDiv).height() / 2)); }

// Maximize:
function maximizeFloaty(targetDiv) {
 $(targetDiv).height($(document).height());
 $(targetDiv).width($(document).width()); }



// Create Tool-Tip / Pop-In:
function makeFloaty(targetDivID, targetDivClass, targetContent, zIndex, closeable) {
	
 // Add container to body:
 $("body").prepend('<div id="' + targetDivID + '"></div>');
	
	// Set the type:
 $('#' + targetDivID).addClass(targetDivClass);
	
	// Set the z-index:
 $('#' + targetDivID).css("z-index", zIndex);
	
	// Add the content to the floaty:
 $('#' + targetDivID).append(targetContent);
	
 // Determine closeable:
 if(closeable == '1') {
  $('#' + targetDivID).addClass('closeable'); }
		
	$(".fullscreen").live("click", function(){
  closeOpenedItems(); }); }

// Show Tool-Tip:
function showFloaty(targetDiv) {
 // Set this as an open item:
 $(targetDiv).addClass("open-item");
	  
 // Show the floaty:
 $(targetDiv).fadeIn("normal"); }




// Create AJAX page loader:
function createLoader(zIndex) {
	makeFloaty('page_loader', 'pop-in', 'Loading...', zIndex, 1);
 centerFloaty("#page_loader");
 showFloaty('#page_loader'); }

// Remove AJAX loader:
function stopLoader() {
 $("#page_loader").remove(); }

// Hide AJAX loader:
function hideLoader() {
 $("#page_loader").fadeOut("fast", stopLoader()); }





// Close/Destroy all open items:
function closeOpenedItems() {
 // Handle custom close function:
 customClose();

 // Hide open items:
 $(".closeable").fadeOut("slow", function() {

  // Destroy Tool-Tips and pop-ins:
  $(this).remove(); }); }




// Listener functions:
$(document).ready(function() {

 // Window resize listener:
 $(window).resize(function() {
  // Keep the fullscreen items the correct size:
  maximizeFloaty(".fullscreen"); });
});