/*
 * jQuery Mouseout-Click plugin 1.0
 *
 * Copyright (c) 2010 PowerHour - www.powerhour.at
 * 
 * @requirements jQuery 1.3+
 * 
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * @example Default-Event
 * 			$('div.hideOnMouseOutClick').mouseoutclick();
 * 
 * @example Individual Event
 * 			$('div#handleIndividualMouseoutClick').mouseoutclick(function()
 * 			{
 * 				alert('mouseoutclick');
 * 			});
 *
 */
$(function() 
{
    $.fn.mouseoutclick = function( callback ) 
    {
    	var $this = $(this);
    	var flagMouseoverKey = 'isMouseover'; 
    	
    	//set flag to 0/false 
    	$this.mouseleave(function()
		{
    		$this.data(flagMouseoverKey,0);
		});
    	
    	//set flag to 1/true
    	$this.mouseenter(function()
		{
    		$this.data(flagMouseoverKey,1);
		});
		
    	//handle mouseup-event
		$(document).bind('mouseup', function()
		{
			// if the mouserOverFlag is not set or set to 0
			if(!$this.data(flagMouseoverKey) || $this.data(flagMouseoverKey) == 0)
			{
				//Trigger callback (if set)
				if(typeof(callback) == 'function')
					callback();
				else //hide by default
					$this.hide();
			}
		});
	
	};
});
