var slideShow = function(){
    var linksDiv, isIE, scrollTimer, scrollSpeed, linksElement, linksElementArray, linksElementList, maxElement, swidth, idirection;
    linksDiv = document.getElementById(thumbid);
    linksElement = linksDiv.getElementsByTagName('li');
    isIE = document.all ? true : false;
    scrollSpeed = 1;
    maxElement = 4;
    idirection = 1;
    scrollTimer = 3;
    return {
        init: function(){
            linksDiv.onmousemove = function(){
                clearTimeout(linksDiv.timer);
            };
            linksDiv.onmouseout = function(){
                slideShow.postion;
                if (idirection == 1) {
                    slideShow.scroll(-1);
                }
                else {
                    slideShow.scroll(1);
                }
            };
            ys = this.topPostion(linksDiv);
            ye = ys + linksDiv.offsetHeight;
            len = linksElement.length;
            linksElementArray = [];
            for (i = 0; i < len; i++) {
                var id = linksElement[i].value;
                linksElementArray[i] = id;
            }
            linksElementList = linksElementArray.length;
            swidth = (linksElement[linksElementList - 1].offsetLeft - (linksDiv.parentNode.offsetWidth - linksElement[linksElementList - 1].offsetWidth) + 10);
        },
        scroll: function(direction){
            idirection = direction;
            clearInterval(linksDiv.timer);
            var l = (direction == -1) ? 0 : swidth;
            linksDiv.timer = setInterval(function(){
                slideShow.move(direction, l)
            }, scrollTimer);
        },
        move: function(direction, l){
            linksDiv.style.left = linksDiv.style.left || '0px';
            var left = linksDiv.style.left.replace('px', '');
            if (direction == 1) {
                if (l - Math.abs(left) <= scrollSpeed) {
                    this.cncl(direction);
                    linksDiv.style.left = '-' + l + 'px';
                }
                else {
                    linksDiv.style.left = left - scrollSpeed + 'px'
                }
            }
            else {
                if (Math.abs(left) - l <= scrollSpeed) {
                    this.cncl(direction);
                    linksDiv.style.left = l + 'px';
                }
                else {
                    linksDiv.style.left = parseInt(left) + scrollSpeed + 'px'
                }
            }
        },
        cncl: function(direction){
            clearTimeout(linksDiv.timer)
            setTimeout(function(){
                if (direction == 1) {
                    slideShow.scroll(-1);
                }
                else {
                    slideShow.scroll(1);
                }
            }, 1500);
        },
        limit: function(){
            var linksDivWidth, linksDivWidthAverage, len;
            linksDivWidth = linksDiv.parentNode.offsetWidth;
            linksDivWidthAverage = linksDivWidth / maxElement;
            linksDivLeftSide = slideShow.leftPostion(linksDiv);
            linksDivMiddlePostion = linksDivLeftSide + linksDivWidthAverage;
            linksDivRightSide = linksDivLeftSide + linksDivWidth;
            fxs = linksDivRightSide - linksDivWidthAverage;
        },
        postion: function(e){
            postion_x = isIE ? event.clientX + document.documentElement.scrollLeft : e.pageX;
            postion_y = isIE ? event.clientY + document.documentElement.scrollTop : e.pageY;
            if (postion_x > linksDivLeftSide && postion_x < linksDivMiddlePostion/* && postion_y > ys && postion_y < ye*/) {
                slideShow.scroll(-1);
            }
            else {
                if (postion_x > fxs && postion_x < linksDivRightSide /*&& postion_y > ys && postion_y < ye*/) {
                    slideShow.scroll(1);
                }
            }
        },
        leftPostion: function(linksElement){
            var l = 0;
            if (linksElement.offsetParent) {
                while (1) {
                    l += linksElement.offsetLeft;
                    if (!linksElement.offsetParent) {
                        break
                    };
                    linksElement = linksElement.offsetParent
                }
            }
            else 
                if (linksElement.x) {
                    l += linksElement.x
                }
            return l;
        },
        topPostion: function(linksElement){
            var p = 0;
            if (linksElement.offsetParent) {
                while (1) {
                    p += linksElement.offsetTop;
                    if (!linksElement.offsetParent) {
                        break
                    };
                    linksElement = linksElement.offsetParent
                }
            }
            else 
                if (linksElement.y) {
                    p += linksElement.y
                }
            return p;
        }
    };
}();

window.onload = function(){
    slideShow.init();
    slideShow.limit();
    setTimeout(function(){
        slideShow.scroll(1);
    }, 1500);
};
