jQuery(document).ready(function(){

  jQuery.easing.custom = function (x, t, b, c, d) {
  	var s = 1; 
  	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  }
  
  //Status of default autoscroll setting
  var autoScroll = false;        
  
  //Select #flowplanes and make it scrollable. use circular and navigator plugins
  var api = jQuery('#flowpanes').scrollable({ 
  	circular: true, 
  	mousewheel: false, 
  	easing: 'custom', 
  	speed: 900 
  }).autoscroll({autoplay:false, interval:8000}).navigator({

  	// select #flowtabs to be used as navigator
  	navi: "#flowtabs",

  	// select A tags inside the navigator to work as items (not direct children)
  	naviItem: 'a',

  	// assign "current" class name for the active A tag inside navigator
  	activeClass: 'current',

  	// make browser's back button work
  	history: true,
	
  	api: true

  });


  //Changes the styles depending on the appropriate index of the display
  api.onSeek(function() {
	
  	var bulbNum = api.getIndex();

  	if(bulbNum == 0){
  		jQuery('#bulbs').addClass('bulb1');
  		jQuery('#bulbs').removeClass('bulb2');
  		jQuery('#bulbs').removeClass('bulb3');
  	}
  	if(bulbNum==1){
  		jQuery('#bulbs').addClass('bulb2');
  		jQuery('#bulbs').removeClass('bulb1');
  		jQuery('#bulbs').removeClass('bulb3');
  	}
  	if(bulbNum==2){
  		jQuery('#bulbs').addClass('bulb3');	
  		jQuery('#bulbs').removeClass('bulb1');
  		jQuery('#bulbs').removeClass('bulb2');	
  	}
  }); 
  
  //On click function for the play/pause button
  jQuery("#play-pause").mousedown( function(){
  
	  api.stop();
	  
	  //console.log(autoScroll);
	  //console.info("current position is: " + api.getIndex());
	  
    if(autoScroll == false) {
      autoScroll = true;
      jQuery('#play-pause a').addClass('paused');
      //api.autoscroll({autoplay: true});
	    api.play();
    } else if (autoScroll == true){
      autoScroll = false;
      jQuery('#play-pause a').removeClass('paused');
      //api.autoscroll({autoplay: false});
	    api.stop();
    }

  });
       
})
