/**
 *
 *
 * @author Sebastian Bielawski
 * @copyright Netafce (c) 2010, http://www.netface.pl
 */

$(document).ready(function(){
    // Tabsy
    $("#profile-nav ul li a").click(function(){
        $("#profile-nav ul li a").each(function(){
            $(this).removeClass("active");
        });

        $(this).attr("class", "active");

        $.ajax({
            url: $(this).attr("href"),
            dataType: "html",
            beforeSend: function(){
                $("#profile-nav-tab").html("Ładowanie danych ...");
            },
            success: function(responseText){
                $("#profile-nav-tab").html(responseText);
            }
        });

        return false;
    });

    // Dodawanie mamy do ulubionych
    $("#add-mom-favourites").click(function(){
        $.ajax({
            url: $(this).attr("href"),
            dataType: "html",
            success: function(responseText) {
                PopupInfo.init(responseText);
            }
        });
        return false;
    });

    // Zgłaszanie mam do moderacji
    $("#moderate-mom").click(function(){
        var http =$(this).attr("href");
        $.ajax({
            url: http,
            success: function(responseText) {
                var response = $(responseText);
                PopupInfo.init(responseText);
                $("#btn-send-popup").click(function(){
                    var params = null;
                    response.find('.mod-error').hide()
                    if (response.find('.mod-error:first').length) {
                        if ($('[name=modmessage]').val().length) {
                            params = {
                                modmessage:$('[name=modmessage]').val()
                                }
                        } else {
                            $('.mod-error').show()
                            return false;
                        }
                    }
                    $("#btn-close-popup").click();
                    $.ajax({
                        url: $("#moderate-mom").attr("href"),
                        type: "post",
                        data: params,
                        success: function(responseText) {
                            PopupInfo.init(responseText);
                        }
                    });
                });
            }
        });
        return false;
 
    });

    // Domyślny tab
    var tab = $("#profile-nav").attr("axis");
    $("#profile-nav ul li:eq(" + tab + ") a:first").click();
});
