function switchImg(oldid, lid, sl, sn, si){
  var elo = document.getElementById(oldid);
  elo.className = 'img-inv';
  setTimeout('switchInfo(\''+sl+'\', \''+sn+'\', \''+si+'\')', 520);
  setTimeout('switchLink(\''+lid+'\')', 520);
}

function switchInfo(sl, sn, si) {
  document.getElementById('site-name').innerHTML = '<a href=\"'+sl+'\">'+sn+'</a>';
  document.getElementById('site-info').innerHTML = si;
}

function switchLink(lid) {
  var links = document.getElementById('main-img-box').getElementsByTagName('a');
  for (var i=0;i<links.length;i++) {
    if (links[i].id == lid) {
      links[i].className = 'img-vis';
    } else {
      links[i].className = 'img-inv';
    }
  }
}

function addEvent(elid, newid, key) {
  var el = document.getElementById(elid);
  el.onclick = function (ev) {
    xajax_loadImages(el.className, 'main-img-'+key, newid);
  }
}

function fadein(id, ln, s) {
  setTimeout('fade(\''+id+'\','+ln+','+s+')', 520);
}

function waitForFade(id) {
  document.getElementById(id).className = 'cover-vis';
  setTimeout('hideCover(\'cover\')', 1020);
}

function hideCover(id) {
  document.getElementById(id).className = 'cover-inv';
}

function $(v) { return(document.getElementById(v)); }
function $S(v) { return($(v).style); }
function uni(v,id,s,top) { var ob=$S(id),b=v/100; ob.opacity=b; ob.MozOpacity=b; ob.KhtmlOpacity=b; ob.filter="alpha(opacity="+v+")"; }
function zero(v) { v=parseInt(v); return(!isNaN(v)?v:0); }

function fade(id,ln,s) { 
  var top=zero(parseInt($S(id).top));
  function op(oStart,oEnd,ln) {
    var speed=Math.round(ln/100),timer=0;
    if(oStart>oEnd) { for(i=oStart; i>=oEnd; i--) { setTimeout("uni("+i+",'"+id+"','','"+(top--)+"')",timer*speed); timer++; } setTimeout("$S('"+id+"').display='none';",timer*speed); }
    else if(oStart<oEnd) { $S(id).display='block'; for(i=oStart; i<=oEnd; i++) { setTimeout("uni("+i+",'"+id+"','"+1+"','"+(top++)+"')",timer*speed); timer++; } }
  }
  if(s==1 || (!s && $S(id).opacity==0)) op(0,100,ln); else op(100,0,ln);
}