var noHover = navigator.userAgent.match(/iPod|iPhone|iPad/i) ? true : false;
$(document).ready(function(){
  var $as = $('#mainImage a').css({position:'relative'}).each(function(){
    var $a = $(this);
    bgCss = $a.css('backgroundPosition') || ($a.css('backgroundPositionX') + ' ' + $a.css('backgroundPositionY'));
    bgCss = bgCss.replace(/%/g, 'px');
    var backgroundPos = bgCss.match(/(\-?([0-9]*)px) (\-?([0-9]*)px)/);
    var bPos = {
      x:parseInt(backgroundPos[1]),
      y:parseInt(backgroundPos[3])
    };

    var $off = $('<div />').addClass('off').css({
      position:'absolute',
      top:0,left:0,
      width:$a.width(),
      height:$a.height(),
      backgroundImage:$a.css('backgroundImage'),
      backgroundPosition:bPos.x + 'px ' + (bPos.y-(noHover ? $a.height() : 0)) + 'px',
      backgroundRepeat:$a.css('backgroundRepeat'),
      cursor:'pointer'
    });

    if (!noHover){
        var $over = $('<div />').addClass('over').css({
          position:'absolute',
          top:0,left:0,
          width:$a.width(),
          height:$a.height(),
          backgroundImage:$a.css('backgroundImage'),
          backgroundPosition:bPos.x + 'px ' + (bPos.y-$a.height()) + 'px',
          backgroundRepeat:$a.css('backgroundRepeat'),
          cursor:'pointer'
        }).hide();
    }

    $a.append($off).append($over);
  });

  if (!noHover){
    $as.hover(function(){
      $(this).find('.over').stop().fadeTo(400, 1);
    }, function(){
      $(this).find('.over').stop().fadeTo(400, 0);
    });
  }

});
