$(document).ready(function () {
    $("#home-news .paging").show();
    $("#home-news .paging a:first").addClass("active");

    var imageWidth = $("#home-news .window").width();
    var imageSum = $("#home-news .image_reel div").size();
    var imageReelWidth = imageWidth * imageSum;

    $("#home-news .image_reel").css({ 'width': imageReelWidth });

    rotate = function () {
        var triggerID = $active.attr("rel") - 1;
        var image_reelPosition = triggerID * imageWidth;
        $("#home-news .paging a").removeClass('active');
        $active.addClass('active');

        $("#home-news .image_reel").animate({
            left: -image_reelPosition
        }, 500);

    };

    rotateSwitch = function () {
        play = setInterval(function () {
            $active = $('#home-news .paging a.active').next();
            if ($active.length === 0) {
                $active = $('#home-news .paging a:first');
            }
            rotate();
        }, 10000);
    };

    rotateSwitch();

    $("#home-news .nav div:eq(1)").click(function () {
        var index = $("#home-news .paging a").index($("#home-news .paging a.active"));
        if (index + 1 < $("#home-news .paging a").length) {
            index++;
        } else {
            return;
        }
        $("#home-news .paging a:eq(" + index + ")").click();
    });

    $("#home-news .nav div:eq(0)").click(function () {
        var index = $("#home-news .paging a").index($("#home-news .paging a.active"));
        if (index - 1 >= 0) {
            index--;
        } else {
            return;
        }
        $("#home-news .paging a:eq(" + index + ")").click();
    });
    $("#home-news .image_reel a").hover(function () {
        clearInterval(play);
    }, function () {
        rotateSwitch();
    });

    $("#home-news .paging a").click(function () {
        $active = $(this);
        clearInterval(play);
        rotate();
        rotateSwitch();
        return false;
    });




    $("#home-center .paging").show();
    $("#home-center .paging a:first").addClass("active");

    var imageWidth1 = $("#home-center .window").width();
    var imageSum1 = $("#home-center .image_reel div").size();
    var imageReelWidth1 = imageWidth1 * imageSum1;

    $("#home-center .image_reel").css({ 'width': imageReelWidth1 });

    rotate1 = function () {
        var triggerID = $active1.attr("rel") - 1;
        var image_reelPosition = triggerID * imageWidth1;
        $("#home-center .paging a").removeClass('active');
        $active1.addClass('active');

        $("#home-center .image_reel").animate({
            left: -image_reelPosition
        }, 500);

    };

    rotateSwitch1 = function () {
        play1 = setInterval(function () {
            $active1 = $('#home-center .paging a.active').next();
            if ($active1.length === 0) {
                $active1 = $('#home-center .paging a:first');
            }
            rotate1();
        }, 15000);
    };

    rotateSwitch1();

    $("#home-center .nav div:eq(1)").click(function () {
        var index = $("#home-center .paging a").index($("#home-center .paging a.active"));
        if (index + 1 < $("#home-center .paging a").length) {
            index++;
        } else {
            return;
        }
        $("#home-center .paging a:eq(" + index + ")").click();
    });

    $("#home-center .nav div:eq(0)").click(function () {
        var index = $("#home-center .paging a").index($("#home-center .paging a.active"));
        if (index - 1 >= 0) {
            index--;
        } else {
            return;
        }
        $("#home-center .paging a:eq(" + index + ")").click();
    });
    $("#home-center .image_reel a").hover(function () {
        clearInterval(play1);
    }, function () {
        rotateSwitch1();
    });

    $("#home-center .paging a").click(function () {
        $active1 = $(this);
        clearInterval(play1);
        rotate1();
        rotateSwitch1();
        return false;
    });
});
