document.observe("dom:loaded", function() {
  /*
   * slideshow
   */ 
  Effect.Transitions.easeInOutCubic=function(pos){if((pos/=0.5)<1)return 0.5*Math.pow(pos,3);return 0.5*(Math.pow((pos-2),3)+2);}
	
  var scroll = {
    'isAnimating':false,
    'getNewOffset':function(modifier){
      if( $('students').positionedOffset().left == 0 && modifier == 1){
        return 0;
      }else if( ($('students').positionedOffset().left + (modifier * 150)) == -($('students').getDimensions().width) && modifier == -1 ){
        return 0;
      }
      return (modifier * 150);
    },
    'animateSlide':function(modifier){
      scroll.isAnimating = true;
      new Effect.Move($('students'), {
        x: scroll.getNewOffset(modifier),
        y: 0,
        duration: 0.5,
        fps: 100,
        transition: Effect.Transitions.easeInOutCubic,
        afterFinish: function(){
          scroll.isAnimating = false;
        }
      });
    },
    'handleNavigation':function(anchor){
      anchor.observe('click', function(event){
        if( scroll.isAnimating == false ){
          var element = event.element();
          if( element.hasClassName('next') ){
            scroll.animateSlide(-1);
          }else if( element.hasClassName('prev') ){
            scroll.animateSlide(1);
          };
        };
        event.stop();
      });
    }
  };
  
  // setup...
  if ($('scroll')) {
    $('scroll').relativize();
  }
  
  // previous & next handling
  $$('#scroll .next', '#scroll .prev').each(function(anchor){
    scroll.handleNavigation(anchor);
  });
}); 
  

Event.observe(document, 'dom:loaded', function() {
  
  //popups
  $$('.external').each(function (e) {
    e.observe('click', openPopup);
  });
  
  // print this page
  if ($('aside-print')) {
    $('aside-print').observe('click', function(event) {
    window.print();
    Event.stop(event);
    });
  }
  
  attachBehaviours();
  
});


function openPopup(event)
{
  var width = 580;
  var height = 700;
  // var left = (screen.width - width)/2;
  // var top = (screen.height - height)/2;
  newwin = window.open(this.href, "acmpopup", "status=no,toolbar=no,resizable=yes,scrollbars=0,width="+width+",height="+height);
  if (window.focus) newwin.focus();
  event.stop();
}


function showPanelTab(event)
{
  $$('#tertiary li a').each( function (elem) {
    elem.removeClassName('on');
  });
  
  this.addClassName('on');
  
  $$('.tab-content').each(function (elem) {
    elem.hide();
  });
  
  $(this.id.split('-').last()).show();
}

function attachBehaviours()
{
	var timetables = $$('#timetable-expand li');

	if( timetables.length >= 1 ){
		timetables.each(function(timetable){
			timetable.select('a.expand').each(function(timetableExpand){
				timetableExpand.observe('click', function(event) {
					if( ! timetable.hasClassName('open') ){
						$$('#timetable-expand li.open .expand-content').each(function(timetableContent){
							timetableContent.hide();
							timetableContent.up('li').removeClassName('open').addClassName('closed');
						});
					};
					if( timetable.hasClassName('closed') ){
						timetableExpand.next('.expand-content').show();
						timetable.removeClassName('closed').addClassName('open');
					}else if( timetable.hasClassName('open') ){
						timetableExpand.next('.expand-content').hide();
						timetable.removeClassName('open').addClassName('closed');
					};
					Event.stop(event);
				});
			});
			timetable.addClassName('closed');
			timetable.select('.expand-content').each(function(timetableContent){ timetableContent.hide(); });
		});
	};	
}

function pageTrack(service, category, info)
{
	if(pageTracker._trackEvent) {
		pageTracker._trackEvent(service, category, info);
	}
}

