﻿//---------------------------------------------+
//         Page public declaration             |
//---------------------------------------------+
var page_attached_to = "index";
var pageContent;
var contents = new Array()


contents[0] = "#slogans";
contents[1] = "#topblogs";
contents[2] = "#about";

function loadPageContent() {
    if (l_lang.substring(0, 2) == "en") {
        window.location = 'models.html';
        return;
    }

    var str = new StringBuilderEx();
    $.ajax({
        type: "GET",
        url: "data/" + page_attached_to + ".xml",
        dataType: "xml",
        success: function (xml) {
            pageContent = xml;
            fillPage();

        }
    });
}

function fillPage() {
    var t;
    var c;
    var i = 0;
    var str = ""; ;
    $("#content").html("")
    for (i = 0; i <= contents.length - 1; i++) {
        c = $(pageContent).find("content_block[name='" + contents[i] + "']")
        if ($(c).length == 0) {
            c = $(pageContent).find("content_block[name='" + contents[i] + "']")
        }
        t = $(cntBlockTypes).find("type[name='" + $(c).attr("type") + "']");

        switch ($(c).attr("type")) {
            case 'ul_h_list_txt':
                var items_count = $(c).find("list_item[lng='" + l_lang.substring(0, 2) + "']").length;
                if (items_count > 0) {
                    var lItems = "";
                    str = $(t).find("block_start").text().replace("{list_css}", $(c).attr("css"));
                    if ($(t).attr("style") == "1") {
                        $('head').append($(t).find("block_style[css='" + $(c).attr("css") + "']").text());
                    }
                    if ($(this).attr("script") == "1") {
                        str += $(t).find("block_script").text();
                    }
                    str += $(t).find("block_header").text().
                            replace("{block-header}", $(c).find("block_header[lng='" + l_lang.substring(0, 2) + "']").text());

                    str += $(t).find("block_content").text().replace("{list-items}", function () {
                        lItems += $(t).find("block_list_start").text();
                        $(c).find("list_item[lng='" + l_lang.substring(0, 2) + "']").each(
                    function () {
                        lItems += $(t).find("block_list_item[type='" + $(c).attr("list_style") + "']").text().
                                replace("{item-width}", (100 / items_count)-0.01 + "%").
                                replace("{item-no}", $(this).attr("no")).
                                replace("{item-text}", $(this).text());
                    })

                        lItems += $(t).find("block_list_end").text();
                        return lItems;
                    });

                    str += $(t).find("block_end").text();
                    $("#content").append(str);
                }
                break;
            case 'ul_image_list_item':
                var items_count = $(c).find("list_item[lng='" + l_lang.substring(0, 2) + "']").length;
                var lItems = "";
                str = $(t).find("block_start").text().replace("{list_css}", $(c).attr("css"));
                if ($(t).attr("style") == "1") {
                    $('head').append($(t).find("block_style[css='" + $(c).attr("css") + "']").text());
                }
                if ($(t).attr("script") == "1") {
                    str += $(t).find("block_script[type='" + $(c).attr("script") + "']").text();
                }
                str += $(t).find("block_header").text().
                            replace("{block-header}", $(c).find("block_header[lng='" + l_lang.substring(0, 2) + "']").text());

                str += $(t).find("block_content").text().replace("{list-items}", function () {
                    lItems += $(t).find("block_list_start").text();
                    $(c).find("list_item[lng='" + l_lang.substring(0, 2) + "']").each(
                    function () {
                        lItems += $(t).find("block_list_item[type='" + $(c).attr("list_style") + "']").text().
                                replace("{item-width}", (100 / 5)-0.01 + "%").
                                replace("{item-img}", $(this).find("img").text()).
                                replace("{item_url}", $(this).find("url").text()).
                                replace("{item_first_line}", $(this).find("first_line").text()).
                                replace("{item_second_line}", $(this).find("second_line").text());
                    })

                    lItems += $(t).find("block_list_end").text();
                    return lItems;
                });
                str += $(t).find("block_end").text();
                $("#content").append(str);
                break;




            default:
                break;
        }



    }




}


