(function($)
{
	$.fn.tooltip = function(options)
	{		
		var settings = 
		{
			'target'	: this.selector,
			'source'	: this.selector,
			'offset'	: {x: 10, y: 35}
		};
		
		if (options)
			$.extend(settings, options);
		
		if (settings.target == settings.source)
		{
			$(settings.target).live('mouseover', function()
			{
				var dimensions = $(this).offset();
				
				var tooltip = $('<div class="tooltip"><span class="tip-arrow"></span>' + $(this).attr('title') + '</div>').appendTo('body');
				
				$(tooltip).css({'position': 'absolute', 'top': dimensions.top + settings.offset.y, 'left': dimensions.left + settings.offset.x});
				
				$(this).data('title', $(this).attr('title')).attr('title', '');	
			}).live('mouseout', function()
			{
				if ($(this).data('title') != null)
					$(this).attr('title', $(this).data('title'));
				
				$('.tooltip').remove();
			});
		}
		else
		{
			$(settings.target).live('mouseover', function()
			{
				$(this).find(settings.source).each(function(i, el)
				{
					if ($(el).attr('title') == '')
						return;
					
					var dimensions = $(el).offset();
					
					var tooltip = $('<div class="tooltip"><span class="tip-arrow"></span>' + $(el).attr('title') + '</div>').appendTo('body');
					
					$(tooltip).css({'position': 'absolute', 'top': dimensions.top + settings.offset.y, 'left': dimensions.left + settings.offset.x});
					
					$(el).data('title', $(el).attr('title')).attr('title', '');	
				});
			}).live('mouseout', function()
			{
				$(this).find(settings.source).each(function(i, el)
				{
					if ($(el).data('title') != null)
						$(el).attr('title', $(el).data('title'));
				});
				
				$('.tooltip').remove();
			});
		}
		
		return this;		
	};
})(jQuery);

jQuery(document).ready(function($)
{
	$('.tip').tooltip();
	
	$('#menu-item-38 a').attr('target', '_blank');
	
	$('#who').mouseenter(function()
	{
		$('#menu-what-we-do').hide();
		$('#menu-our-clients').hide();
		$('#menu-who-we-are').show();
	});
	
	$('#what').mouseenter(function()
	{
		$('#menu-who-we-are').hide();
		$('#menu-our-clients').hide();
		$('#menu-what-we-do').show();
	});
	
	$('#client').mouseenter(function()
	{
		$('#menu-what-we-do').hide();
		$('#menu-who-we-are').hide();
		$('#menu-our-clients').show();
	});
	
	$('table#nav img').mouseenter(function()
	{
		$(this).show();
		var alt = $(this).attr('rel');
		$(this).attr('rel', $(this).attr('src'));
		$(this).attr('src', alt);
	}).mouseout(function()
	{
		var alt = $(this).attr('rel');
		$(this).attr('rel', $(this).attr('src'));
		$(this).attr('src', alt);
		$(this).hide().fadeIn();
	});
	
	/*
	$('table#nav tr:first-child a').mouseenter(function()
	{
		var id = $(this).attr('id');
		
		$('#' + id + 'img').trigger('mouseenter');
	}).mouseleave(function()
	{
		var id = $(this).attr('id');
		
		$('#' + id + 'img').trigger('mouseout');
	});
	*/
});
