var $j = jQuery.noConflict(); 

var xhr = null;

$j(document).ready(function(){
//	if ($j('div.ddg-kit-items').length > 0 && $j('div.ddg-kit-items div').length > 0) {
	if ($j('div.ddg-kit-items').length > 0) {
		$j('div.ddg-kit-items').html($j('div.ddg-kit-items').html().replace(/\[/g, '<div>').replace(/\]/g, '</div>'));
	
		var mySplit = '';

		$j('.ddg-kit-items div').each(function(){
											   
			tempId = $j(this).html();

			$j(this).attr('id', "div_" + tempId);
	$j('#div_'+tempId).hide();
			$j.get("/spiegeldg/getProductName.php", { id:tempId }, function(data) {
				mySplit = data.split("_"); 
				$j('#div_' + mySplit[0]).html('<ul><li><span id=\"tooltip_' + mySplit[0] + '\" style=\"cursor:pointer;\" class=\"tooltip\" title=\"' + mySplit[0] + '\" >' + mySplit[1] + '</span></li></ul>');
					
				tooltip('tooltip_' + mySplit[0]);
				$j('div.ddg-kit-items').show();
				$j('#loader').remove();
				$j('#div_' + mySplit[0]).show();
			});
		});
	}
});


this.tooltip = function(myId){	
	/* CONFIG */		
		/*xOffset = -464;*/
		/*yOffset = 110;*/	
		//yOffset = 80;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */
//	$j('#'+myId).unbind('mouseover').unbind('mouseout');	
	$j('#'+myId).hover(function(e){
								
		/* Added 3/31/09 to calculate absolute page position of li element*/						
		var offset = $j(this).offset();	
		var xOffset = offset.left - 414 - 18; // 414 = box width; 18 = a little extra padding
		var yOffset = offset.top - 74 + 9; // 74 = 1/2 the box height; 8 = makes up for LI padding
										
		this.t = this.title;
		this.title = "";			
		$j("body").append("<div id='tooltip' style='position:absolute;width:414px;height:148px;display:none;'><img id='loaderPop' style='width:20px;height:20px;' src='/skin/frontend/ddg/default/images/bigLoader.gif' alt='' /> Loading...</div>");
		$j("#tooltip")
			/*.css("left",(e.pageX + xOffset) + "px")*/
			
			/*
			.css("left","280px")
			.css("top",(e.pageY - yOffset) + "px")
			*/
			
			/* Added 3/31/09 to calculate absolute page position of li element*/	
			.css("left", xOffset + "px")
			.css("top", yOffset + "px")			
			.fadeIn("fast");

			if(xhr) {xhr.abort(); xhr = null; } //abort any previous requests
			xhr = $j.ajax({
				  url: "/spiegeldg/getPopupProduct.php",
				  type: "GET",
				  data: ({id: this.t}),
				  success: function(data){
					this.dispText = data;
					$j("#tooltip").html(this.dispText);
				  }
			   }
			);
				
    },
	function(){
		this.title = this.t;		
		$j("#tooltip").remove();
    });	
/*
	$j("a.tooltip").mousemove(function(e){
		$j("#tooltip")
			.css("left",(e.pageX + xOffset) + "px")
			.css("top",(e.pageY - yOffset) + "px");
	});
*/		
};