/*
 +-------------------------------------------------------------------+
 |                   J S - T O O L T I P   (v1.2)                    |
 |                                                                   |
 | Copyright Gerd Tentler               info@gerd-tentler.de         |
 | Created: Feb. 15, 2005               Last modified: Mar. 1, 2005  |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

======================================================================================================

 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 4, NN 7, Opera 7
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.

------------------------------------------------------------------------------------------------------

 USAGE:

 Use the toolTip-function with mouse-over and mouse-out events (see example below).

 - To show a tooltip, use this syntax: toolTip(text, width in pixels, opacity in percent)
   Note: width and opacity are optional

 - To hide a tooltip, use this syntax: toolTip()

------------------------------------------------------------------------------------------------------

 EXAMPLE:

 <a href="#" onMouseOver="toolTip('Just a test', 150)" onMouseOut="toolTip()">some text here</a>

======================================================================================================
*/
  function TOOLTIP() {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------
    this.width = 200;                     // width (pixels)
    this.heightImg = 100;                 // height (pixels)
    this.bgColor = '#000000';             // background color
    this.textColor = '#000000';           // text color
    this.borderColor = '#000000';         // border color
    this.opacity = 100;                   // opacity (percent) - doesn't work with all browsers
    this.cursorDistance = 15;             // distance from cursor (pixels)

    // don't change
    this.text = '';
    this.obj = 0;
    this.sobj = 0;
    this.active = false;

// -------------------------------------------------------------------------------------------------------
// Functions
// -------------------------------------------------------------------------------------------------------
    this.create = function() {
      var pulsanti = "";
      if (this.heightImg != 100)
		{
		 //pulsanti = "<tr><td style='color:#ffffff;background-color:#000000;text-align:right;'><a style='color:#ffffff;background-color:#000000;text-align:right;font-size:10px;font-weight:bold;' href='javascript:toolTip();'><img src='/public/images/action_stop.gif'></a>&nbsp;</td></tr>";
		}
      if(!this.sobj) this.init();

      var t = '<table border=0 cellspacing=0 cellpadding=0 width=' + this.width + '>'+pulsanti+'<tr>' +
              '<td colspan=2 align=center><font color=' + this.textColor + '>' + this.text + '</font></td></tr></table>';

      if(document.layers) {
        t = '<table cellspacing=0 cellpadding=0 border=0>'+pulsanti+'<tr><td colspan=2 style=\'padding:0px;\' >' + t + '</td></tr></table>';
        this.sobj.document.write(t);
        this.sobj.document.close();
      }
      else {
        this.sobj.border = '1px solid ' + this.borderColor;
        this.setOpacity();
        if(document.getElementById) document.getElementById('ToolTip').innerHTML = t;
        else document.getElementById('ToolTip').innerHTML = t;
      }
      this.show();
    }

    this.init = function() {
      if(document.getElementById) {
        this.obj = document.getElementById('ToolTip');
        this.sobj = this.obj.style;
      }
      else if(document.all) {
        this.obj = document.all.ToolTip;
        this.sobj = this.obj.style;
      }
      else if(document.layers) {
        this.obj = document.ToolTip;
        this.sobj = this.obj;
      }
    }

    this.show = function() {
      //mouseX = event.clientX+ document.body.scrollLeft;
      //mouseY = event.clientY+ document.body.scrollTop;
      if (mouseX==undefined)
        {
         mouseX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        }
      if (mouseY==undefined)
        {
         mouseY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);    
        }      
      if (this.heightImg != 100)
        {
         document.onmousemove = getMouseXY;
        }
      var ext  = (document.layers ? '' : 'px');
      var left = mouseX;
      var top  = mouseY;
      var dimY = screen.height-100+ document.body.scrollTop;

	  left += this.cursorDistance;

	  if (this.heightImg == 100)
			{
			  if (left + this.width > winX) 
					{
					 left = winX-this.width-this.cursorDistance;
					}
		
			  top += this.cursorDistance;    
		
			  if (top + this.heightImg > dimY) 
					{ 
					 top2 = top;
					 top = dimY-this.heightImg-60-this.cursorDistance;
					 if (left + this.width < winX) 
						{
						 left = winX-this.width-this.cursorDistance-130;
						 //alert(top + "," + top2 + "," + this.heightImg + ","+dimY);
						}
					 //
					}
			  else 
					{
					 top += this.cursorDistance;      
					}
			 //alert(top + "," + this.heightImg + ","+dimY);
			}
	  else
			{
			 left = 220; //(screen.width-this.width)/2;
			 top  = 180; //((screen.height-this.heightImg)/2);
			}

      this.sobj.left = left + ext;
      if (this.heightImg!=100)
		{
		 this.sobj.top = top;
		}
	  else
		{
		 this.sobj.top = mouseY + this.cursorDistance + ext;
		}
      //alert(this.sobj.left+","+this.sobj.top);
      
      //alert(top + "," + this.heightImg + ","+document.body.scrollTop);

      if(!this.active) {
        this.sobj.visibility = 'visible';
        this.active = true;
      }
    }

    this.hide = function() {
      if(this.sobj) this.sobj.visibility = 'hidden';
      this.active = false;
    }

    this.setOpacity = function() {
      this.sobj.filter = 'alpha(opacity=' + this.opacity + ')';
      this.sobj.mozOpacity = '.1';
      if(this.obj.filters) this.obj.filters.alpha.opacity = this.opacity;
      if(!document.all && this.sobj.setProperty) this.sobj.setProperty('-moz-opacity', this.opacity / 100, '');
    }
  }

//----------------------------------------------------------------------------------------------------
// Build layer, get mouse coordinates and window width, create tooltip-object
//----------------------------------------------------------------------------------------------------
  var tooltip = mouseX = mouseY = winX = winY = heightImg = 0;

  if(document.layers) {
    document.write('<layer id="ToolTip"></layer>');
    document.captureEvents(Event.MOUSEMOVE);
  }
  else document.write('<div id="ToolTip" style="position:absolute; z-index:1000000;"></div>');
  document.onmousemove = getMouseXY;

  function getMouseXY(e) {
    if(document.all) {
      mouseX = event.clientX + document.body.scrollLeft;
      mouseY = event.clientY + document.body.scrollTop;
    }
    else {
      mouseX = e.pageX;
      mouseY = e.pageY;
    }
    if(mouseX < 0) mouseX = 0;
    if(mouseY < 0) mouseY = 0;

    if (document.body && document.body.offsetWidth) 
		{
		 winX = document.body.offsetWidth - 25;
		}
    else 
		{
		 if (window.innerWidth) 
			{
			 winX = window.innerWidth - 25;
			}
		 else 
			{
			 winX = screen.width - 25;
			}
		}


    if (document.body && document.body.offsetHeight) 
		{
		 winY = document.body.offsetHeight - heightImg;
		}
    else 
		{
		 if (window.innerHeight) 
			{
			 winY = window.innerHeight - heightImg;
			}
		 else 
			{
			 winY = screen.innerHeight - heightImg;
			}
		}
		
    if(tooltip && tooltip.active) tooltip.show();
    
    
  }

  function toolTip(text, width, opacity, heightImg) {
    if(text) {
      tooltip = new TOOLTIP();
      tooltip.text = text;
      if(width) tooltip.width = width;
      if(heightImg) tooltip.heightImg = heightImg;
      if(opacity) tooltip.opacity = opacity;
      tooltip.create();
    }
    else if(tooltip) tooltip.hide();
  }

  function showImg(textX, widthX, opacity, heightImgX,iii) 
	{
	 //imgIndex = iii;
	 //alert(iii);
	 pulsanti  = ""
	 pulsanti += "<tr>";
	 pulsanti += " <td style='padding-left:60px;width:90%;color:#ffffff;background-color:#000000;text-align:center;'>";
	 pulsanti += "  <a style='color:#ffffff;background-color:#000000;text-align:right;font-size:10px;font-weight:bold;' href='#' onclick=javascript:GoImg("+(iii-1)+");>";
	 pulsanti += "   <<";
	 pulsanti += "  </a>&nbsp;";
	 pulsanti += "  <a style='color:#ffffff;background-color:#000000;text-align:right;font-size:10px;font-weight:bold;' href='#' onclick=javascript:GoImg("+(iii+1)+");>";
	 pulsanti += "   >>";
	 pulsanti += "  </a>&nbsp;";	 
	 pulsanti += " </td>";
	 pulsanti += " <td style='color:#ffffff;background-color:#000000;text-align:right;'>";
	 pulsanti += "  <a style='color:#ffffff;background-color:#000000;text-align:right;font-size:10px;font-weight:bold;' href='#' onclick=javascript:ShowHideList('visible');document.getElementById('divImg').style.visibility='hidden';toolTip();><img src='/public/images/cross.gif' alt='Chiudi' style='position:relative;top:4px;'></a>&nbsp;";
	 pulsanti += " </td>";
	 pulsanti += "</tr>";
     var t = '<table border=0 cellspacing=0 cellpadding=0 width=' + parseInt(widthX) +'>'+pulsanti+'<tr>' +
              '<td colspan=2 align=center><font color=#000000>' + textX + '</font></td></tr></table>';	
     document.getElementById('divImg').innerHTML = t;         
     document.getElementById('divImg').style.visibility="visible";
     document.getElementById('divImg').style.left="220";
     document.getElementById('divImg').style.top=ToolTipY;
     ShowHideList('hidden');
	}
