$.getComments = function(PhotoId, Page){
    var cssObj = {
        'background-image' : 'url("/img/loader.gif")',
        'background-repeat' : 'no-repeat',
        'background-position' : '50% 50%'
    };
    $('#form-comment :input').attr('disabled', 'true');
    $.post("/ajax.php", ({Action: 'getComments', Id: PhotoId, Offset: Page}), function(data) {
        $('#comments').html(data).css('background', 'none');
        $('#form-comment :input').removeAttr('disabled');
    });
}
$.getRecalls = function(Page){
    var cssObj = {
        'background-image' : 'url("/img/loader.gif")',
        'background-repeat' : 'no-repeat',
        'background-position' : '50% 50%'
    };
    $('#form-recall :input').attr('disabled', 'true');
    $.post("/ajax.php", ({Action: 'getRecalls', Offset: Page}), function(data) {
        $('#recalls').html(data).css('background', 'none');
        $('#form-recall :input').removeAttr('disabled');
    });
}

$(document).ready(function(){
    a = parseFloat($('#left').css('height'));
    b = parseFloat($('#content').css('height'));
    if(!$.browser.msie) {
        $('#left').css('height', b + 20);
        $('#counters').css('margin-top', b - a + 80);
    }
    
    $('#prev-img').mouseover(function(){$(this).attr({src : '/img/prev_over.gif'}); $(this).ifixpng();}).mouseout(function(){$(this).attr({src : '/img/prev_out.gif'}); });
    $('#next-img').mouseover(function(){$(this).attr({src : '/img/next_over.gif'}); $(this).ifixpng();}).mouseout(function() {$(this).attr({src : '/img/next_out.gif'}); });
    $('#form-comment').submit(function(){
        re = /[a-zA-Z0-9\.\-_]+\@[a-zA-Z0-9\.\-_]+\.[a-zA-Z]+/;
        if (!re.test($('#form-comment input:text[name=Email]').val()) && $('#form-comment input:text[name=Email]').val().length) {
            alert('Вы ввели некорректный e-mail');
            $('#form-comment input:text[name=Email]').focus();
            return false;
        }
        $.post("/ajax.php", ({
            Action: 'addComment', 
            Id: PhotoId,
            Name: $('#form-comment input:text[name=Name]').val(),
            Email: $('#form-comment input:text[name=Email]').val(),
            Message: $('#form-comment textarea[name=Message]').val()
        }), function(data){
            $.getComments(PhotoId, Page);
        });
        return false;

    });
    $('#form-recall').submit(function(){
        re = /[a-zA-Z0-9\.\-_]+\@[a-zA-Z0-9\.\-_]+\.[a-zA-Z]+/;
        if (!re.test($('#form-recall input:text[name=Email]').val()) && $('#form-recall input:text[name=Email]').val().length) {
            alert('Вы ввели некорректный e-mail');
            $('#form-recall input:text[name=Email]').focus();
            return false;
        }
        $.post("/ajax.php", ({
            Action: 'addRecall', 
            Name: $('#form-recall input:text[name=Name]').val(),
            Email: $('#form-recall input:text[name=Email]').val(),
            Message: $('#form-recall textarea[name=Message]').val()
        }), function(data){
            $.getRecalls(Page);
        });
        return false;

    });

	if (typeof(PhotoId) != 'undefined' && typeof(Page) != 'undefined') {
//		$.getComments(PhotoId, Page);
	}


});
