$('document').ready(function(){
  $('#tellafriend').click(function(){
    $('body').append('<div class="background"></div>');
    $('.background').css('background','#000');
    $('.background').css('display','block');
    $('.background').css('position','absolute');
    $('.background').css('top',0);
    $('.background').css('left',0);
    $('.background').css('opacity',0);
    $('.background').css('height','100%');
    $('.background').css('width','100%');
    $('.background').css('z-index','10001');
    $('.background').fadeTo(500,0.8);

    $('body').append('<div class="tellafriend"></div>');
    $('.tellafriend').css('background', '#fff');
    $('.tellafriend').css('border', '3px solid #ff7200');
    $('.tellafriend').css('position', 'absolute');
    $('.tellafriend').css('display', 'block');
    $('.tellafriend').css('height', '240px');
    $('.tellafriend').css('width','380px');
    $('.tellafriend').css('top', '50%');
    $('.tellafriend').css('left', '50%');
    $('.tellafriend').css('opacity',0);
    $('.tellafriend').css('padding','5px');
    $('.tellafriend').css('margin-left', '-190px');
    $('.tellafriend').css('margin-top', '-120px');
    $('.tellafriend').css('z-index','10002');
    $('.tellafriend').fadeTo(500,1);
    $('.tellafriend').load('/tellafriend',{
    
      });
    return false;
  });

  $('#taf_submit').livequery('click',function (event) {
    var error = '';
    if( $('#your_email').val() == '')
      error = error + 'U heeft uw email adres niet ingevuld\n';
    if( $('#friend_email').val() == '')
      error = error + 'U heeft het email adres van uw vriend niet ingevuld\n';

    if (error != '')
    {
      alert( error );
    }
    else
    {
      $.post('/tellafriend/post',
      {
        url: window.location.href,
        your_name: $('#your_name').val(),
        your_email: $('#your_email').val(),
        friend_name: $('#friend_name').val(),
        friend_email: $('#friend_email').val(),
        comments: $('#comments').val()
      }
      , function(ret){
        alert('Een email is succesvol verstuurd')
        if (ret == 'success')
        {
          $('.tellafriend').fadeOut('fast',function(){
            $('.tellafriend').remove()
          });
          $('.background').fadeOut('fast',function(){
            $('.background').remove()
          });
          return false
        }
      });
    }
  });
});
