  function show(theName) {
    obj = document.getElementById(theName);
    obj.className = 'show';
  }

  function hide(theName) {
    obj = document.getElementById(theName);
    obj.className = 'hide';
  }

  function swap_button(theName) {
    obj = document.getElementById(theName);
    if (obj.className == 'show') {
        hide(theName);
        show(theName + '_act');
    } else {
        hide(theName + '_act');
        show(theName);
    }
  }
  
  function show_bg(theName) {
    obj = document.getElementById(theName);
    obj.style.backgroundPosition = '0px 20px';
  }
  
  function hide_bg(theName) {
    obj = document.getElementById(theName);
    obj.style.backgroundPosition = '0px 0px';
  }
  
  function viewport() {
    test = $(document.body).getSize();
    sw = parseInt(test.x);
    sh = parseInt(test.y);
    return {width: sw , height: sh}
  }
  
  function hidePop() {
    fadeOut('wipe');
    fadeOut('pop');
  }

  
  function fadeIn(el) {
    if (el == 'wipe') toOp = .5;
    else toOp = 1;
    $(el).setStyle('opacity',0);
    $(el).show();
    var fx1 = new Fx.Tween($(el),{
        duration: 500,
        onComplete: function(){ 
          if (window.Browser.Engine.name == 'trident' && el != 'wipe') $(el).style.removeAttribute('filter');
        }
    });
    fx1.start('opacity',0,toOp);
  }
  
  function fadeOut(el) {
    var fx1 = new Fx.Tween($(el),{
        duration: 500,
        onComplete: function(){ 
          $(el).hide();
        }
    });
    if (el == 'wipe') toOp = .5;
    else toOp = 1;
    fx1.start('opacity',toOp,0);
  }
  
  function showPop(id,ty,fid) {
    if ($('wipe').getStyle('display') == 'none') {
      vp = viewport();
      sp = $(document.body).getScroll();
      $('wipe').setStyles({
        'opacity' : '0.5',
        'height' : vp.height + sp.y + 'px'
      });
      fadeIn('wipe');
    }
    var req = new Request({
      method: 'get',
      url: 'photo.php?id=' + id + '&fid=' + fid + '&t=' + ty,
      onComplete: function(data) {
        if (data) {
          $('popContent').innerHTML = parseScript(data);
            vp = viewport();
            fadeIn('pop');
            oh = $('pop').offsetHeight;
            ow = $('pop').offsetWidth;
            sp = $(document.body).getScroll();
            np = Math.max(0,Math.round((vp.height - oh) / 2) + sp.y);
            $('pop').setStyles({
              'left' : Math.round((vp.width - ow) / 2) + 'px',
              'top' : np + 'px'
            });
        }
      }
    }).send();
  }
  
  function refreshPop(id,fy,fid) {
    //fadeOut('pop');
    var req = new Request({
      method: 'get',
      url: 'photo.php?id=' + id + '&fid=' + fid + '&t=' + ty,
      onComplete: function(data) {
        if (data) {
          $('popContent').innerHTML = parseScript(data);
            vp = viewport();
            fadeIn('pop');
            oh = $('pop').offsetHeight;
            ow = $('pop').offsetWidth;
            sp = $(document.body).getScroll();
            np = Math.max(0,Math.round((vp.height - oh) / 2) + sp.y);
            $('pop').setStyles({
              'left' : Math.round((vp.width - ow) / 2) + 'px',
              'top' : np + 'px'
            });
        }
      }
    }).send();
    
  }
