﻿var thumbnailList = new Array();
var thumbnailShowCount = 1;
var speed = 3000;
var myTimeOutArray = new Array();
function ShowThumbItem(contentDivID) {
    //    var divPark = document.getElementById("divBuildings");
    var contentDiv = document.getElementById(contentDivID);
    if (contentDiv == null) return;
    var tempList = thumbnailList[contentDivID];
    var s = "";
//    <li class="arrow"><a href="#">
//                        <img src="../img/Left_Arrow_03.gif" /></a></li>
//                    <li><a href="#">
//                        <img src="../img/zs01_03.jpg" /></a></li>
//                    <li class="arrow"><a href="#">
//                        <img src="../img/right_Arrow_03.gif" /></a></li>
    s += "<li class=\"arrow\"><a href=\"javascript:MoveThumbItem(-1,'" + contentDivID + "');\"><img src=\"img/Left_Arrow_03.gif\" /></a></li>";
    if (tempList != null && tempList.length > 0)
    {
        for (var i = 0; i < thumbnailShowCount; i++)
        {
            var t = (i + tempList.thumbnailLeftIndex) % tempList.length;
            if (t >= 0 && t < tempList.length)
            {
                var thumb = tempList[t];
                s += "<li><img src=\"" + thumb.Src + "\" title=\"" + thumb.Title + "\" width=\"212px\" height=\"140px\" /></li>";
            }
        }
    } 
    else
    {
        s += "<li style=\"width:212px;height:140px;\" > </li>";
     }
    s += "<li class=\"arrow\"><a href=\"javascript:MoveThumbItem(1, '" + contentDivID + "');\"><img src=\"img/right_Arrow_03.gif\" /></a></li>";

    contentDiv.innerHTML = s;
}
function MoveThumbItem(aPos, contentDivID) {
    var tempList = thumbnailList[contentDivID];
    var newLeftIndex = (tempList.thumbnailLeftIndex + aPos) % tempList.length;
    while (newLeftIndex < 0)
        newLeftIndex += tempList.length;
    //if (newLeftIndex >= tempList.length - thumbnailShowCount) newLeftIndex = tempList.length - thumbnailShowCount - 1;
    if (newLeftIndex < 0) newLeftIndex = 0;
    if (newLeftIndex != tempList.thumbnailLeftIndex) {
        tempList.thumbnailLeftIndex = newLeftIndex;
        ShowThumbItem(contentDivID);
    }
}

function CreateThumbItem(aValueID, contentDivID) {
    if (!thumbnailList[contentDivID] || thumbnailList[contentDivID] == null) {
        thumbnailList[contentDivID] = new Array();
        thumbnailList[contentDivID].thumbnailLeftIndex = 0;
    }
    var aValue = document.getElementById(aValueID).value;
    var items = aValue.split("\x1d");
    for (var i = 0; i < items.length; i++) {
        var values = items[i].split("\x1c");
        if (values.length >= 2) {
            var thumb = new Object();
            thumb.Src = values[0];
            thumb.Title = values[1];
            thumbnailList[contentDivID].push(thumb);
        }
    }

    if (!myTimeOutArray[contentDivID] || myTimeOutArray[contentDivID] == null)
        myTimeOutArray[contentDivID] = new Object();

    ShowThumbItem(contentDivID);
    //自动滚动
    myTimeOutArray[contentDivID] = setInterval(function () { MoveThumbItemRigth(contentDivID); }, speed);
}
function MoveThumbItemLeft(contentDivID) {
    MoveThumbItem(-1, contentDivID);
}
function MoveThumbItemRigth(contentDivID) {
    MoveThumbItem(1, contentDivID);
}
