var indexArticles = new Array();
var indexArticlesCurrent = new Array();

var blockArticlesCountPage = new Array();
var blockArticlesSport = {order:"last",page:1,pages:2};
var smallBlocArticles = new Array();
var bigBlocArticles = new Array();


function nextIndexArticle(categoryId) {
    if (smallBlocArticles["_" + categoryId].inProcess || smallBlocArticles["_" + categoryId].page == smallBlocArticles["_" + categoryId].pages || smallBlocArticles["_" + categoryId].pages == 0) {
        return;
    }
    var div = document.getElementById("articleContent" + categoryId);
    div.innerHTML = "Загрузка ";
    smallBlocArticles["_" + categoryId].inProcess = true;
    smallBlocArticles["_" + categoryId].interval = setInterval(processSmallBlock, 200, categoryId);
    smallBlocArticles["_" + categoryId].page++;

    loadCategoryAricles(categoryId);
}

function loadCategoryAricles(categoryId) {
    integrio.js.include("integrio.majax");
    integrio.MAJAX.processAjax("mobus_index_get_category_" + categoryId, "/modules/news/ajax/index.jsp", "index_category", {type:smallBlocArticles["_" + categoryId].order,categoryId:categoryId, page:smallBlocArticles["_" + categoryId].page}, loadCategoryComplete);
}

function processSmallBlock() {
    var div = document.getElementById("articleContent" + arguments[0]);
    if (div) {
        div.innerHTML += ".";
        if (div.innerHTML.length > 12) {
            div.innerHTML = "Загрузка ";
        }
    }
}

function prevIndexArticle(categoryId) {
    if (smallBlocArticles["_" + categoryId].inProcess || smallBlocArticles["_" + categoryId].page == 1 || smallBlocArticles["_" + categoryId].pages == 0) {
        return;
    }
    var div = document.getElementById("articleContent" + categoryId);
    div.innerHTML = "Загрузка ";
    smallBlocArticles["_" + categoryId].inProcess = true;
    smallBlocArticles["_" + categoryId].interval = setInterval(processSmallBlock, 200, categoryId);
    smallBlocArticles["_" + categoryId].page--;

    loadCategoryAricles(categoryId);
}


function showAccentArticle(type, td) {
    integrio.js.include("integrio.majax");
    integrio.js.include("integrio.element");
    if (integrio.MAJAX.isInProcess("mobus_index_get_accents")) {
        return;
    }
    if (td.className == "aTab") {
        return;
    }
    var oldTab = td.parentNode.cells.item(td.cellIndex == 1 ? 3 : 1);
    td.className = "aTab";
    oldTab.className = "tab";
    var table = integrio.Element.getElementById("index_accent");
    table.style.height = table.getDimensions().height + "px";
    table.rows.item(0).cells.item(0).innerHTML = "Загрузка ...";
    table.rows.item(1).cells.item(0).getElementsByTagName("TABLE")[0].rows.item(0).cells.item(0).innerHTML = "&nbsp;";
    integrio.MAJAX.processAjax("mobus_index_get_accents", "/modules/news/ajax/index.jsp", "index_accent", {type:type}, loadAccentComplete);
}

function loadAccentComplete() {
    var table = integrio.Element.getElementById("index_accent");
    table.style.height = table.getDimensions().height + "px";
    table.rows.item(0).cells.item(0).innerHTML = this.getParameter("first");
    if (this.getParameter("second") != null) {
        table.rows.item(1).cells.item(0).getElementsByTagName("TABLE")[0].rows.item(0).cells.item(0).innerHTML = this.getParameter("second");
    }
}


function showArticleByCategory(categoryId, type, td) {
    if (smallBlocArticles["_" + categoryId].inProcess || smallBlocArticles["_" + categoryId].pages == 0) {
        return;
    }
    if (td.className == "aTab") {
        return;
    }
    var oldTab = td.parentNode.cells.item(td.cellIndex == 1 ? 3 : 1);
    td.className = "aTab";
    oldTab.className = "tab";
    smallBlocArticles["_" + categoryId].order = type;
    var div = document.getElementById("articleContent" + categoryId);
    div.innerHTML = "Загрузка ";
    smallBlocArticles["_" + categoryId].inProcess = true;
    smallBlocArticles["_" + categoryId].interval = setInterval(processSmallBlock, 200, categoryId);
    smallBlocArticles["_" + categoryId].page = 1;
    loadCategoryAricles(categoryId);
}

function loadCategoryComplete() {
    var categoryId = this.getParameter("categoryId");
    var content = integrio.Element.getElementById("articleContent" + categoryId);
    clearInterval(smallBlocArticles["_" + categoryId].interval);
    content.innerHTML = this.getParameter("text");
    smallBlocArticles["_" + categoryId].pages = parseInt(this.getParameter("pages"));
    smallBlocArticles["_" + categoryId].inProcess = false;
    smallBlocArticles["_" + categoryId].page = parseInt(this.getParameter("page"));
    var td = document.getElementById("bottomBlock" + categoryId).rows.item(0).cells.item(1);
    td.getElementsByTagName("IMG")[1].src = smallBlocArticles["_" + categoryId].page < smallBlocArticles["_" + categoryId].pages ? "/images/modules/news/down_over.gif" : "/images/modules/news/down.gif";
    td.getElementsByTagName("IMG")[0].src = smallBlocArticles["_" + categoryId].page != 1 ? "/images/modules/news/up_over.gif" : "/images/modules/news/up.gif";
}

function showMainNews(type, td) {
    integrio.js.include("integrio.majax");
    integrio.js.include("integrio.element");
    if (integrio.MAJAX.isInProcess("mobus_index_get_main")) {
        return;
    }
    if (td.className == "aTab") {
        return;
    }
    var oldTab = td.parentNode.cells.item(td.cellIndex == 1 ? 3 : 1);
    td.className = "aTab";
    oldTab.className = "tab";
    var div = integrio.Element.getElementById("mainnews").getElementsByTagName("DIV")[0];
    div.innerHTML = "Загрузка ...";
    integrio.MAJAX.processAjax("mobus_index_get_main", "/modules/news/ajax/index.jsp", "index_main", {type:type}, loadMainComplete);
}

function showVideoNews(type, td) {
    integrio.js.include("integrio.majax");
    integrio.js.include("integrio.element");
    if (integrio.MAJAX.isInProcess("mobus_index_get_video")) {
        return;
    }
    if (td.className == "aTab") {
        return;
    }
    var oldTab = td.parentNode.cells.item(td.cellIndex == 1 ? 3 : 1);
    td.className = "aTab";
    oldTab.className = "tab";
    var div = integrio.Element.getElementById("videonews").getElementsByTagName("DIV")[0];
    div.innerHTML = "Загрузка ...";
    integrio.MAJAX.processAjax("mobus_index_get_video", "/modules/news/ajax/index.jsp", "index_video", {type:type}, loadVideoComplete);
}


function loadMainComplete() {
    var div = integrio.Element.getElementById("mainnews").getElementsByTagName("DIV")[0];
    integrio.js.include("integrio.json");
    var articles = integrio.JSON.parse(this.getParameter("articles")).articles;
    var table = integrio.Element.createElement("TABLE");
    table.cellPadding = 0;
    table.cellSpacing = 0;
    table.width = "100%";
    table.border = 0;
    for (var i = 0; i < articles.length; i++) {
        var tr = table.insertRow(table.rows.length);
        var td = tr.insertCell(0);
        td.style.paddingBottom = "15px";
        td.innerHTML = articles[i].text;
        td.setAttribute("hint", articles[i].hint);
        td.onmouseover = showMainNewsTip;
    }
    div.innerHTML = "";
    div.parentNode.scrollTop = 0;
    div.appendChild(table);
    //div.innerHTML = this.getParameter("articles");
}

function loadVideoComplete() {
    var div = integrio.Element.getElementById("videonews").getElementsByTagName("DIV")[0];
    integrio.js.include("integrio.json");
    var articles = integrio.JSON.parse(this.getParameter("articles")).articles;
    var table = integrio.Element.createElement("TABLE");
    table.cellPadding = 0;
    table.cellSpacing = 0;
    table.width = "100%";
    table.border = 0;
    for (var i = 0; i < articles.length; i++) {
        var tr = table.insertRow(table.rows.length);
        var td = tr.insertCell(0);
        td.style.paddingBottom = "15px";
        td.innerHTML = articles[i].text;
        td.setAttribute("hint", articles[i].hint);
        td.onmouseover = showMainNewsTip;
    }
    div.innerHTML = "";
    div.appendChild(table);
    div.parentNode.scrollTop = 0;
}

function showMainNewsTip() {
    Tip(this.getAttribute("hint"), WIDTH, 300);
}

function nextBigBlock(categoryId) {
    if (bigBlocArticles["_" + categoryId].inProcess || bigBlocArticles["_" + categoryId].page == bigBlocArticles["_" + categoryId].pages) {
        return;
    }
    var table = document.getElementById("big_block_content_" + categoryId);
    var td = table.rows.item(0).cells.item(2);
    td.innerHTML = "Загрузка ";
    bigBlocArticles["_" + categoryId].inProcess = true;
    bigBlocArticles["_" + categoryId].interval = setInterval(bigBlockProcess, 200, categoryId);
    integrio.js.include("integrio.majax");
    bigBlocArticles["_" + categoryId].page++;
    integrio.js.include("integrio.majax");
    integrio.MAJAX.processAjax("mobus_index_get_big_block" + categoryId, "/modules/news/ajax/index.jsp", "index_big_block", {type:bigBlocArticles["_" + categoryId].order,categoryId:categoryId, page:bigBlocArticles["_" + categoryId].page}, loadBigBlockComplete);
}

function prevBigBlock(categoryId) {
    if (bigBlocArticles["_" + categoryId].inProcess || bigBlocArticles["_" + categoryId].page == 1) {
        return;
    }
    var table = document.getElementById("big_block_content_" + categoryId);
    var td = table.rows.item(0).cells.item(2);
    td.innerHTML = "Загрузка ";
    bigBlocArticles["_" + categoryId].inProcess = true;
    bigBlocArticles["_" + categoryId].interval = setInterval(bigBlockProcess, 200, categoryId);
    integrio.js.include("integrio.majax");
    bigBlocArticles["_" + categoryId].page--;
    integrio.MAJAX.processAjax("mobus_index_get_big_block" + categoryId, "/modules/news/ajax/index.jsp", "index_big_block", {type:bigBlocArticles["_" + categoryId].order,categoryId:categoryId, page:bigBlocArticles["_" + categoryId].page}, loadBigBlockComplete);
}
function bigBlockProcess() {
    var table = document.getElementById("big_block_content_" + arguments[0]);
    if (table) {
        var td = table.rows.item(0).cells.item(2);
        td.innerHTML += ".";
        if (td.innerHTML.length > 12) {
            td.innerHTML = "Загрузка ";
        }
    }
}
function loadBigBlockComplete() {
    var categoryId = this.getParameter("categoryId");
    var table = document.getElementById("big_block_content_" + categoryId);
    var td1 = table.rows.item(0).cells.item(0);
    var td2 = table.rows.item(0).cells.item(2);
    clearInterval(bigBlocArticles["_" + categoryId].interval);
    td1.innerHTML = this.getParameter("mainNews");
    td2.innerHTML = this.getParameter("text");
    bigBlocArticles["_" + categoryId].inProcess = false;
    bigBlocArticles["_" + categoryId].pages = parseInt(this.getParameter("pages"));
    document.getElementById("big_block_up_" + categoryId).src = bigBlocArticles["_" + categoryId].page != 1 ? "/images/modules/news/up_over.gif" : "/images/modules/news/up.gif";
    document.getElementById("big_block_down_" + categoryId).src = bigBlocArticles["_" + categoryId].page == bigBlocArticles["_" + categoryId].pages ? "/images/modules/news/down.gif" : "/images/modules/news/down_over.gif";
}

function showArticlesByBigBlock(categoryId, td, order) {
    if (bigBlocArticles["_" + categoryId].inProcess) {
        return;
    }
    bigBlocArticles["_" + categoryId].page = 1;
    bigBlocArticles["_" + categoryId].order = order;
    if (td.className == "aTab") {
        return;
    }
    var oldTab = td.parentNode.cells.item(td.cellIndex == 1 ? 3 : 1);
    td.className = "aTab";
    oldTab.className = "tab";
    var table = document.getElementById("big_block_content_" + categoryId);
    var td = table.rows.item(0).cells.item(2);
    td.innerHTML = "Загрузка ";
    bigBlocArticles["_" + categoryId].inProcess = true;
    bigBlocArticles["_" + categoryId].interval = setInterval(bigBlockProcess, 200, categoryId);
    integrio.js.include("integrio.majax");
    integrio.MAJAX.processAjax("mobus_index_get_big_block" + categoryId, "/modules/news/ajax/index.jsp", "index_big_block", {type:bigBlocArticles["_" + categoryId].order,categoryId:categoryId, page:bigBlocArticles["_" + categoryId].page}, loadBigBlockComplete);

}
