﻿// Free for any type of use so long as original notice remains unchanged.
// Report errors to feedback@ashishware.com
//Copyrights 2006, Ashish Patil , ashishware.com
//////////////////////////////////////////////////////////////////////////

function getViewportHeight() {
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (window.innerHeight!=window.undefined) return window.innerHeight;	
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (window.innerWidth!=window.undefined) return window.innerWidth; 	
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function ToolTip(isAnimated,aniSpeed)
{ 
  var isInit = -1;    
  var frame, frm,divWidth,divHeight;
  var xincr=10,yincr=10;
  var animateToolTip =false;
  var html;
  var loadingUrl = "/Loading.html"; 
  var mouseInToolTip = false;
  var mouseInImage = false;

  this.IsMouseOnToolTip = function(e)
  {        
    var frameWidth = parseInt(frame.style.width);
    var frameHeight = parseInt(frame.style.height);
    var frameX = frame.offsetLeft;
    var frameY = frame.offsetTop;
    
    if(window.pageYOffset)
    { 
        frameY= frameY - window.pageYOffset;
        frameX = frameX - window.pageXOffset;
    }
    else
    { 
        frameY= frameY - document.documentElement.scrollTop;
        frameX = frameX - document.documentElement.scrollLeft;
    }
        
    var curPosx = (e.clientX)?parseInt(e.clientX):parseInt(e.x);
    var curPosy = (e.clientY)?parseInt(e.clientY):parseInt(e.y);
    
    if (curPosx > frameX && curPosx < frameX + frameWidth && curPosy > frameY && curPosy < frameY + frameHeight)
    {
        return true;
    }
    
    return false;
  }
  
  function OnToolTipMouseOut()
  {
    mouseInToolTip = false;
    ttip.Hide();
  }
  
  function OnToolTipMouseOver()
  {
    mouseInToolTip = true;
  }
  
  function OnImageMouseOut()
  {
    mouseInImage = false;
    this.PrepareToHide();
  }
  
  function OnImageMouseOver()
  {
    mouseInImage = true;
  }
  
  function Init()
  {
   frame = document.createElement("DIV");
   frame.style.border = "solid 1px Gray";
   frame.style.width = 300+"px"; 
   frame.style.height = 400+"px";  
   frame.style.display="none";
   frame.style.position="absolute"      
   frm = document.createElement("IFRAME");    
   frm.style.width = "100%"; 
   frm.style.height = "100%";    
   frm.setAttribute("frameBorder", "0");       
   frm.setAttribute("scrolling", "no");
   frm.src = loadingUrl;
   addEvent(frm, "mouseout", OnToolTipMouseOut);
   addEvent(frm, "mouseover", OnToolTipMouseOver);
   frame.appendChild(frm); 
   //frm.frameBorder = "0";
   //document.body.appendChild(frm); 
   document.body.appendChild(frame); 
   
   divWidth = parseInt(frame.style.width);
   divHeight= parseInt(frame.style.height);
   if(frm.style.overflow!="hidden")frm.style.overflow="hidden";   
   
   if(isAnimated && aniSpeed>0)
   {xincr = parseInt(divWidth/aniSpeed);
    yincr = parseInt(divHeight/aniSpeed);
    animateToolTip = true;
    }
        
   isInit++;   
  }
      
  var ctime;
  var img;
  this.Show =  function(e, srcpath, w, h, imgID)
  {
    mouseInToolTip = false;
    try { window.clearTimeout(ctime); } catch(err) {}
    try { window.clearTimeout(itime); } catch(err) {}
    img = document.getElementById(imgID);
    if(isInit<0) return;
    
    frame.style.width = w + "px"; 
    frame.style.height = h + "px"; 
    divWidth = w;
    divHeight = h;
    
    var newPosx, newPosy, height, width;
    
    width = getViewportWidth();
    height = getViewportHeight();
    
    var curPosx = (e.clientX)?parseInt(e.clientX):parseInt(e.x);
    var curPosy = (e.clientY)?parseInt(e.clientY):parseInt(e.y);
    
    frm.src=srcpath + (srcpath.indexOf("?") == -1 ? "?" : "&") + "Random=" + (new Date()).getTime();
    if((curPosx+divWidth+10)< width)
    {
        newPosx= curPosx+10;
    }
    else
    {
        newPosx = curPosx-divWidth;
    }

    if((curPosy+divHeight)< height)
    {
        newPosy= curPosy;
    }
    else
    {        
        newPosy = curPosy-divHeight-10;
    }

    if(window.pageYOffset)
    { 
        newPosy= newPosy+ window.pageYOffset;
        newPosx = newPosx + window.pageXOffset;
    }
    else
    { 
        newPosy= newPosy + document.documentElement.scrollTop;
        newPosx = newPosx + document.documentElement.scrollLeft;
    }
    
    frame.style.display='block';    
    frame.style.top= newPosy + "px";
    frame.style.left= newPosx+ "px";

    frm.focus();
    if(animateToolTip){
    frame.style.height= "0px";
    frame.style.width= "0px";
    ToolTip.animate(frame.id,divHeight,divWidth);}          
}    

    this.PrepareToHide = function()
    {
        ctime = window.setTimeout("ttip.Hide();", 300);
    }
    
    var itime;
    this.PrepareToHideImage = function(imgID)
    {        
        itime = window.setTimeout("ttip.HideImage('" + imgID + "');", 300);
    }
    
    this.HideImage = function(imgID)
    {
        if (mouseInImage) return;
        var img = document.getElementById(imgID);
        img.style.display = 'none';
    }
    
    this.Hide= function()
    {
        if (mouseInToolTip) return;    
        if (img != null) img.style.display = 'none';        
        frm.src = loadingUrl;         
        frame.style.display='none';
        if(!animateToolTip)return;
        frame.style.height= "0px";
        frame.style.width= "0px";            
    }    
    
    ToolTip.animate = function(a,iHeight,iWidth)
    { 
        a = document.getElementById(a);
         
        var i = parseInt(a.style.width)+xincr ;
        var j = parseInt(a.style.height)+yincr;  
   
        if(i <= iWidth)
        {
            a.style.width = i+"px";
        }
        else
        {
            a.style.width = iWidth+"px";
        }

        if(j <= iHeight)
        {
            a.style.height = j+"px";
        }
        else
        {
            a.style.height = iHeight+"px";
        }

        if(!((i > iWidth) && (j > iHeight)))      
            setTimeout( "ToolTip.animate('"+a.id+"',"+iHeight+","+iWidth+")",1);
    }
    
    Init();
}

onload = function() { ttip = new ToolTip(false);}


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();