function HelpHover()
{
	this._mousePosX = 0;
	this._mousePosY = 0;
	this._hoverItem = null;
	this._hoverContents = null;
	this._offsetY = 0;
}


function getWidth() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement &&
          ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
}

function getHeight() {
    myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        myHeight = window.innerHeight;
    } else if( document.documentElement &&
          ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function checkOverlaySupport() {
        if(navigator.userAgent.indexOf("Windows")!=-1  && typeof document.body!="undefined" &&
           typeof document.body.insertAdjacentHTML!="undefined" && !window.opera&&navigator.appVersion.indexOf("MSIE 5.0")==-1) {
            return true;
        } else {
            return false;
        }
}



HelpHover.prototype.init = function()
{
	var hh = this;
	var helpItems = document.getElementsByClassName('hasHelp');
	for (var i=0; i<helpItems.length; i++)
	{
		helpItems[i].onmousemove = function(e)
		{
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
				hh.mousePosX = e.pageX;
				hh.mousePosY = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				hh.mousePosX = e.clientX + document.documentElement.scrollLeft;
				hh.mousePosY = e.clientY + document.documentElement.scrollTop;
			}
			hh._hoverItem = this;
			hh._hoverContents = document.getElementById(this.id+'Help');
			hh.move();
		}
		helpItems[i].onmouseout = function (e)
		{
			hh.out();
		}
	}
	var helpItems = document.getElementsByClassName('hasHelpb');
	for (var i=0; i<helpItems.length; i++)
	{
		helpItems[i].onmousemove = function(e)
		{
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
				hh.mousePosX = e.pageX;
				hh.mousePosY = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				hh.mousePosX = e.clientX + document.documentElement.scrollLeft;
				hh.mousePosY = e.clientY + document.documentElement.scrollTop;
			}
			hh._hoverItem = this;
			hh._hoverContents = document.getElementById(this.id+'Help');
			hh.moveb();
		}
		helpItems[i].onmouseout = function (e)
		{
			hh.out();
		}
	}

}

HelpHover.prototype.out = function()
{
	this._hoverContents.style.top = -10000+'px';
	this._hoverContents.style.left = -10000+'px';
	this._hoverItem = null;
	this._hoverContents = null;
	if(checkOverlaySupport()){
//DC	    document.getElementById("tipShim").style.visibility='hidden';
	}
}

HelpHover.prototype.move = function()
{

        //this part is for scrolling
        var y = 0;
        if (self.pageYOffset)
            y = self.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)
            y = document.documentElement.scrollTop;
        else if (document.body)
            y = document.body.scrollTop;

        //these sites, don't neet worry about changing scroll 
        var brow = navigator.userAgent.toLowerCase();
        if (brow.indexOf("netscape")!=-1 || brow.indexOf("firefox")!=-1) {
             y = 0;
        }   

        var x1 = this.mousePosX + 'px';
        var browWidth = getWidth();
        if (browWidth != 0 && this.mousePosX + 310 > browWidth) {
           x1 = browWidth-310;
           x1 += 'px';
        }
        
        var y1 = this.mousePosY +10+y;
        y1 += "px";
        if(checkOverlaySupport()){
//DC            if(!document.getElementById('tipShim'))
//DC	        document.body.insertAdjacentHTML("beforeEnd",'<iframe id="tipShim" style="position:absolute; opacity: .85; -moz-opacity: .85;filter: Alpha(Opacity=85);left:0; top:0; z-index:500; visibility:hidden" scrolling="no" frameborder="0"></iframe>');
//DC	    document.getElementById('tipShim').style.width="275px";
//DC	    this._hoverContents.style.height= '75px';
//DC	    document.getElementById('tipShim').style.height='76px'; //this.tip.offsetHeight+"px";
//DC	    document.getElementById("tipShim").style.visibility='visible'
//DC	    document.getElementById("tipShim").style.left = x1;
//DC	    document.getElementById("tipShim").style.top = y1;
        }

	this._hoverContents.style.top = y1;
	this._hoverContents.style.left =  x1;

}

HelpHover.prototype.moveb = function()
{

        //this part is for scrolling
        var y = 0;
        if (self.pageYOffset)
            y = self.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)
            y = document.documentElement.scrollTop;
        else if (document.body)
            y = document.body.scrollTop;

        //these sites, don't neet worry about changing scroll 
        var brow = navigator.userAgent.toLowerCase();
        if (brow.indexOf("netscape")!=-1 || brow.indexOf("firefox")!=-1) {
             y = 0;
        }   

        var x1 = this.mousePosX;
        var y1 = this.mousePosY +10+y;


        var browWidth = getWidth();
        if (browWidth != 0 && this.mousePosX + 310 > browWidth) {
           x1 = browWidth-310;
        }

        var browHeight = getHeight();
        if (brow.indexOf("netscape")!=-1 || brow.indexOf("firefox") !=-1) {
            browHeight += self.pageYOffset;
        }
        if (browHeight != 0 && this.mousePosY +116   > browHeight) {
            y1 = browHeight-106 + y ;
            x1+= 5;
        }

        x1 += 'px';
        y1 += 'px';
        if(checkOverlaySupport()){
//DC            if(!document.getElementById('tipShim'))
//DC	        document.body.insertAdjacentHTML("beforeEnd",'<iframe id="tipShim" style="position:absolute; opacity: .85; -moz-opacity: .85;filter: Alpha(Opacity=85);left:0; top:0; z-index:500; visibility:hidden" scrolling="no" frameborder="0"></iframe>');
//DC	    document.getElementById('tipShim').style.width="275px";
//DC	    this._hoverContents.style.height= '105px';
//DC	    document.getElementById('tipShim').style.height='106px'; //this.tip.offsetHeight+"px";
//DC	    document.getElementById("tipShim").style.visibility='visible'
//DC	    document.getElementById("tipShim").style.left = x1;
//DC	    document.getElementById("tipShim").style.top = y1;
        }

	this._hoverContents.style.top = y1;
	this._hoverContents.style.left =  x1;

}

addEvent(window, 'load', function()
{
	var hh = new HelpHover();
	hh.init();
});


