Andrew = {
  
  slide: 'off',

  showGalleries: function() {
    var fxChain = new Chain();
    $each(
      $$('#gallery_items .item img'),
      function(item) {
      
        fxChain.chain(
          function() {
            fx = new Fx.Morph(
              item, 
              {
                duration: 100, 
                transition: Fx.Transitions.Sine.easeOut,
                onComplete: function() {
                  fxChain.callChain();
                  if ( $chk(item) ) {
                    $(item).getParent().getNext('span').style.visibility = 'visible';
                  }
                }
              }
            );
            fx.start({
              'width': 190,
              'height': 190
            });
          }
        );
        
      }
    );
    fxChain.callChain();
  },

  showGallery: function() {
    var fxChain = new Chain();
    $each(
      $$('#gallery_items .item img'),
      function(item) {
      
        fxChain.chain(
          function() {
            fx = new Fx.Morph(
              item, 
              {
                duration: 100, 
                transition: Fx.Transitions.Sine.easeOut,
                onComplete: function() {
                  fxChain.callChain();
                }
              }
            );
            fx.start({
              'width': 132,
              'height': 132
            });
          }
        );
        
      }
    );
    fxChain.callChain();
  },
  
  swapImage: function(container, src) {
    var fx = new Fx.Morph(
      container, 
      {
        duration: 300, 
        transition: Fx.Transitions.Sine.easeOut,
        onComplete: function() {
          $(container).src = src;
          var fx = new Fx.Morph(
            container, 
            {
              duration: 300, 
              transition: Fx.Transitions.Sine.easeOut
            }
          );
          fx.start({
            'opacity': 1
          });
        }
      }
    );
    fx.start({
      'opacity': 0
    });
  },
  
  openImage: function(item) {
    $('showimage').src = item;
    $('c_showimage').style.display = 'block';
    var fx = new Fx.Morph(
      'c_showimage', 
      {
        duration: 300, 
        transition: Fx.Transitions.Sine.easeOut
      }
    );
    fx.start({
      'opacity': 1
    });
  },
  
  closeImage: function() {
    var fx = new Fx.Morph(
      'c_showimage', 
      {
        duration: 300, 
        transition: Fx.Transitions.Sine.easeOut,
        onSuccess: function() {
          $('imagestore/1/680/0/upload/{$item->image}').style.display = 'none';
        }
      }
    );
    fx.start({
      'opacity': 0
    });
  },
  
  slideFlyers: function() {
    var slide = function(){ 
      
      Andrew.slide = 'on';
      
      if ( $chk( $('flyers_container') ) ) {
      
        var fxChain = new Chain();
          
        $each(
        
          $$('#flyers_container img'),
          function(item) {
            fxChain.chain(
              function() {
                fx = new Fx.Morph(
                  item, 
                  {
                    duration: 200, 
                    transition: Fx.Transitions.Sine.easeOut,
                    onComplete: function() {
                      $(item).style.marginLeft = '180px';
                      fxChain.callChain();
                    }
                  }
                );
                fx.start({
                  'margin-left': -180
                });
              }
            );
              
          }
            
        );
        
        $('flyers_container').getLast().style.marginLeft = '180px';
        $('flyers_container').getLast().clone().inject( $('flyers_container'), 'top' );
        $('flyers_container').getLast().destroy();
        
        $each(
        
          $$('#flyers_container img'),
          function(item) {
          
            fxChain.chain(
              function() {
                fx = new Fx.Morph(
                  item, 
                  {
                    duration: 200, 
                    transition: Fx.Transitions.Sine.easeOut,
                    onComplete: function() {
                      fxChain.callChain();
                    }
                  }
                );
                fx.start({
                  'margin-left': 0
                });
              }
            );
          }
          
        );
        
        fxChain.callChain();
  
      }

    };
    if (Andrew.slide == 'off')
      slide.periodical(7000);
  }

}

function openPage(page) {
  new Request.HTML(
    {
      url: page,
      method: 'get',
      onSuccess: function(responseTree, responseElements, responseHTML) {
        $('center').set('text', '');
        $('center').adopt(responseTree);
        $each( 
          $$('#center *[onclick]'),
          function(item) {
            $(item).addEvent(
              'click',
              function() {
                eval(this.onclick);
              }
            );
          }
        );
      },
      evalResponse: true,
      evalScripts: true
    }
  ).send();
}