/*
This class applies tooltips to the prizeCarousel list element images.

Tooltip copy is semantically inserted into the list element in the span .tipBlurb. HTML is allowed in the tooltip copy.

It must play nice with the jCarouselLite plugin, since they are both applied to the prize Carousel.
Hovering over a prize image shows a tooltip dynamically placed above the prize.
*/
jQuery.fn.prizeToolTips = function() {
	var container = this;	
	var parentOffsetLeft = 220;
	//var parentOffsetLeft = 115;
	var parentOffsetTop = 0;
	if ($("#prizeCarouselContainer").length) {
		parentOffsetTop = $('#prizeCarouselContainer').position().top + 12;
	}
	// IE6 box model fix
	// not using feature detection because this problem is endemic to IE6.
	if (($.browser.msie) && (parseInt($.browser.version) == 6)) {
		parentOffsetTop += 3;
	} 
	var listEls = container.find('li');
	var toolTip = $('#prizeTip');
	var toolTipCopy = $('#prizeTipCopy');
	listEls.each( function(e) {
		$(this).first('img').hover(
			function() {
				// populate tool tip with tipBlurb contents
				var tipBlurb = $(this).find('.tipBlurb').html();
				toolTipCopy.html('<p>'+tipBlurb+'</p>');
				// compute x-position
				var xOffset = $(this).first('img').position().left + $(this).parent('ul').position().left + parentOffsetLeft;
				toolTip.css('left', xOffset);
				// compute y-position
				var yOffset = parentOffsetTop - toolTip.outerHeight();
				toolTip.css('top', Math.round(yOffset));
				toolTip.css('display', 'block');
			},
			function() {
				toolTip.css('display', 'none');
			}
		);
	});
}
