$(document).ready(function()
{
  function addEnlargement(sthis, simg, percent)
  {
    var
      //sthis    = $(this),
      //simg     = sthis.find("img:first-child"),
      top      = parseInt(simg.css("top").replace(/\D/, "")),
      left     = parseInt(simg.css("left").replace(/\D/, "")),
      width    = parseInt(simg.css("width").replace(/\D/, "")),
      height   = parseInt(simg.css("height").replace(/\D/, "")),
      anistate = 0,
      delta    = 0,
      maxstate = 10,
      //percent  = 90,
      delay    = 25,
      allowout = true
      ;
    
    if (sthis.attr("class") == "active")
    {
      delta = 1;
      allowout = false;
    }
    
    sthis.hover(
      function()
      {
        delta = 1;
      },
      function()
      {
        if (allowout)
        {
          delta = -1;
        }
      }
    );
    
    setInterval(
      function()
      {
        if (delta != 0)
        {
          anistate += delta;
          
          if ((anistate >= maxstate) || (anistate <= 0))
          {
            delta = 0;
            anistate = Math.min(maxstate, Math.max(0, anistate));
          }

          var
            newscale = (1 + percent * anistate / maxstate / 100),
            newheight = height * newscale,
            newwidth  = width  * newscale;
          
          //opera.postError("newscale=" + newscale + " hewheight=" + newheight + " newwidth=" + newwidth);
          
          simg
            .css("top"   , Math.round(top - (newheight - height) / 2))
            .css("left"  , Math.round(left - (newwidth - width) / 2))
            .css("height", Math.round(newheight))
            .css("width" , Math.round(newwidth))
            ;
        }
      },
      delay
    );
  }
  
  $("#swch a").each(function()
  {
    var sthis = $(this);
    addEnlargement(sthis, sthis.find("img:first-child"), 90);
  });

  $("a#logo").each(function()
  {
    var sthis = $(this);
    addEnlargement(sthis, sthis.find("img:first-child"), 10);
  });
});

