﻿$(document).ready(function () {
    getContents_0();

    $('#t_0').click(function () { setTab(0); getContents_0(); });
    $('#t_1').click(function () { setTab(1); getContents_1(); });
    $('#t_2').click(function () { setTab(2); getContents_2(); });
    /*$('#t_3').click(function () { setTab(3); });
    $('#t_4').click(function () { setTab(4); });
    $('#t_5').click(function () { setTab(5); });
    $('#t_6').click(function () { setTab(6); });
    $('#t_7').click(function () { setTab(7); });
    $('#t_8').click(function () { setTab(8); });
    $('#t_9').click(function () { setTab(9); });
    $('#t_10').click(function () { setTab(10); });
    $('#t_11').click(function () { setTab(11); });*/

    myTimer = setTimeout("showNext()", 3000);
    showNext(); //loads first image
    $('#thumbs li').bind('click', function (e) {
        var count = $(this).attr('rel');
        showImage(parseInt(count) - 1);
    });

});

function setTab(id) {
    for (var i = 0; i < 12; i++) {
        $('#t_' + i).removeClass("flon").addClass("fl");
    }

    $('#t_' + id).removeClass("fl").addClass("flon");
}

function getContents_0() {
    setP();
    $("#contents_magazine").load("/contents.aspx", { action: "magazine", category: "4", date: new Date().getTime() });
    $('#contents_shopwindow').load("/contents.aspx", { action: "shopwindow", category: "33554432", date: new Date().getTime() });
    $('#contents_style').load("/contents.aspx", { action: "style", category: "33554432", date: new Date().getTime() });
    $('#contents_book').load("/contents.aspx", { action: "book", category: "33554432", date: new Date().getTime() });
}

function getContents_1() {
    setP();
    $("#contents_magazine").load("/contents.aspx", { action: "magazine", category: "3", date: new Date().getTime() });
    $('#contents_shopwindow').load("/contents.aspx", { action: "shopwindow", category: "16777216", date: new Date().getTime() });
    $('#contents_style').load("/contents.aspx", { action: "style", category: "16777216", date: new Date().getTime() });
    $('#contents_book').load("/contents.aspx", { action: "book", category: "16777216", date: new Date().getTime() });
}

function getContents_2() {
    setP();
    $("#contents_magazine").load("/contents.aspx", { action: "magazine", category: "2", date: new Date().getTime() });
    $('#contents_shopwindow').load("/contents.aspx", { action: "shopwindow", category: "50331648", date: new Date().getTime() });
    $('#contents_style').load("/contents.aspx", { action: "style", category: "50331648", date: new Date().getTime() });
    $('#contents_book').load("/contents.aspx", { action: "book", category: "50331648", date: new Date().getTime() });
}

function setP() {
    $("#contents_magazine").html('<img style="margin-top:50px;" src="/images/load.gif" alt="" />');
    $('#contents_shopwindow').html('<img style="margin-top:50px;" src="/images/load.gif" alt="" />');
    $('#contents_style').html('<img style="margin-top:150px;" src="/images/load.gif" alt="" />');
    $('#contents_book').html('<img style="margin-top:150px;" src="/images/load.gif" alt="" />');
}
/*================================ad部分===============================================*/
var currentImage;
var currentIndex = -1;
var interval;
function showImage(index) {
    if (index < $('#bigPic img').length) {
        var indexImage = $('#bigPic img')[index]
        if (currentImage) {
            if (currentImage != indexImage) {
                $(currentImage).css('z-index', 2);
                clearTimeout(myTimer);
                $(currentImage).fadeOut(250, function () {
                    myTimer = setTimeout("showNext()", 3000);
                    $(this).css({ 'display': 'none', 'z-index': 1 })
                });
            }
        }
        $(indexImage).css({ 'display': 'block', 'opacity': 1 });
        currentImage = indexImage;
        currentIndex = index;
        $('#thumbs li').removeClass('active');
        $($('#thumbs li')[index]).addClass('active');
    }
}

function showNext() {
    var len = $('#bigPic img').length;
    var next = currentIndex < (len - 1) ? currentIndex + 1 : 0;
    showImage(next);
}

var myTimer;
/*================================ad部分结束===============================================*/
