/* addEvent handler for IE and other browsers */
function addEvent(elm, evType, fn, useCapture) 
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
}

/* create appropriate mouseover with timeout for links */
// global variable to reset tb_mo_timeout
function AnchorMouseOver() {
   var timeout = typeof(tb_mo_timeout) != "undefined" ? tb_mo_timeout : 1500;
   var links = document.links;
  for (var i = 0; i < links.length; i++) {
    var link = links[i];
    if (link.className.search("thickbox") > -1 && link.className.search("tb_mo") > -1) {
      var func = new Function('tb_show(' + '"' + link.title + '"' + ', "' + link.href + '", false);'); 
      link.old_mover_func = link.onmouseover ? link.onmouseover : new Function('return;');
      link.old_mout_func = link.onmouseout ? link.onmouseout : new Function('return;');
      link.mo_func = func;
      link.onmouseover = new Function('this["old_mover_func"](); tb_am = setTimeout(this.mo_func,' + timeout + ')');
      link.onmouseout = function() {
        this["old_mout_func"]();
        clearTimeout(tb_am);
      }
    }
  }
}

preloaded_img = new Array();
function PreloadImages(imageArray) {
  if (document.images && (typeof(imageArray) != "undefined") && imageArray) {
    for (var i = 0; i < imageArray.length; i++) {
      var imagex = document.createElement('img');
      imagex.setAttribute('src', imageArray[i]);
      preloaded_img.push(imagex);
    }
  }
}

// returns if image specified by name image_src is loaded
function IsImageLoaded(image_src) {
  var image_temp = new Image();
  image_temp.src = image_src;
  if ((typeof image_temp.naturalWidth) != "undefined") {
      // for firefox
    if (image_temp.naturalWidth > 20) return true;
    else return false;
  } else {
      // for IE
      return image_temp.complete;
  }
}

function parseQueryString(key) {
  if (location.search && location.search.length > 1) {
     var key_pair = location.search.substring(1).split("&");    
     for (var i=0; i< key_pair.length; i++) {
       key_pair[i] = key_pair[i].split("=", 2);

       if ((key_pair[i].length > 1) && (key_pair[i][0] == key)) {
          return key_pair[i][1];
       }
     }
  }
  return null;
}

function writeLog(str)
{
  if (typeof(loggingOn) != "undefined" && loggingOn) {
     console.log(str);
  }
}
addEvent(window, 'load', AnchorMouseOver);

