﻿

$(document).ready(function() {
    $('.PageMenuItem').click (function () {
        $('#PagePopupGrayBackground').show ();
    });
});

function openPopup (code, w, h)
{
    $('#PopupContent').html (code);
    
    $('#PagePopupGrayBackground').fadeIn (300);
}

function closePopup ()
{
    $('#PagePopupGrayBackground').fadeOut (300);
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 10;
		
		specOffset = 0;
		
		var curId = "";
		
		var titles = new Array ();
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */
	
	$(".toolTip").mouseover(function(e) {
	
        var curTitle = '';
        
	    if (titles[this.id] == undefined)
	    {
	        titles[this.id] = this.title;
	        this.title = "";
	    }

	    curTitle = titles[this.id];
	    
	    curTitle = curTitle.replace (/energiinfo/i, "<span style=\"font-style: italic;\">energiinfo&trade;</span>");
	    
		//this.t = this.title;
		//this.title = "";
		$("body").append("<p id='tooltip'>" + curTitle +"</p>");
		
		this.newX = e.pageX + xOffset;
		
		this.curWidth = $(window).width();
		
		this.curTooltipWidth = 40 + $("#tooltip").width();
		
		specOffset = 0;
		
		if (this.newX + this.curTooltipWidth >= this.curWidth)
		{
		    this.newX = this.curWidth - this.curTooltipWidth;
		    
		    specOffset = this.newX - (e.pageX + xOffset);
		    
		}
        
        curId = this.id;
        
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset + specOffset) + "px")
			.fadeIn("fast");
	});
	
	
	$(".toolTip").mouseout(function(e) {
		specOffset = 0;
		curId = "";
		$("#tooltip").remove();
	});
	
	/*
	$(".toolTip").hover(function(e){

        var curTitle = '';
        
	    if (titles[this.id] == undefined)
	    {
	        titles[this.id] = this.title;
	        this.title = "";
	    }

	    curTitle = titles[this.id];
	    
		//this.t = this.title;
		//this.title = "";
		$("body").append("<p id='tooltip'>" + this.id + " - " + curTitle +"</p>");
		
		this.newX = e.pageX + xOffset;
		
		this.curWidth = $(window).width();
		
		this.curTooltipWidth = 40 + $("#tooltip").width();
		
		specOffset = 0;
		
		if (this.newX + this.curTooltipWidth >= this.curWidth)
		{
		    this.newX = this.curWidth - this.curTooltipWidth;
		    
		    specOffset = this.newX - (e.pageX + xOffset);
		    
		}
        
        
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset + specOffset) + "px")
			.fadeIn("fast");
		
    },
	function(){
		//this.title = this.t;
		specOffset = 0;
		$("#tooltip").remove();
    });
    */
	$(".toolTip").mousemove(function(e){
	
	    if (curId == this.id)
	    {
    		$("#tooltip")
			    .css("top",(e.pageY - yOffset) + "px")
			    .css("left",(e.pageX + xOffset + specOffset) + "px");
		}
		else
		{
    		specOffset = 0;
		    curId = "";
		    $("#tooltip").remove();
		}
		
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});



