/**
 * Created by SONY-PC on 2015/6/16.
 */


function initView (){
    var window_height = $(window).height(); //ä¯ÀÀÆ÷µ±Ç°´°¿Ú¿ÉÊÓÇøÓò¸ß¶È
    $("#Big").css("height", parseInt(window_height))

    var news_width = $("#Big").outerWidth()-115-$("#func_zone").outerWidth();
    var news_height = $(window).height()-$(".banner").outerHeight()-20

    $(".news_Data").css({
        "width":news_width,
        "height":news_height
    })
    $(".news_card").css({
        "width":(news_width/4)-29
    })

    //$(".news_card_ul").css({
    //    //"height":$(".news_card").outerHeight()*$(".news_card_ul li").length,
    //    "width":(news_width/4.5)*4
    //})


}

$(document).ready(function () {

    var mBannerMoveInterval = 5000
    var banner_img_width = $(".banner").outerWidth() + 15
    $(".banner_img").css({
        "width": banner_img_width,
    })
    $(".banner_ul").css("width", $(".bigCard").outerWidth() * 4 + 60)
    $(".banner_title").css("left", ($(".banner").outerWidth() - $(".banner_title").outerWidth()) / 2)
    $(".banner_navs").css("left", ($(".banner").outerWidth() - $(".banner_navs").outerWidth()) / 2)

    bannerMove(banner_img_width, mBannerMoveInterval);
})

function bannerMove(banner_img_width, mBannerMoveInterval) {
    var speed = 0
    var bannerTimer = setInterval(move, mBannerMoveInterval)
    var banner_nav_poi = 1;
    function move() {

        if(banner_nav_poi>3){
            banner_nav_poi = 1;
        }else{
            banner_nav_poi++
        }
        if (speed >= banner_img_width * 3) {
            speed = 0
        } else {
            speed = speed + banner_img_width
        }

        for(var i =0;i<$(".banner_nav").length;i++){
            if($(".banner_nav").get(i).value == banner_nav_poi){
                bannerPosition(speed,i)
                break;
            }
        }
    }

    $(".banner").eq(0).mouseover(function () {
        clearInterval(bannerTimer)
    })
    $(".banner").mouseout(function () {
        bannerTimer = setInterval(move, mBannerMoveInterval)
    })


    for(var i=0;i<$(".banner_nav").length;i++) {
        $(".banner_nav").eq(i).click(function (event) {
            event.stopPropagation();
            switch ($(this).get(0).value){
                case 1:
                    bannerPosition(0,0)
                    break
                case 2:
                    bannerPosition(banner_img_width,1)
                    break
                case 3:
                    bannerPosition(banner_img_width*2,2)
                    break
                case 4:
                    bannerPosition(banner_img_width*3,3)
                    break
            }
        })
    }
}
 function bannerPosition(moveNum,index) {

     $(".banner_nav").eq(index).css("background","rgba(255,255,255,1)")
     $(".banner_nav").not($(".banner_nav").eq(index)).css("background","rgba(255,255,255,0)")

     $(".banner_ul").css({
         "-webkit-transform": "translateX(" + (-moveNum) + "px)",
         "-moz-transform": "translateX(" + (-moveNum) + "px)",
         "-ms-transform": "translateX(" + (-moveNum) + "px)",
         "-o-transform": "translateX(" + (-moveNum) + "px)",
         "transform": "translateX(" + (-moveNum) + "px)"
     })

 }