/**
 * MMSlide
 *
 * Requires MooTools.js
 * @author Matthew Langtree - 2008-09-26
 *
 **/


var current_pos = 0;
var scroll = false;

var carousel = {

  moveTab : function()
  {
    pos = carousel.nextTabId();
    scroll.toElement($(carousel.currentTabId(pos)).id);
  },
  nextTabId : function()
  {
    var frameCount = $$('#panorama .frame').length;
    if(current_pos >= frameCount){
      current_pos = 1;
    }
    else
      current_pos = current_pos + 1;
    return current_pos;
  },
  currentTabId : function(tabNumber)
  {
    return 'frame'+tabNumber;
  },
  init : function()
  {
     scroll = new Fx.Scroll('panorama', {
    	wait: false,
    	duration: 0,
    	offset: {'x': 0, 'y': -0 },
    	transition: Fx.Transitions.Quad.easeInOut
    });
    var frames = $$('#panorama .frame');
  	scroll.toElement(frames[0].id);
    // Automatic Scrolling
    // carousel.moveTab.periodical(3000);
    
    var panoramaLinks = $$('.poster-choices a');
    
    panoramaLinks.each(function(section , i) {

    	if(i < frames.length){

    		section.addEvent('click', function(event){
    			event = new Event(event).stop();
    			section.blur();
    			scroll.toElement(frames[i].id);
    			panoramaLinks[current_pos].removeClass('active');
    			section.addClass('active');
    			current_pos = i;
    		});
    	}
    	});
    
  }
}

window.addEvent('domready', carousel.init);

