var carousel, active_link;
	 
function carouselInit() {
  carousel    = new UI.Carousel($$('#zoom_content .horizontal_carousel')[0], { scrollInc: 1 }),
  active_link = $$("#zoom_content .link1")[0];

  document.observe('carousel:scroll:started', function() {
    $$('.try_buy').invoke('hide');
  });

  document.observe('carousel:scroll:ended', function(event) {
    if (active_link) {
      active_link.removeClassName('active');
      active_link = null;
    }

    var active = carousel.currentIndex() + 1;
    
    if (active < 25)
      $$('#zoom_content .try_buy').invoke('hide');
    
    if (active >= 25) {
      
      $$('#zoom_content .try_buy').invoke('show');
    } else if (active >= 19)
      active = 19;
    else if (active >= 17)
      active = 17;
    else if (active >= 12)
      active = 12;
    else if (active >= 5)
      active = 5;
    else
      active = 1;

    var link = $$("#zoom_content .link" + active);
    if (link.length > 0) {
      link.invoke('addClassName', 'active');
      active_link = link[0];
    }
  });

  $$('#zoom_content .nav').invoke('observe', 'click', function(event) {
    var link = event.findElement('li');
    if (link) {
      var linkClasses = link.classNames().select(function(klass) {
        return (klass.substring(0, 4) == 'link');
      });
      carousel.scrollTo(parseInt(linkClasses[0].substring(4, linkClasses[0].length)) - 1);
    }
  });

	document.observe('keydown', function(event) {
	  if ((event.which == Event.KEY_UP) || (event.which == Event.KEY_LEFT)) {
	    carousel.scrollTo(carousel.currentIndex() - 1);
	    event.stop();
	  } else if ((event.which == Event.KEY_DOWN) || (event.which == Event.KEY_RIGHT)) {
	    carousel.scrollTo(carousel.currentIndex() + 1);
	    event.stop();
    }
	});
}

FancyZoomBox.directory = '/images/zoom';
$(document).observe('dom:loaded', function() {
										   
	new FancyZoom('status_toolbar_tour_link2', { width: 863, height: 515, after: function() {
	  carouselInit();
	}});
	new FancyZoom('status_toolbar_tour_link', { width: 863, height: 515, after: function() {
	  carouselInit();
	}});
});