﻿$(document).ready(function() {
    $(".cmdRatePhoto").click(function() {
        $(this).parent().parent().fadeOut(function() {
            $(this).remove();
        });

        $.post("/ajax_functions.aspx", { "func": "ratePhoto", "id": $(".ajax_param.photoid").val(), "value": this.title }, function(data) {
            var newObj = $(data);
            $(".rate_result").replaceWith(newObj);
            newObj.effect("pulsate", { times: 2 }, 500);
        }, "html");
        return false;
    });

    $("#cmdMorePhotoInfos").click(function() {
        getMorePhotoInfos(
            $(".ajax_param.photoid").val(),
            $(this).parent().parent().find(".key_value_pair"));

        $(this).parent().remove();
        return false;
    });
});

function setFavourite(id,sender) {
    var objLoading = document.createElement("img");
    objLoading.setAttribute("src","/images/loading.gif");
    objLoading.setAttribute("alt","loading...");

    $(sender).append(objLoading);
    $.post("/ajax_functions.aspx", { "func": "setFavourite", "id": id }, function(data) {
        $(sender).parent().html(data);
        //        $(sender).parent().fadeOut("fast",function()
        //        {
        //            $(sender).replaceWith(data);
        //            $(this).fadeIn("slow");
        //        });
    }, "html");
}

function getMorePhotoInfos(id, list) {
    $.post("/ajax_functions.aspx", { "func": "getMorePhotoInfos", "id": id }, function(data) {
        for (var elem in data)
            list.append("<li><span>" + elem + ":</span>" + data[elem] + "</li>");
    }, "json");
}
