﻿prepPageForInlinePopUps();
            
function getElementsByClass(searchClass,node,tag)
{
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    
   
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function triggerHover(trigger)
{
    //The problem here is that IE 6 does some funky stuff with images.  It will pass
    //the image in as the triggering element if it is wrapped inside something
    //(currently only verfied for a tags).  This will cause the nextObject to fail
    //This means we need to check to see if show is null, if it is, then check the
    //parent's nextObject

    var show = nextObject(trigger);
    if (show == null) {
        show = nextObject(trigger.parentNode);
    }

    show.className = show.className + ' ShowInlinePopUp';
}

function triggerHide(trigger)
{
    //Same problem exists for hide as for show
    var hide = nextObject(trigger);
    if (hide == null) {
        hide = nextObject(trigger.parentNode);
    }

    hide.className = hide.className.replace(/ShowInlinePopUp/, "");   
}

function nextObject(baseObject) {
    var n = baseObject;
    do n = n.nextSibling;
 
    while (n && n.nodeType != 1);
    return n;
}


//Prep the page to have the pop ups appear
function prepPageForInlinePopUps() 
{
  
    
    //Get all the triggers on the page
    var popLinks = getElementsByClass('InlinePopUpTrigger');

    //loop through the triggers and do what we want to them
    for (i=0; i < popLinks.length; i++) {
      
        //alert(popLinks[i].id);
        if (window.addEventListener)
        { 
            //Modern non-ie browsers
            triggerHide(popLinks);
            popLinks[i].addEventListener("mouseover", function (event) { triggerHover(this); }, false);
            popLinks[i].addEventListener("mouseout", function (event) { triggerHide(this); }, false);
            
        } else if (window.attachEvent) {
            //IE
           
            popLinks[i].attachEvent("onmouseover", function (event) {triggerHover(window.event.srcElement); });
            popLinks[i].attachEvent("onmouseout", function (event) { triggerHide(window.event.srcElement); });
        } else {
            //Older browsers
            popLinks[i].onmouseover = function (event) { triggerHover(this); };
            popLinks[i].onmouseout = function (event) { triggerHide(this); };
        }

    }
} // End prepPageForInlinePopUps

