﻿$(document).ready(function() {
    $.ajax({ type: "GET", url: "/Json/Demands.rails", data: null, success:
        function(data) {
            var demands = eval(data);
            for (var i in demands) {
                var currentDemand = "";
                for (var j in demands[i]) {
                    if ((demands[i][j].Name == "Kategoria") && (demands[i][j].Value != null)) {
                        currentDemand += "<li><strong>W kategorii:</strong> " + demands[i][j].Value;
                    }
                    if ((demands[i][j].Name == "Marka") && (demands[i][j].Value != null)) {
                        currentDemand += ", <strong>marka:</strong> " + demands[i][j].Value;
                    }
                    if ((demands[i][j].Name == "Model") && (demands[i][j].Value != null)) {
                        currentDemand += ", <strong>model:</strong> " + demands[i][j].Value;
                    }
                    if ((demands[i][j].Name == "Dodatkowe informacje") && (demands[i][j].Value != null)) {
                        currentDemand += ", <strong>dodatkowe informacje:</strong> " + demands[i][j].Value.substring(0,30);
                    }
                    if ((demands[i][j].Name == "Ilość minimalna") && (demands[i][j].Value != null)) {
                        currentDemand += ", <strong>ilość minimalna:</strong> " + demands[i][j].Value;
                    }
                }
                if (currentDemand != "") {
                    currentDemand += "</li>";
                    $("#demandscarousel").append(currentDemand);
                }
            }

            jQuery('#demandscarousel').jcarousel({
                auto: 2,
                wrap: 'last',
                vertical: true,
                scroll: 1,
                visible: 1
            });
        }
    });
    $.ajax({ type: "GET", url: "/Json/Currencies.rails", data: null, success:
        function(data) {
            var currencies = eval(data);
            for (var i in currencies) {
                var currency = "";
                for (var j in currencies[i]) {
                    if (j == "Name") {
                        currency += "<tr><td align=\"center\"><strong>" + currencies[i][j] + "</strong></td>";
                    }
                    if (j == "SaleRate") {
                        currency += "<td align=\"right\">" + currencies[i][j] + "</td>";
                    }
                    if (j == "BuyRate") {
                        currency += "<td align=\"right\">" + currencies[i][j] + "</td></tr>";
                    }
                }
                $("#currencies").append(currency);
            }
        }
    });
    $.ajax({ type: "GET", url: "/Json/News.rails", data: null, success:
        function(data) {
            var news = eval(data);
            for (var i in news) {
                var currentNews = "";
                for (var j in news[i]) {
                    if (j == "Content") {
                        currentNews += news[i][j];
                    }
                }
                $("#newsmarquee").append(currentNews);
            }
        }
    });
});


