// Utility function that SHOULD have been included in the DOM.

function getElementsByClassName(searchClass, tag, node) {

  var classElements = new Array();

  node = (node) ? node : document;

  tag = (tag) ? 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;

}



// Our function to "fix" AdEngage's ads.

function fixAE() {

  var myDest = '';

  var myArray;

  var parent;



  // Make the picture clickable to the same destination as the title:

  parent = document.getElementById("ae_image");

  if (parent) {

    myArray = getElementsByClassName("ae_title_horiz", "a", parent);	// Find the AE title.

    //alert(myArray[0].href);	
	
    if (myArray.length > 0) { myDest = myArray[0].href; }				// Get its destination.

    myArray = getElementsByClassName("ae_thumb", "a", parent);			// Find our picture's anchor

    if (myArray.length > 0) { myArray[0].href = myDest; }				// Give it that same destination.

  }

}

