/*   fixedPosition   

var fixedPosition = function(element, top, left)
    {
    element.style.display = "block";

    if (!window.XMLHttpRequest && window.ActiveXObject)
        {
        element.style.position = "absolute";
        fixedPosition.setGlobal();
        }

    else
        {
        element.style.position = "fixed";
        }

    element.style.top = top + "px";
    element.style.left = left + "px";
    };

fixedPosition.addCSSRule = function(key, value)
    {
    var css = document.styleSheets[document.styleSheets.length - 1];
    css.cssRules ? (css.insertRule(key + "{" + value + "}", css.cssRules.length)) : (css.addRule(key, value));
    };

fixedPosition.inited = false;

fixedPosition.setGlobal = function()
    {
    if (!fixedPosition.inited)
        {
        document.body.style.height = "100%";
        document.body.style.overflow = "auto";
        fixedPosition.addCSSRule("*html", "overflow-x:auto;overflow-y:hidden;");
        fixedPosition.inited = true;
        }
    };
*/

$(function()
    {
    var inner_width;
    var last_x = 0;
    var inner = 0;
    var m;

    //var btn_top = window.screen.availHeight * 0.2;

    //$("#arL,#arR").css({ top: btn_top });
    $("#arR").css({ right: 0 });
    //$("#container").css({ top: btn_top });

    function WindowResize()
        {
        //btn_top = window.screen.availHeight * 0.2;

        //$("#arL,#arR").css({ top: btn_top });
        $("#arR").css({ right: 0 });
        //$("#container").css({ top: btn_top });
        }

    window.onresize = WindowResize;

    if ($.browser.msie)
        {
        $("#arL,#arR").hover(function()
            {
            $(this).show()
            } ,              function()
            {
            $(this).hide()
            } )
        }

    else
        {
        $("#arL,#arR").fadeTo(500, 0.0);

        $("#arL,#arR").hover(function()
            {
            $(this).fadeTo(500, 1.0)
            } ,              function()
            {
            $(this).fadeTo(500, 0.0)
            } )
        }

    $(".post_block .index").click(function()
        {
        last_x = $("#wrapper").css("left");
        inner_width = $(this).parent().find(".entry-content").width();

        $(this).removeClass("index").addClass("clicked");
        $(this).parent().find(".entry-content").attr("w",
                                                     inner_width).css(
             { display: "block" }).show().width(0).animate({ width: inner_width + 40 }, 300, function()
            {
            var in_l = 0;
            $(this).find("td").each(function(i)
                {
                in_l = $(this).find("img").attr("width") + in_l + 10;
                in_l_ = in_l - $(this).find("img").width() - 10;
                //$(this).attr("l",l);
                $(this).attr("l", in_l);
                $(this).attr("l_", in_l_);
                });

            m = 0;
            $(".close_btn").width(32);
            });

        last_x_ = -$(this).attr("l_");
        $("#wrapper").animate({ left: last_x_ }, 500);
        inner = 1;
        })

    $(".post_block .clicked").click(function()
        {
        var w = $(this).parent().find(".entry-content").attr("w");
        $(this).parent().find(".entry-content").show().animate({ width: w }, 300);
        })

    $(".entry-content td").click(function()
        {
        return false;
        } )

    $(".entry-content").append("<div class='close_btn'></div>");
    $(".close_btn").hover(function()
        {
        $(this).addClass("hover");
        } ,               function()
        {
        $(this).removeClass("hover");
        } )

    $(".close_btn").click(function()
        {
        $(this).width(0);

        //$(this).parent().parent().parent().parent().animate({ width: 0 }, 300, function()
        $(".clicked").parent().find(".entry-content").animate({ width: 0 }, 300, function()
            {
            $(this).hide().width(inner_width);
            $(this).css({ left: 0 });
            $(".clicked").addClass("index").removeClass("clicked");
            });

        $("#wrapper").animate({ left: last_x }, 500);

        inner = 0;
        m = 0;
        })

    var n = 0;
    var o = 6;

    $("#arL").click(function()
        {
        if (n > 0 && inner == 0)
            {
            n--;

            if ($.browser.msie)
                {
                $("#wrapper").animate({ left: -Number($(".index").eq(n).attr("l_")) - o }, 500);
                }

            else
                $("#wrapper").animate({ left: -Number($(".index").eq(n).attr("l_")) }, 500);
            }

        else if (inner == 1 && m > 0)
            {
            m--;
            $(".clicked").parent().find(".entry-content").animate(
                 { left: -Number($(".clicked").parent().find(".entry-content").find("td").eq(m).attr("l_")) }, 500);
            //alert($(".clicked").parent().find(".entry-content").html())
            }
        })

    $("#arR").click(function()
        {
        if (n < $(".post_block").length - 1 && inner == 0)
            {
            n++;

            if ($.browser.msie)
                {
                $("#wrapper").animate({ left: -Number($(".index").eq(n).attr("l_")) - o }, 500);
                }

            else
                $("#wrapper").animate({ left: -Number($(".index").eq(n).attr("l_")) }, 500);
            }

        else if (n < $(".post_block").length - 1 && inner == 1 && m < $(".clicked").parent().find("td").length - 1)
            {
            m++;
            $(".clicked").parent().find(".entry-content").animate(
                 { left: -Number($(".clicked").parent().find(".entry-content").find("td").eq(m).attr("l_")) }, 500);
            //alert(Number($(".clicked").parent().find("td").eq(m).attr("l_")))
            }
        })
    })
