$(document).ready(function(){
  
  $(".hide").hide();

  $('.view').click(function(){
    $(".hide").hide();
    $('.box_' + this.id).show();
  });
  
  $("#email").keyup(function(){
    var email = $("#email").val();
    if(email != 0)
    {
      if(isValidEmailAddress(email))
      {
      $("#validEmail").css({ "background-image": "url('img/validyes.png')" });
      }
      else
      {
      $("#validEmail").css({ "background-image": "url('img/validno.png')" });
      }
    }
    else
    {
      $("#validEmail").css({ "background-image": "none" });
    }
  });

  $('#send').click(function() {
    var email = $("#email").val();
    if(isValidEmailAddress(email)){
      $.ajax({
        type: 'POST',
        data: decodeURIComponent($('#subscribeform').serialize()+'&emailconfirm='+email),
        url: 'http://mailinglist.2gtl.net/?p=subscribe&id=8',
        success: function(){
          $('#box_newsletter').text('Your newsletter subscription has been registered,  thank you for joining our mailing list.')
        }
      });
    }
    else
    {
      alert('Invalid email address, please check your email.');
    }
    event.preventDefault();
  });
});

function isValidEmailAddress(emailAddress) {
  var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  return pattern.test(emailAddress);
}

function ShowHide_concerts(){
$("#previous_concerts").animate({"height": "toggle"}, { duration: 1000 });
}

function ShowHide_comments(id){
$("#comment_block_"+id).animate({"height": "toggle"}, { duration: 1000 });
}

function onYouTubePlayerReady(playerId) { 
  ytplayer = document.getElementById("video_overlay"); 
  ytplayer.setVolume(100); 
}
