/**
 *
 */
(function($) {
	// define the condition plugin
	$.fn.condition = function(tooltip,options) {
		// build main options before initial procedure
		var opts = $.extend({}, $.fn.condition.defaults, options);
		// initialize condition tooltip plugin
		return this.each(function() {
			// creating reference to tooltip box
			var tip = $("<div></div")
				.addClass('tooltip')
				.css({
					'-webkit-border-radius':'3px',
					'-moz-border-radius':'3px',
					'-ms-border-radius':'3px',
					'border-radius':' 3px',
					'-moz-box-shadow':'2px 2px 5px #888',
					'-webkit-box-shadow':'2px 2px 5px #888',
					'box-shadow':'2px 2px 5px #888'
				}).html($(this).parent().find(tooltip).html());
			// building hover mouse actions
			$(this).hover(function() {
				$("body").append(tip); $(tip).show();
			}, function() {
				$(tip).hide(); $(tip).remove();
			}).mousemove(function(event) {
				var posx = event.pageX + 20; // Get X coordinates
				var posy = event.pageY + 20; // Get Y coordinates
				var tipWidth = $(tip).width(); // Find width of tooltip
				var tipHeight = $(tip).height(); // Find height of tooltip
				// distance of element from the right edge of viewport
				var tipVisX = $(window).width() - (posx + tipWidth);
				// distance of element from the bottom of viewport
				var tipVisY = $(window).height() - (posy + tipHeight);
				if (tipVisX < 20) { // if tooltip exceeds the X coordinates
					posx = event.pageX - tipWidth - 20;
				} if (tipVisY < 20) { // if tooltip exceeds the Y coordinates
					posy = event.pageY - tipHeight - 20;
				}
				// absolute position the tooltip according to mouse pointer
				$(tip).css({'top':posy+'px','left':posx+'px'});
			});
		});
	};
	function debug($msg) {
		if (window.console && window.console.log)
			window.console.log('debug: '+$msg);
	}
	$.fn.condition.defaults = {
		
	}
})(jQuery);
