/**
 * Peppermoon JavaScript Controller
 * <http://www.peppermoon.fr/>
 * 
 * Romain Huet <http://romainhuet.com/>
 */

$(document).ready(function() {
  // Hide the purchase links and the country notice
  $('#album .links li').hide();
  $('.empty-notice').hide();
  $('.unavailable-notice').hide();
  
  // Handle the country selection
  $('.country-selection').change(function() {
    var id = '#' + $(this).parent().attr('id');
    $(id).find('.links li').hide();
    $(id).find('.empty-notice').hide();
    $(id).find('.unavailable-notice').hide();
    var country = $('.country-selection').val();
    switch (country) {
    case 'australia':
      $(id).find('.itunes').show();
      $(id).find('.cdbaby').show();
      break;
    case 'brazil':
      $(id).find('.nokiamusicstore').show();
      $(id).find('.cdbaby').show();
      break;
    case 'europe':
      $(id).find('.itunes').show();
      $(id).find('.amazon').show();
      $(id).find('.priceminister').show();
      break;
    case 'france-belgium':
      $(id).find('.amazon').show();
      $(id).find('.fnac').show();
      $(id).find('.priceminister').show();
      $(id).find('.itunes2').show();
      $(id).find('.virginmega').show();
      break;
    case 'japan':
    case 'switzerland':
      $(id).find('.itunes').show();
      $(id).find('.tba').show();
      break;
    case 'mexico':
    case 'south-africa':
      $(id).find('.nokiamusicstore').show();
      $(id).find('.cdbaby').show();
      break;
    case 'south-america':
      $(id).find('.cdbaby').show();
      break;
    case 'netherlands':
      $(id).find('.bol').show();
      $(id).find('.nlstore').show();
      $(id).find('.velvetmusic').show();
      $(id).find('.platomania').show();
      $(id).find('.itunes2').show();
      break;
    case 'singapore':
      $(id).find('.nokiamusicstore').show();
      $(id).find('.tba').show();
      break;
    case 'taiwan':
      $(id).find('.books').show();
      break;
    case 'usa-canada':
        $(id).find('.itunes').show();
        $(id).find('.amazonmp3').show();
        $(id).find('.cdbaby').show();
      break;
    case '':
      $(id).find('.empty-notice').show();
      break;
    default:
      $(id).find('.unavailable-notice').show();
    }
  })
  
  // Hide the timeline
  $('#timeline').hide();
  
  // Handle the click on "More" to display the timeline
  $('#timeline-toggle a').click(function() {
    if ($('#timeline').css('display') == 'none') {
      $(this).text('Read less...');
    } else {
      $(this).text('Read more...');
    }
    $('#timeline').slideToggle('slow');
    return false;
  });
  
  // Facebook widget
  FB.init("0490559909bc3c7c80209d215a11674a");
  
  // Twitter widget
  new TWTR.Widget({
    profile: true,
    id: 'twtr-profile-widget',
    loop: true,
    width: 300,
    height: 150,
    theme: {
      shell: {
        background: '#3D5176',
        color: '#FFFFFF'
      },
      tweets: {
        background: '#FFFFFF',
        color: '#6E4089',
        links: '#C52682'
      }
    }
  }).render().setProfile('peppermoonmusic').start();
});
