// открываем для просмотра картинки
function viewWind(theURL,winName,features) {
        var ScreenWidth=window.screen.width;
        var ScreenHeight=window.screen.height;
        placementx=(ScreenWidth/2)-((780)/2);
        placementy=(ScreenHeight/2)-((580)/2);
        window.open(theURL,winName,features+",left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy);
        return false;
}

$(document).ready(function(){
        jQuery("#info").jqm({
                onShow: function(hash){ hash.w.fadeIn(500); },
                onHide: function(hash){
                                 hash.w.fadeOut('2000', function(){ hash.o.remove(); });

                                 jQuery("#complementImg").fadeOut('fast');
                                 jQuery("textarea[@name='msg']").val('');
                        }
        });
});

function openCompliment(event, position, foto_id)
{
        jQuery("#info").jqmShow();
        jQuery("#complimentError").text('').fadeOut(200);
        loadCompliment(foto_id);
        jQuery("#complementImg").attr('src', '/fotos/thumb/'+ event +'_'+ position +'.jpg').fadeIn(500);
        jQuery("input[rel='foto_id']").val(foto_id);
}

function sendCompliment()
{
        var button = jQuery("#sendButton").val();
        jQuery("#sendButton").attr("disabled", "disabled").val("Подождите...");
        jQuery("#complimentError").text('').fadeOut(200);

        var post = {
                    action:  'save',
                    foto_id: jQuery("input[rel='foto_id']").val(),
                    name:    jQuery("input[@name='name']").val(),
                    email:   jQuery("input[@name='email']").val(),
                    msg:     jQuery("textarea[@name='msg']").val()
                    };

        jQuery.post("/gallery_ajax.php", post, function(data){
                data = data.split("|");
                if (data[0] == 'saved')
                {
                        jQuery("textarea[@name='msg']").val('');
                        loadCompliment(post['foto_id']);
                }
                jQuery("#complimentError").text(data[1]).fadeIn(500);
                jQuery("#sendButton").removeAttr("disabled").val(button);
        });
}

function loadCompliment(foto_id)
{
        jQuery("#complimentMsgs").css('display', 'none');

        var post = {
                    action:  'load',
                    foto_id: foto_id
                    };
                    
        jQuery.post("/gallery_ajax.php", post, function(data){
                jQuery("#complimentMsgs").html(data).fadeIn(500);
        });
}