$(document).ready(function() {
    var m = 0, n = 0;
    $("div.rate").hover(function() {
        m = $(".star-full").map(function(index) {
            return $(this).attr("id");
        });
        n = $(".star-half").map(function(index) {
            return $(this).attr("id");
        });

        $("div.rate").removeClass("star-full").removeClass("star-half").addClass("star-none");
        on(this);
    }, function() {
        $("div.rate").removeClass("star-hover");
        if (m)
        {
            $.each(m, function(i, v) {
                $("#" + v).addClass("star-full");
            });
        }

        if (n)
        {
            $.each(n, function(i, v) {
                $("#" + v).addClass("star-half");
            });
        }
    });

    $("div.rate").click(function() {
        $("div.rate").unbind("mouseenter").unbind("mouseleave").unbind("click");
        on(this);
        rate = v(this);
        video_id = $("div.video-id").attr("id");
        $.post("/rate.php", { movie: video_id, rating: rate }, function(data) {
            $("p.rating-text").html(data).show();
        });
    });

    function on(w)
    {
        val = v(w);
        for (x = 1; x <= val; x++)
            $("#rate-" + x).addClass("star-hover");
    }

    function v(w)
    {
        return $(w).attr("id").replace(/rate\-/, "");
    }
});

$(document).ready(function() {
    var id;
    var o;

    $("img.thumbnail").hover(function() {
        o = $(this).attr("src");
        var x = $(this).attr("src").replace(/http:\/\/img.pornblind.com\/thumbs\/([0-9|a-f]+)\/[0-9].jpg/i, "$1");
        var y = $(this).attr("src").replace(/http:\/\/img.pornblind.com\/thumbs\/[0-9|a-f]+\/([0-9]).jpg/i, "$1");
        change($(this), x, y);
    }, function() {
        stop($(this));
    });

    $("img.thumbnail").click(function() {
        stop($(this));
    });

    function change(t, x, y)
    {
        if (++y > 8) y = 1;
        $(t).attr({src: "http://img.pornblind.com/thumbs/" + x + "/" + y + ".jpg"});
        id = setTimeout(function()
        {
            change(t, x, y);
        }, 500);
    }

    function stop(t)
    {
        clearTimeout(id);
        $(t).attr({src: o});
    }
});

$(document).ready(function() {
    $('.flag-menu-header').click(
        function() { $('ul.flag-under-menu').css('display', 'block'); }
    );

    $('ul.flag-menu').hover(
        function() { $('ul', this).css('display', 'block'); },
        function() { $('ul', this).css('display', 'none'); }
    );

    $('a.flag-as-inappropriate').click(
        function() { $('.flag-as-inappropriate-form').css('display', 'block'); }
    );

    $('a.flag-as-underage').click(
        function() { $('.flag-as-underage-form').css('display', 'block'); }
    );

    $('a.flag-as-not-playing').click(
        function() { $('.flag-as-not-playing-form').css('display', 'block'); }
    );
});

var z = Array();
function swap(nx)
{
    e = document.getElementById(nx);
    (e.style.display == 'none')? e.style.display = 'block' : e.style.display = 'none';
}

function nq(a, b)
{
    if (!z[a])
        return;
    (b >= 8)? b = 1 : b++;
    document.getElementById(a).src = "/thumbs/" + a + "-" + b + ".jpg";

    setTimeout("nq('" + a + "', " +  b + ");", 500);
}

function pq(a, b)
{
    z[a] = document.getElementById(a).src;
    nq(a, b);
}

function qq(a)
{
    document.getElementById(a).src = z[a];
    z[a] = false;
}
