$(document).ready(function () {
  var colour = $("div#overlay");
	var content = $("#CommentsForm");

	content.hide();
	colour.hide();

  $('#CommentsCancel').click(function(){
    content.hide();
    colour.stop().fadeTo(100, 0, function(){
      colour.css({display: 'none'});
    })
    return false;
  })
  $('#CommentsSubmit').click(function(){
    $.post("/save_com.php",$("#CommentsFormForm").serialize(),function(data){
      $('#CommentsCancel').click();
      commentBlick(data);
      return false;
    });
    return false;
  })

  $('.buttonBuy').mouseover(function(){
    buttonBuyAnimate();
  })
  $('.makeComments').click(function(){

    // Определим видимую часть экрана
    var scrollTop       = $(window).scrollTop();
    var scrollLeft      = $(window).scrollLeft();
    var contentWidth    = content.width();
    var contentHeight   = content.height();
    var windowWidth     = $(window).width();
    var windowHeight    = $(window).height();


    centerContentHeight = Math.round(windowHeight/2-content.height()/2);
    centerContentWidth  = Math.round(windowWidth/2-content.width()/2);

    content.css({
      display: 'block',
      visibility: 'visible',
      position: 'fixed',
      top: centerContentHeight+'px',
      left:  centerContentWidth+'px'

    });
    
    colour.css({
      display: 'block',
      visibility: 'visible',
      position: 'fixed',
      width:  '100%',
      height: '100%'

    });
    content.show('slow');

		colour.stop().fadeTo(500, .4)


    return false;
  })

});
function commentBlick(data)
{
  $('#CommentSaved').html(data + $('#CommentSaved').html());
  $('#commentBlick').fadeTo(200,.1,function(){
    $('#commentBlick').fadeTo(300,1, function(){
      $('#commentBlick').fadeTo(200,.1,function(){
        $('#commentBlick').fadeTo(300,1);
      });
    });
  });
}
