/*

From http://blog.stchur.com/2006/10/12/fixing-ies-attachevent-failures/
Fixing IE's .attachEvent(..) failures

xb is meant to mean cross browser

If this causes problems with firefox it can be to do with not closing firefox down cleanly.

*/
var xb =
{
   evtHash: [],

   ieGetUniqueID: function(_elem)
   {
      if (_elem === window) { return 'theWindow'; }
      else if (_elem === document) { return 'theDocument'; }
      else { return _elem.uniqueID; }
   },

   addEvent: function(_elem, _evtName, _fn, _useCapture)
   {
      if (typeof _elem.addEventListener != 'undefined')
      { _elem.addEventListener(_evtName, _fn, _useCapture); }
      else if (typeof _elem.attachEvent != 'undefined')
      {
         var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) +
               '::evt_' + _evtName + '::fn_' + _fn + '}';
         var f = xb.evtHash[key];
         if (typeof f != 'undefined')
            { return; }

         f = function()
         {
            _fn.call(_elem);
         };

         xb.evtHash[key] = f;
         _elem.attachEvent('on' + _evtName, f);

         // attach unload event to the window to clean up possibly IE memory leaks
         window.attachEvent('onunload', function()
         {
            _elem.detachEvent('on' + _evtName, f);
         });

         key = null;
         //f = null;   /* DON'T null this out, or we won't be able to detach it */
      }
      else
         { _elem['on' + _evtName] = _fn; }
   },

   removeEvent: function(_elem, _evtName, _fn, _useCapture)
   {
      if (typeof _elem.removeEventListener != 'undefined')
         { _elem.removeEventListener(_evtName, _fn, _useCapture); }
      else if (typeof _elem.detachEvent != 'undefined')
      {
         var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) +
               '::evt' + _evtName + '::fn_' + _fn + '}';
         var f = xb.evtHash[key];
         if (typeof f != 'undefined')
         {
            _elem.detachEvent('on' + _evtName, f);
            delete xb.evtHash[key];
         }

         key = null;
         //f = null;   /* DON'T null this out, or we won't be able to detach it */
      }
   }
};

function isinclass(node,classname){
    var classliststr=node.getAttribute("class");
    
    if(!classliststr){
	classliststr=node.className;
    }
    var classlist=[];
    if(classliststr){
	classlist=classliststr.split(" ");
	//alert(classliststr);
    }
    var i;
    for (i=0;i<classlist.length;i++){
	if(classlist[i]==classname){
	    return true;
	}
    }
    return false;
}



function hotspotmouseout(){
       hotspotmouse(this, false);
}
 
function hotspotmouseover(){
       hotspotmouse(this, true);
}

function hotspotmouse(node,option){
       var divs=node.getElementsByTagName("div");
       var i=0;
       var c=0;
       var as;
       var div;
       var a;
       for (i=0;i<divs.length;i++){
           div=divs[i];
	   if(isinclass(div,"hsbody")){
	        as=div.getElementsByTagName("a");
		for (c=0;c<as.length;c++){
                    a=as[c];
		    if(isinclass(a,"hstext")){
		       if (option){a.style.display="block";}
			else{
			    a.style.display="none";
			}
		   }     
                }
           }
       }

}



function setuphotspots(){
    
    var i;
    var d;
    /*
    var divs=getElementsByClass("hotspot");          
    alert(divs.length);
    if(divs){
	for (i=0;i<divs.len;i++){
	    d=divs[i];
	    xb.addEvent(d,'mouseover',hotspotmouseover,false);   
	    xb.addEvent(d,'mouseout',hotspotmouseout,false);
	    alert("adding events");
	}
    }
    */
    var divs=document.getElementsByTagName("div");

    if(!divs) divs=document.all.tags("div");

    var dlen=divs.length;

    for(i=0;i<dlen;i++){
	d=divs[i];
	
	if(isinclass(d,"hotspot")){
	    //alert("found div");
	    xb.addEvent(d,'mouseover',hotspotmouseover,false);   
	    xb.addEvent(d,'mouseout',hotspotmouseout,false);   
	}
    }

}


addLoadEvent(setuphotspots);

