﻿var number_of_teachs = 0;
var pos_of_teachs = 0;

function recentpoststeach(json) 
{

    document.write("<div style=\"overflow:hidden; width:255px; height:255px; position:absolute; \">");
    document.write("<div id=\"inner_teach_div\" style=\"overflow:visible; width:10000px; height:165px; position:absolute; left:0px;\">");

    number_of_teachs = (json.feed.entry.length > 20 ? 20 : json.feed.entry.length);
    for (var i = 0; i < (json.feed.entry.length > 20 ? 20 : json.feed.entry.length) + 1; i++)
    {

        var ind = (i >= (json.feed.entry.length > 20 ? 20 : json.feed.entry.length) ? i - (json.feed.entry.length > 20 ? 20 : json.feed.entry.length) : i);

        for (var j = 0; j < json.feed.entry[ind].link.length; j++) 
        {
            if (json.feed.entry[ind].link[j].rel == 'alternate') 
            {
                break;
            }

        }

        var entry = json.feed.entry[ind];

        if ("content" in entry) 
        {
            s = entry.content.$t;
        }
        else if ("summary" in entry) 
        {
            s = entry.summary.$t;
        }
        else 
        {
            s = "";
        }

        a = s.indexOf("<img");
        b = s.indexOf("src=\"", a);
        c = s.indexOf("\"", b + 5);
        d = s.substr(b + 5, c - b - 5);
        if ((a != -1) && (b != -1) && (c != -1) && (d != "")) { thumburl = d; } else thumburl = 'http://lh3.ggpht.com/_sS1Q7guTuCw/TO-xB-FcO_I/AAAAAAAAAh0/6y_91wP4vbU/blank.png';

        var entryUrl = "'" + json.feed.entry[ind].link[j].href + "'";
        var entryTitle = json.feed.entry[ind].title.$t;

        if (entryTitle.length >= 77) {
            entryTitle = entryTitle.substring(0, 77);
            var quoteEnd = entryTitle.lastIndexOf(" ");
            entryTitle = entryTitle.substring(0, quoteEnd) + "...";
        }

        var image = "<a href=" + entryUrl + "><img src=\"" + thumburl + "\" width=\"90\" height=\"127\" /></a>";
        var item = "<a href=" + entryUrl + '" >' + entryTitle + "</a>";

        if ("content" in entry) {
            var postcontent = entry.content.$t;
        }
        else if ("summary" in entry) {
            var postcontent = entry.summary.$t;
        }
        else {
            var postcontent = "";
        }

        var re = /<\S[^>]*>/g;
        postcontent = postcontent.replace(re, "");
        postcontent = postcontent.replace("Olvasd tovább »", "");

        document.write("<div style=\"width:255px; height:100px; float:left;\">");
        document.write("<div style=\"float:left;width:90px;overflow:visible;\">" + image + "</div>");

        var foundRem = 0;
        a = s.indexOf("<div id=\"1==");
        if (a != -1) {
            b = s.indexOf("===", a);
            c = s.substr(a + 12, b - a - 12);
            foundRem = 1;
            if (postcontent.length >= 140) {
                postcontent = postcontent.substring(0, 140);
                var quoteEnd = postcontent.lastIndexOf(" ");
                postcontent = postcontent.substring(0, quoteEnd) + "...";
            }
            document.write("<div style=\"float:left;width:160px;font-family:Verdana;font-size:11px;text-align:left;font-weight:normal;padding-left:5px;padding-right:0px;\">" + item + "<br/>");
            document.write("<div style=\"font-family:sans-serif;font-size:11px;line-height:13px;font-weight:normal; height:65x; overflow:hidden;\">" + postcontent + "</div>");
            document.write("<div style=\"font-family:sans-serif;font-size:11px;padding:3px 0px 3px 0px;line-height:13px;font-weight:normal;text-align:center; height:26px; overflow:hidden; background-color:#3b5999;color:#f5f4e2;\">" + c + "</div>");
            document.write("</div>");
        }

        a = s.indexOf("<div id=\"2==");
        if (a != -1) {
            b = s.indexOf("===", a);
            c = s.substr(a + 12, b - a - 12);
            foundRem = 1;
            if (postcontent.length >= 140) {
                postcontent = postcontent.substring(0, 140);
                var quoteEnd = postcontent.lastIndexOf(" ");
                postcontent = postcontent.substring(0, quoteEnd) + "...";
            }
            document.write("<div style=\"float:left;width:160px;font-family:Verdana;font-size:11px;text-align:left;font-weight:normal;padding-left:5px;padding-right:0px;\">" + item + "<br/>");
            document.write("<div style=\"font-family:sans-serif;font-size:11px;line-height:13px;font-weight:normal; height:75x; overflow:hidden;\">" + postcontent + "</div>");
            document.write("<div style=\"font-family:sans-serif;font-size:13px;margin-top:5px;padding:6px 0px 6px 0px;line-height:13px;font-weight:bold;text-align:center; height:15px; overflow:hidden; background-color:#ff9899;color:#666666;\">" + c + "</div>");
            document.write("</div>");
        }

        a = s.indexOf("<div id=\"3==");
        if (a != -1) {
            b = s.indexOf("===", a);
            c = s.substr(a + 12, b - a - 12);
            foundRem = 1;
            if (postcontent.length >= 140) {
                postcontent = postcontent.substring(0, 140);
                var quoteEnd = postcontent.lastIndexOf(" ");
                postcontent = postcontent.substring(0, quoteEnd) + "...";
            }
            document.write("<div style=\"float:left;width:160px;font-family:Verdana;font-size:11px;text-align:left;font-weight:normal;padding-left:5px;padding-right:0px;\">" + item + "<br/>");
            document.write("<div style=\"font-family:sans-serif;font-size:11px;line-height:13px;font-weight:normal; height:75x; overflow:hidden;\">" + postcontent + "</div>");
            document.write("<div style=\"font-family:sans-serif;font-size:13px;margin-top:5px;padding:6px 0px 6px 0px;line-height:13px;font-weight:bold;text-align:center; height:15px; overflow:hidden; background-color:#ff9899;color:#666666;\">" + c + "</div>");
            document.write("</div>");
        }

        if (foundRem == 0) {
            if (postcontent.length >= 200) {
                postcontent = postcontent.substring(0, 200);
                var quoteEnd = postcontent.lastIndexOf(" ");
                postcontent = postcontent.substring(0, quoteEnd) + "...";
            }
            document.write("<div style=\"float:left;width:160px;font-family:Verdana;font-size:11px;text-align:left;font-weight:normal;padding-left:5px;padding-right:0px;\">" + item + "<br/><div style=\"font-family:sans-serif;font-size:11px;line-height:13px;font-weight:normal;\">" + postcontent + "</div></div>");
        }

        if (json.feed.entry[ind]) {
            if ((new Date().getTime() - new Date(json.feed.entry[ind].published.$t.substr(0, 10).replace("-", "/")).getTime()) / (1000 * 60 * 60 * 24) <= 10) {
                document.write("<div style=\"position:absolute; width:27px; top:0px; color:red; text-align:right;\"><img src=\"http://www.prolineinteriors.co.uk/pictures/blog/icon/legujabb.png\" /></div>");
            }
        }
        document.write("</div>");

    }

    document.write("</div>");
    document.write("<div style=\"position:absolute; top:135px; width:255px; text-align:right;\">");
    document.write("<a href=\"\" onclick=\"backteach(); return false;\"><< vissza</a>&nbsp;&nbsp;");
    document.write("<a href=\"\" onclick=\"pauseteach(); return false;\">állj</a>&nbsp;&nbsp;");
    document.write("<a href=\"\" onclick=\"playteach(); return false;\">előre >></a>&nbsp;&nbsp;");
    document.write("<a href=\"http://www.uzenetek.com/search/label/Tanitas\" >összes</a>");
    document.write("</div>");
    document.write("</div>");

    document.write("<script>$(window).load(function() { $(\"#inner_teach_div\").delay(7000).animate({\"left\": \"-=\"+255+\"px\"}, 2550, function() { movenextteach(); }); });</script>");
}

function movenextteach() {
    pos_of_teachs += 1;
    if (pos_of_teachs == number_of_teachs) {
        pos_of_teachs = 0;
        document.getElementById("inner_teach_div").style.left="0px";
    }
    $("#inner_teach_div").delay(7000).animate({ "left": "-=" + 255 + "px" }, 2550, function () { movenextteach(); });
}

function pauseteach() {
    $('#inner_teach_div').stop(true);
}

function playteach() {
    pauseteach();
    if (parseInt(document.getElementById('inner_teach_div').style.left) == 255 * number_of_teachs) {
        pos_of_teachs = 0;
        document.getElementById("inner_teach_div").style.left = "0px";
    }
    $("#inner_teach_div").animate({ "left": "-=" + (255 + parseInt(document.getElementById('inner_teach_div').style.left) % 255) + "px" }, (255 + parseInt(document.getElementById('inner_teach_div').style.left) % 255) / 255 * 500, function () { movenextteach(); });
}

function backteach() {
    pauseteach();
    if (parseInt(document.getElementById('inner_teach_div').style.left) % 255 == 0) {
        if (parseInt(document.getElementById('inner_teach_div').style.left) == 0) {
            document.getElementById("inner_teach_div").style.left = "-" + (255 * number_of_teachs) + "px";
            pos_of_teachs = number_of_teachs;
            $("#inner_teach_div").animate({ "left": "+=" + 255 + "px" }, 500, function () { pos_of_teachs--; });
        }
        else {
            $("#inner_teach_div").animate({ "left": "+=" + 255 + "px" }, 500, function () { pos_of_teachs--; });
        }
    }
    else {
        $("#inner_teach_div").animate({ "left": "+=" + (-parseInt(document.getElementById('inner_teach_div').style.left) % 255) + "px" }, (-parseInt(document.getElementById('inner_teach_div').style.left) % 255) / 255 * 500);
    }
}
