function setFontSize () {
  window.addEvent('domready', function() {
  	// load the font-size cookie if it exists and change body font
  	var start = parseInt(Cookie.read('fontsize'));
  	
  	if ($type(start) != 'number') { start = 11; Cookie.write('fontsize', start); }
  	
  	$(document.body).setStyle('font-size', start + 'px');

  	// Bind buttons
    $('font-down').addEvent('click', function() {
      var size = parseInt(Cookie.read('fontsize')); size--;
      Cookie.write('fontsize', size);
      $(document.body).setStyle('font-size', size + 'px');
      return false;
    });

    $('font-up').addEvent('click', function() {
      var size = parseInt(Cookie.read('fontsize')); size++;
      Cookie.write('fontsize', size);
      $(document.body).setStyle('font-size', size + 'px');
      return false;
    });
  });
}

function printButton () {
  window.addEvent('domready', function() {
    var print = $('print');
    if (print) {
      print.addEvent('click', function() {
        window.print();
        return false;
      });
      print.setStyle('cursor', 'pointer');
    }
  });
}

function sendToFriend () {
  window.addEvent('domready', function() {
    var mail = $('mail');
    if (mail) {
      mail.addEvent('click', function(event) {
        Mediabox.open('/mails', '', '250 220');
        event.stop();
      });
      mail.setStyle('cursor', 'pointer');
    }
  });
}

function enableAutocomplete () {
  window.addEvent('domready', function() {
    new Autocompleter.Request.JSON($('words'), '/search/ajax/?authenticity_token=' + encodeURIComponent($('token').get('value')));
  });
}

function rotateInfo () {
  window.addEvent('domready', function() {
    var infos = $$('.a-venir > div');
    
    if (infos.length > 1) {
      // wait 15 sec and rotate
      setTimeout("_rotate()",15000);
    }
    else {
      return false;
    }
  });
}

function _rotate () {
  // Fade out current info
  current_info = $$('.a-venir > div.current')[0];
  current_info.set('tween', {
 	  onComplete: function(e) {
 	    // Unset current set of div
 		  current_info.setStyle('display', 'none');
 		  current_info.removeClass('current');
 		  
      // Go to next info or back to first
      var next_info = current_info.getNext('div') || $$('.a-venir > div')[0];
      
      // Fade in new info
      next_info.set('tween', {
     	  onComplete: function(e) {
     		  next_info.setStyle('display', 'block');
     		  next_info.addClass('current');
     		  setTimeout("_rotate()",15000);
     		}
     	});
      next_info.tween('opacity', 1.0);
 		}
 	});
  current_info.tween('opacity', 0.0);
}

function externalLinks () {
  window.addEvent('domready', function() {
    $$('.external').addEvent('click', function(event) {
      var target = event.target;
      window.open(target.getProperty('href')); 
      event.stop();
    });
  });
}