/*
	# Code to display and hide the help information and any drop downs which will be within the area the help information will cover.	
	*/
	
	var selectArray = new Array();
    var helpTextPosition;
    
    
    function setupSelectPositionArray()
    {
        //Create an array of the select elements on the page and the related position values
        $("select").each
	    (
            function()
            {
           
                var objPosition = Position(this);
        
                if (objPosition.top)
                {
                    var JSON_object = 
                    {
                     top:    objPosition.top, 
                     left:   objPosition.left, 
                     bottom: (objPosition.top + objPosition.height), 
                     right:  (objPosition.left+ objPosition.width)
                    }
                  
                    selectArray.push( JSON_object );
                } 
            }
       );
    }
    
    function SetHiddenTitleInfo(titleInfo)
    {           
        var hiddenTitleInfo = $('#hiddenTitleInfo');
           
        $('#hiddenTitleInfo').attr({value : titleInfo });
    }
    function GetHiddenTitleInfo()
    {
       var hiddenTitleInfo;        
       hiddenTitleInfo = $('#hiddenTitleInfo').attr("value");        
       return hiddenTitleInfo;        
    }
    function AddHiddenTitleInfo()
    {        
        $("form").append("<input type=\"hidden\" id=\"hiddenTitleInfo\" value=\"\" name=\"hiddenTitleInfo\" />");
    }
   
	$(document).ready
	(
		function()
		{
            
            AddHiddenTitleInfo();    
          //  setupSelectPositionArray();
            SetHiddenTitleInfo("");
            
            try
            {
                       
                        
                $("img.INFOBOX").hover
                //$("img.INFOBOX").click
                (
                    function()
                    {
                        var atext;
                        if ( (atext = $(this).attr("title") ) != "undefined")
                        {
                            SetHiddenTitleInfo(atext);
                            $(this).attr({title: ""});
                            $("<div class='infoHoverWindow'>" + atext+ "</div>").appendTo(document.body).fadeIn("slow");
                            $(".infoHoverWindow").right( $(this).right()).top($(this).top());
                            
                            $(".infoHoverWindow").css('top',  $(".infoHoverWindow").top()- $(".infoHoverWindow").height()-10);

                        
                            var hoverBoxPos = Position( $(".infoHoverWindow").get(0))
                          
                           
                            helptextPosition = 
                            {
                                top:    (hoverBoxPos.top - 10), 
                                left:   (hoverBoxPos.left - 10), 
                                right:  (hoverBoxPos.left+hoverBoxPos.width + 10), 
                                bottom: (hoverBoxPos.top+ hoverBoxPos.height + 10)
                            }

                            $("select").each
                            (
                                function(i)
                                {
                         
                                    var b = helptextPosition;
                                    var a = selectArray[i];
                                    if (typeof(a) == "undefined") return;
                                    var chkHoz  = (((a.left > b.left) && (a.left <b.right)) ||  ((a.right < b.right) && (a.right > b.left)));
                                    var chkVert = (((a.top > b.top) && (a.top <b.bottom)) ||  ((a.bottom < b.bottom) && (a.bottom > b.top)));
                       
                                    if ( chkHoz  && chkVert)
                                    {
                                        $(this).css({visibility: "hidden"});
                                    }
                                }     
                            );
                        }
                    },function()
                    {
                        var hiddenTitleInfo = GetHiddenTitleInfo();
                        $(this).attr({title: hiddenTitleInfo});
                        $("div.infoHoverWindow").fadeOut(200).remove();
                        $("select").css({visibility: "visible"});
                    }
                
                );
                    
              }
              catch(err)
              {
                   $("img.INFOBOX").hover
                   (
                        function()
                        {
                        },
                        function()
                        {
                            var hiddenTitleInfo = GetHiddenTitleInfo();
                            $(this).attr({title: hiddenTitleInfo});
                            $("div.infoHoverWindow").fadeOut(200).remove();
                            $("select").css({visibility: "visible"});
                        }
                    );
               }       
               
           }
    )

function Position(o) 
{
    var fixBrowserQuirks = true;
    
    if (o==null) 
    {
      return null;
    }
    
    var left = 0;
    var top = 0;
    var width = 0;
    var height = 0;
    var parentNode = null;
    var offsetParent = null;
  
    
    offsetParent = o.offsetParent;
    var originalObject = o;
    var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
    while (el.parentNode!=null) 
    {
      el = el.parentNode;
      if (el.offsetParent==null) 
      {
      }
      else 
      {
        var considerScroll = true;
        /*
        In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
        take its scroll position into account. If elements further up the chain are scrollable, their 
        scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
        which must be ignored.
        */
        if (fixBrowserQuirks && window.opera) 
        {
          if (el==originalObject.parentNode || el.nodeName=="TR") 
          {
            considerScroll = false;
          }
        }
        if (considerScroll) 
        {
          if (el.scrollTop && el.scrollTop>0)
          {
            top -= el.scrollTop;
          }
          if (el.scrollLeft && el.scrollLeft>0) 
          {
            left -= el.scrollLeft;
          }
        }
      }
      // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
      if (el == offsetParent) 
      {
        left += o.offsetLeft;
        if (el.clientLeft && el.nodeName!="TABLE") 
        { 
          left += el.clientLeft;
        }
        top += o.offsetTop;
        if (el.clientTop && el.nodeName!="TABLE") 
        {
          top += el.clientTop;
        }
        o = el;
        if (o.offsetParent==null) 
        {
          if (o.offsetLeft) 
          {
            left += o.offsetLeft;
          }
          if (o.offsetTop) 
          {
            top += o.offsetTop;
          }
        }
        offsetParent = o.offsetParent;
      }
    }
    
  
    if (originalObject.offsetWidth) 
    {
      width = originalObject.offsetWidth;
    }
    if (originalObject.offsetHeight) 
    {
      height = originalObject.offsetHeight;
    }
    
    return {'left':left, 'top':top, 'width':width, 'height':height};

 };
