(function(container){

	var self = {
		
		init:		function()
		{
			self.wrapHints();
			$('.profileDataHomePower div').hover(self.showHint, self.hideHint);
			$('.hintIcon').hover(self.showHint, self.hideHint);
		},
		
		showHint: function()
		{
			var currentElement = this;
			
			
			var hintElement = self.getHintElement(currentElement);
			
			if($(hintElement).parent().get(0).tagName != 'BODY')
			{
				$(hintElement).remove();
				$('body').append(hintElement);
				var position = self.getHintPosition(currentElement, hintElement);
				$(hintElement).css(position);
			}
			
			$(hintElement).show();
			
			//extra handling of the status bar
			if($(currentElement).parent('#profileDataHomePower').get(0) != null)
			{
				$(currentElement).css('background-position', '0px -40px');
			}
			
		},
		
		hideHint: function()
		{
			var currentElement = this;
			//extra handling of the status bar
			if($(currentElement).parent('#profileDataHomePower').get(0) != null)
			{
				$(currentElement).css('background-position', '0px 0px');
			}
			
			$(self.getHintElement(currentElement)).hide();
		},
		
		getHintPosition: function(element, hintElement)
		{
			var position = $(element).offset();
			var height = $(element).height();
			var hintWidth = $(hintElement).width();
			var viewPortWidth = $('body').width();

			if((position.left + hintWidth + 30) > viewPortWidth)
			{// we are outer view port
				var hintPosition = {left: (viewPortWidth - hintWidth - 30), top: (position.top + height)};
			}
			else
			{
				var hintPosition = {left: position.left, top: (position.top + height)};
			}
			return hintPosition;
		},
		
		wrapHints: function()
		{
			$('.hasHint').wrapInner("<div class='hintIcon'></div>");
		},
		
		getHintElement: function(element)
		{
			//get last class and use it as id of the hint element
			if($(element).parent('#profileDataHomePower').get(0) != null)
			{
				var hintId = '#' + $(element).attr('class').split(' ').slice(-1);				
			}
			else
			{
				var hintId = '#' + $($(element).parent().get(0)).attr('class').split(' ').slice(-1);
			}
			
			return $(hintId);
		}
		
	}
	container.game.hints = self;
})(_meef);
$(_meef.game.hints.init);