Comaea = new Object;

$(document).ready(function(){
	// set up nugget layer triggers
	jQuery( 'a.tooltip' ).each( Comaea.ToolTips.setup );						   
	
	//jQuery( 'body' ).bind( 'click', Comaea.ToolTips.timeClose ) ;
	
	//jQuery('#tooltip').click(function(e){e.stopPropagation();});
});

Comaea.ToolTips =
{
	setup: function(){
		jQuery(this).bind('click',Comaea.ToolTips.open);
		//jQuery(this).bind('mouseenter mouseleave', function(){Comaea.ToolTips.open});
		jQuery(this).hoverIntent(Comaea.ToolTips.open, Comaea.ToolTips.close);
		//jQuery(this).bind('mouseleave',Comaea.ToolTips.close);
	},
	
	open: function(e){
		var content= jQuery(this).next('span.moreinfo').html();
		var tooltipLayer = jQuery('<div id="tooltip"><div class="content"><p></p></div></div>').css( { height:0, width:0, margin:0, opacity:0 } );
		
		if (!jQuery('#tooltip').length)
		{
			jQuery('.tabcontent').append( tooltipLayer ).find( '#tooltip p').html(content);
			Comaea.ToolTips.delegateResults();
			tooltipLayer.animate( { height:301, width:330, opacity:1, right:-280, top:jQuery(this).parent('p').position().top-280 }, 500, 'swing' );
		}
		
		// Close on Body Click
		setTimeout( function() { jQuery( 'body' ).bind( 'click', Comaea.ToolTips.close ) }, 1);
		
		jQuery('#tooltip').click(function(e){
										  e.stopPropagation();
										  });
		e.preventDefault();
	},
	
	close: function(e){
		jQuery( '#tooltip' ).animate( { opacity:0 }, 300, 'swing', function() { jQuery( '#tooltip' ).remove() } );
		
		// remove close event
		jQuery( 'body' ).unbind( 'click',  Comaea.ToolTips.close );
		
		//e.preventDefault();
	},
	
	delegateResults: function(){
		jQuery( '#tooltip' ).append( jQuery( '<div class="close"><a href="#" class="buttonBlueClose">Close</a></div>' ) );
		jQuery( '#tooltip .close' ).bind( 'click', Comaea.ToolTips.close );
		
	}
}