/*
** Img Flow 1.0 08/03/05
*/
var current = 0;
var target = 0;
var timer = 0;
var captionId = "i1";
function windowWidth()
{
    var width;
    if (document.layers) {
        width = window.innerWidth;
    }
    else {
        width = document.body.clientWidth;
    }

    return width;
}
function step()
{
    if (target < current - 1 || target > current + 1) {
        moveTo(current + (target - current) / 5);
        window.setTimeout(step, 50);
        timer = 1;
    }
    else {
        timer = 0;
    }
}
function glideTo(x, newCaptionId)
{
    changeImg(newCaptionId - 1);
    target = x;
    if (timer == 0) {
        window.setTimeout(step, 50);
        timer = 1;
    }
    captionId = newCaptionId;
}
function moveTo(x)
{
    current = x;
    var div = document.getElementById("thums30s");
    var top = div.offsetTop;
    //サムネイル表示全体横幅
    var width = 400;
    var size = width * 0.4;
    var biggest = width * 0.4;
    var zIndex = div.childNodes.length;
    for (index = 0; index < div.childNodes.length; index++)
    {
        var image = div.childNodes.item(index);
        if (image.nodeType == 1)
        {
            var z = Math.sqrt(10000 + x * x) + 10;
            var xs = x  / z * size + size;

            //サムネイルｘ座標
            var l = xs - 30 / z * biggest;
            if (l > 285) {
            	l = 285;
            }
            else if (l < 0) {
            	l = 0;
            }

            image.style.left = l + 'px';

            /*
            alert("x=" +  x);
            alert("z=" +  z);
            alert("size=" +  size);
            alert("xs=" +  xs);
            alert("biggest=" +  biggest);
            alert("img_left=" +  image.style.left);
            alert("img_top=" + image.style.top);
            alert("img_width=" +image.style.width);
            alert("img_height=" + image.style.height);
            */
            image.style.zIndex = zIndex;
            if ( x < 0 ) {
                zIndex++;
            }
            else {
                zIndex--;
            }
            x += 100;
        }
    }
}
function refresh()
{
    var width = windowWidth();
    var caption = document.getElementById(captionId);
    moveTo(current);
}
