
var Flyover = {
	
	mainElem: null
	
	, hideTimer: null
	
	, show: function(linkElem, contentElem) {
		this.hideNow();
		this.mainElem = $('<div class="flyover-main"></div>').appendTo('body');
		
		this.mainElem.hover(
			function() {
				Flyover.clearHideTimer();
			}
			, function() {
				Flyover.hide();
			}
		);
		
		var clone = contentElem.clone();
		clone.attr('id', '');
		clone.attr('class', '');
		this.mainElem.append(clone);
		
		/*
		// NOTE: This misses any contained text, since those aren't "children".
		for (var i=0; i<contentElem.children().length; i++) {
			var childNode = contentElem.children()[i];
			log('childNode: ' + childNode);
			log('childNode.html(): ' + childNode.html());
			this.mainElem.append($(childNode).clone());
		}
		*/
		
		var pos = linkElem.offset();
		pos.left += linkElem.outerWidth();
		
		this.mainElem.css({
			left: pos.left
			, top: pos.top
		});
	}
	
	, hide: function() {
		this.clearHideTimer();
		if (this.mainElem) {
			this.hideTimer = setTimeout(function() { Flyover.hideNow(); }, 500);
		}
	}
	
	, hideNow: function() {
		this.clearHideTimer();
		if (this.mainElem) {
			this.mainElem.remove();
			this.mainElem = null;
		}
	}
	
	, clearHideTimer: function() {
		if (this.hideTimer) {
			clearTimeout(this.hideTimer);
			this.hideTimer = null;
		}
	}
	
};

