/*
insert.js 
(c) Ing. Jan Malý, 2008
It is forbidden to copy and (or) publish any parts of this code withnout my permission!
*/ 

function activateElem(t) {
  if(t.className != 'men-active') {
    // change class
    t.className = 'men-active';
    // switch image
    if(t.childNodes[0].childNodes[0].nodeName == "IMG") {
      var p = t.childNodes[0].childNodes[0].src;
      reg = /color\=[0-9]+/;
      p = p.replace(reg, 'color='+hoversActiveC);
      // preload
      var n = new Image();
      n.src = p;
      checkLoaded(t.childNodes[0].childNodes[0], n, true);       
    }
  } 
}

function deactivateElem(t) {
  if(t.className != 'men') {
    // change class
    t.className = 'men';
    // switch image
    if(t.childNodes[0].childNodes[0].nodeName == "IMG") {
      var p = t.childNodes[0].childNodes[0].src;
      reg = /color\=[0-9]+/;
      p = p.replace(reg, 'color='+hoversInactiveC);
      // preload
      var n = new Image();
      n.src = p;
      checkLoaded(t.childNodes[0].childNodes[0], n, false);
    }
  } 
}

// waits for n to be loaded
// if loaded, replaces o's src with n
// v true - active requested, false - inactive
function checkLoaded(o,n,v)
{
     if (n.complete)
     {
       var s = o.parentNode.parentNode.className;
       if((v && s == "men-active") || (!v && s == "men")) {
          o.src = n.src;   
       }
       return;
                 
     } else {
       setTimeout(function(){checkLoaded(o,n,v)}, 20);
     }
}

