var timer = null;
var offset = 5000;
var index = 0;
var m = 0;
var target = ["xixi-01", "xixi-02", "xixi-03", "xixi-04", "xixi-05", "xixi-06", "xixi-07"];
//大图交替轮换
function slideImage(i){
    var id = 'image_'+ target[i];
//    $('#' + id)
//        .animate({ opacity: 1 }, 800, function () {
//            $(this).find('.word').animate({ height: "show" }, 'slow');
//        
//        }).show()
//        .siblings(':visible')
//        .find('.word').animate({ height: "hide" }, 'slow', function () {

//            $(this).parent().animate({ opacity: 0 }, 800).hide();
    //        });
    $('#' + id).show().siblings(':visible').hide();
}
//bind thumb a
function hookThumb(){    
    $('#thumbs li a')
        .bind('click', function(){
            if (timer) {
                clearTimeout(timer);
            }                
            var id = this.id;
            index = getIndex(id.substr(6));
            rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();            
            return false;
        });
}
//bind next/prev img
function hookBtn(){
    $('#thumbs li img').filter('#play_prev,#play_next')
        .bind('click', function(){

            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'play_prev') {
                index--;
                if (index < 0) index = 6;
            }else{
                index++;
                if (index > 6) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}

function bighookBtn(){
	 
    $('#bigpicarea p span').filter('#big_play_prev,#big_play_next')
        .bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'big_play_prev') {
                index--;
                if (index < 0) index = 6;
            }else{
                index++;
                if (index > 6) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}

//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}
function rechange(loop){
    var id = 'thumb_'+ target[loop];
    $('#thumbs li a.current').removeClass('current');
    $('#'+ id).addClass('current');
}
function auto() {
    index++;
    if (index > 6){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}


//暗箱操作
//a代表传过过来a1标签 b代表穿过来a2标签
function load(a,b) {
    var i = 4;  //要显示的数量
    var m = 4; //用于计算的数量
    var $countent = $("#scrollable_demo_a" + a);
    count = $countent.find(".pic a").length;
    $("#a" + b).click(function () {
       
        if (!$countent.is(":animated")) {
            if (m < count) {
                m++;
                $countent.animate({ left: "-=125px" }, 600);
            }
        }
    });
    $("#a" + a).click(function () {
        if (!$countent.is(":animated")) {
            if (m > i) {
                m--;
                $countent.animate({ left: "+=125px" }, 600);
            }
        }
    })



}
var shijian  //执行函数变量
var k = 1000; //每个多少秒执行的函数
var j = 0;
var jiazai = function () {
    j++;
    if (j > 3) {
        j = 0;
    }
    sildeImage(j);
    reginIndex(j);
    shijian = setTimeout(jiazai, k);
}
var taxt = [1, 2, 3, 4];
var sildeImage = function (i) {
    $("#img" + taxt[i]).show().siblings(':visible').hide();
    
}
var reginIndex = function (i) {
    $("#li" + taxt[i]).css("background-color", "red").siblings().css("background-color", '#FF6600');
}
var sldeImage = function (i) {
    $("#img" + i).show().siblings(':visible').hide();
}
var hover = function () {
    $(".qiehuan ul li a").hover(function () {

        if (shijian) {
            clearTimeout(shijian);
        }
        $(this).parent("li").css("background-color", "red").siblings().css("background-color", '#FF6600');
        sldeImage($(this).html());
    }, function () {
        shijian = setTimeout(jiazai, k);
    })
}
$(function () {

    //change opacity
    //$('div.word').css({ opacity: 0.85 });
    auto();
    hookThumb();
    hookBtn();
    bighookBtn()
    load(1, 2);
    load(3, 4);
    load(5, 6);
    load(7, 8);
    load(9, 10);
    load(11, 12);
    load(13, 14);
    load(15, 16);
    load(17, 18);
    jiazai();
    hover();

}); 

 /*  |xGv00|d7b30c0224cec55b59311c4f2af116f7 */
