(function($)
{	
	// constructor
	function Flyout(root, conf)
	{	
		// Private fields ------------------------------------------------------------------
	
		var _root = $(root),
			
			_domElement = _root[0],
			_detailsHolder = _root.find(".detailsContainer"),
			_self = this,
			_opts = {
				debug: false
			}
			;
			$.extend(_opts, conf);
	
		// Public methods ------------------------------------------------------------------
		$.fn.extend({
			
			showFlyout: function(whichDetails) {
			
				var curDetails = $('#' + whichDetails);
				

				//show the details
				$(curDetails).css('display', 'table');
				$(_domElement).css('display', 'table');
				return false;
			},
			
			hideFlyout: function(whichDetails){
				
				var curDetails = $('#' + whichDetails);
		
				$(curDetails).css('display', 'none');
				$(_domElement).css('display', 'none');
				return false;
			}
		
		});	
	
		// Private methods -----------------------------------------------------------------
			
		$.extend(_self, {

		});
		
		// generic binding function
		function bind(name, fn)
		{
			if ($.isFunction(fn) == false)
				return;
				
			$(_self).bind(name, fn);
		};
	
		function init()
		{	
			//load the details content into the holder
			var detailElements = $('.details').detach();
			$(_detailsHolder).append(detailElements);
			
			$(document).mousemove(function(e){
				$(_domElement).css('left', (e.pageX + 5));
				$(_domElement).css('top', ((e.pageY - $(_domElement).height()) - 5));
			});
			
		};
	
		// Initialization ------------------------------------------------------------------
		init();
	};

	// jQuery plugin implementation
	$.fn.flyout = function(conf)
	{
		var opts = {};
		$.extend(opts, conf);
		
		this.each(function()
		{
			var $instance = new Flyout($(this), opts);
		});
		return this; 
	};
})(jQuery);

