// requires dimensions library | jquery.dimensions.js

jQuery.fn.poptip = function(baseRel,baseStyle,type) {

	//hello jQuery
	$ = jQuery;
	
	//hover delay in milliseconds
	delay = 300;
	
	//tooltip types
	if (type == 'vertical_fixed') {
		$('<div id="'+ baseStyle + '"><div class="top"></div><div class="content"></div><div class="bottom"></div></div>').hide().appendTo('body');
	} else if (type == "vertical") {
		$('<div id="'+ baseStyle + '"><div id="'+ baseStyle + '_arrow_top"></div><div class="top"></div><div class="content"></div><div class="bottom"></div><div id="'+ baseStyle + '_arrow_bottom"></div></div>').hide().appendTo('body');
	}
	else if (type == "game") {
		$('<div id="'+ baseStyle + '"><div id="'+ baseStyle + '_arrow_left"></div><div class="top"></div><div class="content"></div><div class="bottom"></div><div id="'+ baseStyle + '_arrow_right"></div></div>').hide().appendTo('body');
	}
	else if (type == "preview") {
		$('<div id="'+ baseStyle + '"><div class="content"></div><div class="bottom"></div></div>').hide().appendTo('body');
	}
	
	
	//snatch up the graavy aka that is define a custom class for all anchors with a rel of the baseRel
	jQuery.extend(
		jQuery.expr[ ":" ],
		{
			poptips : ("jQuery(a).attr('rel') == '"+baseRel+"'")
		}
	);
	
		//show and hide tooltips
		$("a:poptips").bind("mouseenter",function(){
			
			mainHeight = $(window).height();
			mainWidth = $(window).width();
			buttonLeft = $(this).position().left;
			buttonWidth = $(this).width();
			buttonTop = $(this).position().top;
			
			hoverTimer = setTimeout(function() {		
				
				// show the tip
				$("#"+baseStyle).css({ top: curTop + 'px', left: curLeft + 'px' }).show();	
			});
			if (type == "preview") {
				$("#"+baseStyle).find(".game_links").remove();
				$(this).parent().clone().prependTo("#"+baseStyle);
			}
			curID = $(this).attr("id");
			curText = eval(curID+"text");
			if (type == "vertical_fixed") {
				curHeader = eval(curID+"header");
				$("#"+baseStyle).find(".top").html(curHeader);
				$("#"+baseStyle).find(".content").html(curText);
			} else if (type == "game") {
				curImg = eval(curID+"img");
				$("#"+baseStyle+"_img").attr("src",curImg);
				$("#"+baseStyle).find(".content").html("<img src="+ curImg + ">" + curText);
			} else if (type == "preview") {
				$("#"+baseStyle).find(".content").css("min-height","250px")
			} else {
				$("#"+baseStyle).find(".content").html(curText);
			}
						
			if (type == "game" && jQuery.browser.msie == true) {
				buttonTop = buttonTop + 55;
			}
			
			tipHeight = $("#"+baseStyle).height();
			tipWidth = $("#"+baseStyle).width();
			curLeft = buttonLeft - tipWidth/4 + 40; 
			curTop = buttonTop - tipHeight - 5;
			
			
			
		});
		
		$("a:poptips").bind("mouseleave",function(){
			$("#"+baseStyle).hide();
		});
		
}