
$(document).ready(
    function()
    {
        $('.obliczZAgiel').live("click", function(e){
            e.preventDefault();
            eval("var json="+$(this).attr('rel'));
            if (json.total < 100) {
               $.achtung({
                        className: 'achtungWebsite',
                        icon: 'ui-icon-notice',
                        timeout: 60,
                        message: 'Zakupów w systemie Żagiel można dokonywać od kwoty 100 zł'
                    });
            }
            else
            {
            window.open('https://www.eraty.pl/symulator/oblicz.php?numerSklepu='+json.numer+'&wariantSklepu='+json.wariant+'&typProduktu=0&wartoscTowarow='+json.total, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
            }
    });

        $('a.nyroModalLink').nyroModal({width: 620,  height: 580});


        if ($(".login-link").length > 0)
        {
            var email = $("#email_login"), password = $("#pass_login"), allFields = $([]).add(email).add(password), tips = $("#validateTips");
            function updateTips(t) {
                tips.text(t).effect("highlight",{},1500);
            }

            var buttons = {};
            buttons[language.log_in] = function() {
                $.post("/"+SiteLang+"/account/login_ajax", {
                    email: email.val(),
                    pass: password.val()
                },
                function(data){
                    if (data == 'ok') {
                        document.location = "/"+SiteLang+"/";
                    }
                    else {
                        updateTips(data);allFields.addClass('ui-state-error');
                    }
                })
            };

            $("#dialog-login").dialog({
                bgiframe: true,
                autoOpen: false,
                width: 425,
                height: 250,
                modal: true,
                draggable: false,
                resizable: false,
                buttons: buttons,
                close: function() {
                    allFields.val('').removeClass('ui-state-error');updateTips('');
                }
            });

            $(".login-link").click(function(e) {
                e.preventDefault();
                $('#dialog-login').dialog('open');
            });
        }

        if ($("#ask-link").length > 0)
        {
            var email_ask = $("#email_ask"), message_ask = $("#message_ask"),copy_ask = $("#copy_ask"),product = $("#product"), allFields_ask = $([]).add(email_ask).add(message_ask), tips_ask = $("#validateTips_ask");
         
            function updateTips_ask(t) {
                tips_ask.text(t).effect("highlight",{},1500);
            }


            var buttons = {};
            buttons[language.ask_send_query] = function() {
                $.post("/"+SiteLang+"/ajax/ask", {
                    email: email_ask.val(),
                    message: message_ask.val(),
                    product: product.val(),
                    copy: (copy_ask.is(":checked") ? 1 : 0)

                },
                function(data){
                    if (data == 'ok') {
                        $('#dialog-ask').dialog('close');
                        $.achtung({
                            className: 'achtungWebsite',
                            icon: 'ui-icon-notice',
                            timeout: 60,
                            message: language.ask_query_sent
                        });
                    }
                    else {
                        updateTips_ask(data);allFields_ask.addClass('ui-state-error');
                    }
                })
            };




            $("#dialog-ask").dialog({
                bgiframe: true,
                autoOpen: false,
                width: 625,
                height: 450,
                modal: true,
                draggable: true,
                resizable: false,
                buttons: buttons,
                close: function() {
                    allFields_ask.val('').removeClass('ui-state-error');updateTips_ask('');
                }
            });

            $("#ask-link").click(function(e) {
                e.preventDefault();
                $('#dialog-ask').dialog('open');
            });
        }
                
        if ($("#currency-link").length > 0)
        {
            $("#dialog-currency").dialog({
                bgiframe: true,
                autoOpen: false,
                width: 600,
                height: 200,
                modal: true,
                draggable: true,
                resizable: false

            });

            $("#currency-link").click(function(e) {
                e.preventDefault();
                $('#dialog-currency').dialog('open');
            });
        }




        if ($("#recomend-link").length > 0)
        {
            var     email_recomend_from   = $("#email_recomend_from"),
            email_recomend_to   = $("#email_recomend_to"),
            name_recomend_to   = $("#name_recomend_to"),
            name_recomend_from   = $("#name_recomend_from"),
            message_recomend = $("#message_recomend"),
            copy_recomend    = $("#copy_recomend"),
            product          = $("#product"),
            allFields_recomend = $([]).add(email_recomend_to).add(email_recomend_from).add(name_recomend_to).add(name_recomend_from).add(message_recomend),
            tips_recomend = $("#validateTips_recomend");

            function updateTips_recomend(t) {
                tips_recomend.html(t).effect("highlight",{},1500);
            }


            var buttons = {};
            buttons[language.recomend_send_query] = function() {
                $.post("/"+SiteLang+"/ajax/recomend", {
                    email_recomend_to: email_recomend_to.val(),
                    email_recomend_from: email_recomend_from.val(),
                    name_recomend_to: name_recomend_to.val(),
                    name_recomend_from: name_recomend_from.val(),
                    message: message_recomend.val(),
                    product: product.val(),
                    copy: (copy_recomend.is(":checked") ? 1 : 0)

                },
                function(data){
                    if (data == 'ok') {
                        $('#dialog-recomend').dialog('close');
                        $.achtung({
                            className: 'achtungWebsite',
                            icon: 'ui-icon-notice',
                            timeout: 60,
                            message: 'Wiadomość została wysłana.'
                        });



                    }
                    else {
                        updateTips_recomend(data);allFields_recomend.addClass('ui-state-error');
                    }
                })
            };

            $("#dialog-recomend").dialog({
                bgiframe: true,
                autoOpen: false,
                width: 625,
                height: 450,
                modal: true,
                draggable: true,
                resizable: false,
                buttons: buttons,
                close: function() {
                    allFields_recomend.val('').removeClass('ui-state-error');updateTips_recomend('');
                }
            });

            $("#recomend-link").click(function(e) {
                e.preventDefault();
                $('#dialog-recomend').dialog('open');
            });
        }


        $("#tofavorites-link").click(function(e) {
            e.preventDefault();
            $.post("/"+SiteLang+"/ajax/add_to_favorites", {
                product: $("#product").val()
            },
            function(data){
                if (data == 'ok') {
                    $.achtung({
                        className: 'achtungWebsite',
                        icon: 'ui-icon-notice',
                        timeout: 60,
                        message: language.added_to_store
                    });
                }
            })

        });


        $(".remove_from_fav").click(function(e) {
            e.preventDefault();
            var $id = $(this).attr('rel');
            var $elem = $(this).parents("div.storebox");
            $.post("/"+SiteLang+"/ajax/remove_to_favorites", {
                product: $id
            },
            function(data){
                if (data == 'ok') {
                    $elem.remove();
                    $.achtung({
                        className: 'achtungWebsite',
                        icon: 'ui-icon-notice',
                        timeout: 60,
                        message: language.removed_to_store
                    });
                }
            })

        });







        $('form').formtips({
            class_name: 'tipped'
        });
        $(".toggleNext").next("div").hide();
        $(".active").parents(".wssk_podmenu").show();
        $(".toggleNext").click( function(e) {
            e.preventDefault();
            $(this).toggleClass('offer_hover');
            $(this).next("div").toggle();
        });
        $('.active').each(function()
        {
            $(this).parent().prev('a').trigger('click');
        });

        $("#c_menu").css("opacity","0");
    });


function simba(){
    $("#c_menu").animate({
        opacity: 1
    }, 5000 );
}


