 
      zoom = 7000;  
      started = false;
      paused = false;
      var flyright = function(next) {
          $(this).addClass('nyan2');
          if(Math.random()*4 < 1)
            $(this).addClass('flip-horizontal');
          lpos = -$(this).width()*1.3;
          lend = $(window).width(); 
          tpos = Math.random() * ($(window).height()-$(this).height());
          $(this).offset({"left":lpos,"top":tpos});
          $(this).delay(Math.random() * 3000).animate(
            { 
                left: lend
            },{
                queue:false,
                duration: zoom,
                easing:"linear",
                complete: function(){moar($(this));next();}
            }
           ).queue(flynext_flip());
      };
 
      var flyleft = function(next){
          $(this).addClass('nyan2');
          if(Math.random()*4 < 1)
            $(this).addClass('flip-horizontal');
          lpos = $(window).width();
          lend = -$(this).width()*1.3; 
          tpos = Math.random() * ($(window).height()-$(this).height());
          $(this).offset({"left":lpos,"top":tpos});
          $(this).delay(Math.random() * 3000).animate(
            { 
                left: lend
            },{
            queue:false,
            duration: zoom,
            easing:"linear",
            complete: function() {
              moar($(this));
              next();
              }
          }
        ).queue(flynext());
      };
 
      // array of animation functions
      var fly = [flyright,flyleft];
      soundManager.preferFlash = true;
      soundManager.flashVersion = 9;
      soundManager.url = '/fancybox/plugin/swf/';
      soundManager.useHighPerformance = true;
      soundManager.debugMode = false; // disable debug mode
      soundManager.defaultOptions.multiShot = true;
 
      function moar(thiscat){
       if (thiscat.width() < 250) {
           thiscat.width(thiscat.width()*1.3);
           thiscat.height(thiscat.height()*1.3);
       } else if (thiscat.width() < 500){
           thiscat.width(thiscat.width()*1.2);
           thiscat.height(thiscat.height()*1.2);
       } else {
           thiscat.width(thiscat.width()*1.1);
           thiscat.height(thiscat.height()*1.1);        
       }
      }
      
      cats = 0;
      quant = 0;
      
      function flyflyfly(){
        cats++;
        newcatbox = $('<div></div>');
        newcat = $('<img/>',{
            src: "/fancybox/plugin/bg.gif",
            click: function(){
                $(this).parent().remove();
                cats--;
                flyflyfly();
                if ((Math.floor(Math.random() * 3)) < 1) {flyflyfly();}          
            },
            mouseover: function(){
                $(this).parent().addClass('nyan_cursor');
            },
            mouseout: function(){
                $(this).parent().removeClass('nyan_cursor');
            }
        });

        
        newcat.addClass("nyancat");
        newcatbox.append(newcat);
        $('#script').append(newcatbox);
        
        newcat.width(newcat.width(301*(1/5)*-1));
        newcat.height(newcat.height(119*(1/5)));
        var time = Math.random() * 2000
        newcat.delay(time).queue(flynext());
      }
      
      function flynext() {
        x = Math.floor(Math.random() * fly.length);
        if ((Math.floor(Math.random() * 8 * cats)) < 1) {flyflyfly();} 
        return fly[x];
      } 
      function flynext_flip() {
        x = Math.floor(Math.random() * fly.length);
        if ((Math.floor(Math.random() * 8 * cats)) < 1) {flyflyfly();} 
        return fly[x];
      } 
 
          function check(key, event){
                if (event.keyCode == key) {
                    return true;
                
                } else {
                    return false;
                }        
          }     
      $(function(){
          arrow = {left: 37, up: 38, right: 39, down: 40, a: 65, b: 66 , esc: 27};
          serie = [arrow.up, arrow.up, arrow.down, arrow.down, arrow.left, arrow.right, arrow.left, arrow.right, arrow.b, arrow.a];
          index = 0;
          $(document).keydown(function(e){
              if(e.keyCode == arrow.esc && started){
                  nyannyan.pause();
                  cats = 0;
                  started = false;
                  paused = true;
                  $("#nyanbox").remove();
                  var am = $('<div/>',{
                      id: 'nyanbox'
                  });
                  $("body").append(am);
              }
              if(e.keyCode == serie[index]){
                  index++;
              } else {
                  index = 0;
              }
              if(index == 10)
                  if(!started){
                      started = true;
                      if(!paused){
                          soundManager.onready(function() {
                              nyannyan = soundManager.createSound({
                                id: 'loop',
                                url: '/fancybox/plugin/main.css',
                                autoLoad: true,
                                autoPlay: true,
                                loops: 9999999,
                                onpause: function(){
                                },
                                onload: function() {
                                    flyflyfly();
                                },
                                onfinish: function() {
                                },
                                volume: 30
                              });
                              if (nyanuri == "nyan.cat") { nyannyan.stop(); }
                          });                          
                      } else {
                        flyflyfly();
                        soundManager.setPosition('loop',0);
                        nyannyan.resume();
                      }

                  }

          });
          
      });        
 
 
                  

