$(function()
{
  if ($.browser.msie && $.browser.version == 6)
  {
    fixAllPNG();
    fixbgpng.fnLoadPngs();
  }
  
  $('#sendToBg').height($('body').height());
  
  $("a.fancybox").fancybox({
		overlayShow: true
	});
	
	$('.printWindow').each(function()
	{
    $(this).click(function()
    {
      window.open(this.href, "print", "status=0,toolbar=0,width=1024,height=480,scrollbars=yes,resize=no");
      return false;
    });
	});
});

function sendToAFriend()
{
  $('#sendToBg').fadeIn("normal", function()
  {
    showSendTo();
  });
  
  return false;
}

function showSendTo()
{
  $('#sendTo').show();
  $('input').removeClass('error');
  $('#isErrorP').css('visibility', 'hidden');
  $('#friendProcess').hide();
  $('#friendSuccess').hide();
  $('#friendForm').show();
  
  var s = { w : $('#sendTo').width() , h : $('#sendTo').height() };
  var ws = { w : $(window).width() , h : $(window).height() };
  
  $('#sendTo').css({
    left : ws.w / 2 - s.w / 2 + 'px',
    top : ws.h / 2 - s.h / 2 + 'px'
  });
  
  $('#sendTo').hide();
  $('#sendTo').slideDown();
  
  $(window).bind("keyup", function(e)
  {
    if (e.keyCode == 27) sendFriendCancel();
  });
}

function sendFriendSubmit()
{
  var datas = {
    send_to_a_friend : 1,
    from_name : $('input[name=from_name]').val(),
    from_email : $('input[name=from_email]').val(),
    to_name : $('input[name=to_name]').val(),
    to_email : $('input[name=to_email]').val()
  };
  $('#friendform').hide();
  $('#friendSuccess').hide();
  $('#friendProcess').show();
  
  setTimeout(function()
  {
    $.post(window.location.href, datas,
    function (data)
    {
      var data = eval("(" + data + ")");
      
      if (!data.ok)
      {
        $('#isErrorP').css('visibility', 'visible');
        
        for (i in data.data)
        {
          $('input[name=' + data.data[i] + ']').addClass("error");
        }
        
        $('#friendform').show();
        $('#friendProcess').hide();
      }
      else
      {
        $('#friendSuccess').show();
        $('#friendForm').hide();
        $('#friendProcess').hide();
      }

    });
  }, 500);
  
  return false;
}

function sendFriendCancel()
{
  $('#sendTo').slideUp("normal", function()
  {
     $('#sendToBg').fadeOut();
  });

  return false;
}

