﻿$(document).ready(function() {

    //  arrow hover
    $("#mainnewestleftarrow span").hover(function() {
        $(this).css("background-position", "-734px -2px");
    }, function() {
        $(this).css("background-position", "-758px -2px");
    });
    $("#mainnewestrightarrow span").hover(function() {
        $(this).css("background-position", "-722px -2px");
    }, function() {
        $(this).css("background-position", "-746px -2px");
    });
    $("#mainpopularleftarrow span").hover(function() {
        $(this).css("background-position", "-734px -2px");
    }, function() {
        $(this).css("background-position", "-758px -2px");
    });
    $("#mainpopularrightarrow span").hover(function() {
        $(this).css("background-position", "-722px -2px");
    }, function() {
        $(this).css("background-position", "-746px -2px");
    });

    //  arrow animate
    var aniSpeed1 = 500;
    var aniPageSize1 = 4;
    var aniItemWidth1 = 175;
    var aniIndex1 = 1;
    var aniItemCount1 = $("#mainnewestcontentlist ul").children().size();
    var turnPageIndexRight1 = parseInt((aniItemCount1 - 1) / aniPageSize1) * aniPageSize1 + 1;
    $("#mainnewestleftarrow a").click(function() {
        if (aniIndex1 == 1) {
            aniIndex1 = turnPageIndexRight1;
            $("#mainnewestcontentlist ul").animate({ left: -(aniIndex1 - 1) * aniItemWidth1 }, aniSpeed1);
        }
        else {
            aniIndex1 -= aniPageSize1;
            $("#mainnewestcontentlist ul").animate({ left: -(aniIndex1 - 1) * aniItemWidth1 }, aniSpeed1);
        }

        return false;
    });
    $("#mainnewestrightarrow a").click(function() {
        if (aniIndex1 == turnPageIndexRight1) {
            aniIndex1 = 1;
            $("#mainnewestcontentlist ul").animate({ left: 0 }, aniSpeed1);
        }
        else {
            aniIndex1 += aniPageSize1;
            $("#mainnewestcontentlist ul").animate({ left: -(aniIndex1 - 1) * aniItemWidth1 }, aniSpeed1);
        }

        return false;
    });

    var aniSpeed = 500;
    var aniPageSize = 5;
    var aniItemWidth = 140;
    var aniIndex = 1;
    var aniItemCount = $("#mainpopularcontentlist ul").children().size();
    var turnPageIndexRight = parseInt((aniItemCount - 1) / aniPageSize) * aniPageSize + 1;
    $("#mainpopularleftarrow a").click(function() {
        if (aniIndex == 1) {
            aniIndex = turnPageIndexRight;
            $("#mainpopularcontentlist ul").animate({ left: -(aniIndex - 1) * aniItemWidth }, aniSpeed);
        }
        else {
            aniIndex -= aniPageSize;
            $("#mainpopularcontentlist ul").animate({ left: -(aniIndex - 1) * aniItemWidth }, aniSpeed);
        }

        return false;
    });
    $("#mainpopularrightarrow a").click(function() {
        if (aniIndex == turnPageIndexRight) {
            aniIndex = 1;
            $("#mainpopularcontentlist ul").animate({ left: 0 }, aniSpeed);
        }
        else {
            aniIndex += aniPageSize;
            $("#mainpopularcontentlist ul").animate({ left: -(aniIndex - 1) * aniItemWidth }, aniSpeed);
        }

        return false;
    });

});