﻿var thumbnailList = new Array();
var thumbnailShowCount =5;
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 = "";
//    s += "<div class=\"index_content_dibu_left_content_left\"><a href=\"javascript:MoveThumbItem(1, '" + contentDivID + "');\"><img src=\"images/index_hezuo_left.jpg\" border='0' /></a></div>";
    s += "<div class='index_content_dibu_left_content_content'><ul>";
    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><a href='" + thumb.URL + "' target='_blank'><img src='" + thumb.Src + "' alt='" + thumb.Alt + "' height='44px' width='120px' border='0'/></a></li>";
            s += "<li style=\"border:0px\"><img src=\"images/img1.jpg\" width='2px' border=\"0\"/></li>";
        }

    }    
     s+="</ul></div>";
//     s += "<div class=\"index_content_dibu_left_content_right\"><a href=\"javascript:MoveThumbItem(-1, '" + contentDivID + "');\"><img src=\"images/index_hezuo_right.jpg\" border='0' /></a></div>";
               
    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.URL = values[1];
            thumb.Alt = values[2];
            thumb.Title = values[3];
            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);
}
