
$(function(){ // Start jQuery ondomready

// Change the current site
$('#language-selector').change(function() {
  el = $('#language-selector option:selected')[0];
  document.location.href = 'http://' + $(el).val();
})

// Print button
$('#tools .print').show()
.find('a').click(function(){
  window.print();
  return false;
})

// Increase text size
$('#tools .size').show();
if($.cookie('bigfont') == '1') {
  $('body').addClass('bigfont');
  $('#tools .size a span').text('\u2212');
}
$('#tools .size a').click(function(){
  if ($('body').hasClass('bigfont')) {
    $.cookie('bigfont', '0', {expires: 90, path: '/'});
    $('body').removeClass('bigfont');
    $(this).find('span').text('+');
  } else {
    $.cookie('bigfont', '1', {expires: 90, path: '/'});
    $('body').addClass('bigfont');
    $(this).find('span').text('\u2212');
  }
});

// Change the current site
$('#language-selector').change(function() {
  el = $('#language-selector option:selected')[0];
  document.location.href = 'http://' + $(el).val();
})

// Superfish dropdown
// (Without opacity fade-in as IE 6-8 doesn't handle it well.)
$('#nav-main').superfish({
  hoverClass: 'lvl1-hover',
  delay: 400,
  animation: {/*opacity: 'show',*/ height: 'show'},
  speed: 'fast',
  autoArrows: false,
  dropShadows: false
});

// Thin grey boxes: adjust background style automatically
$('.box-thingrey').each(function(){
  var box_height = $(this).innerHeight();
  if(box_height >= 350) {
    $(this).addClass('box-thingrey-tall');
  } else if (box_height >= 200) {
    $(this).addClass('box-thingrey-med');
  }
});

// Link on top-right of content boxes
$('.box-link-full').each(function(){
  var target = $(this).find('a.target').attr('href');
  if (target) {
    $(this).addClass('box-link-full-ok')
    .click(function(){window.location.href = target;})
  }
});

// HOME: cycle through diaporama
$('#diaporama').cycle({
  slideExpr: '.slide',
  timeout: 8000,
  pause: 1
});

// ARTICLES: put top illustration before title
$('#content-main > h1:first-child + .before-title').prependTo('#content-main');

// CENTERS: collapse HIFU center info
$('#centers-results li').removeClass('normal').addClass('collapsed');
$('#centers-results h2 a').click(function(){
  $(this).blur();
  var $li = $(this).closest('li');
  $li.toggleClass('open').toggleClass('collapsed');
  $li.siblings('.open').removeClass('open').addClass('collapsed');
  return false;
});
$('#centers-results .close').click(function(){
  $(this).parent().removeClass('open').addClass('collapsed');
  return false;
});

}) // End jQuery ondomready

