// JavaScript Document

var glide = new function () {
    function $id(id) { return document.getElementById(id); };

    this.layerGlide = function (auto, oEventCont, oSlider, sSingleSize, second, fSpeed, point) {
        var oSubLi = $id(oEventCont).getElementsByTagName('li');
        var interval, timeout, oslideRange;
        var time = 1;
        var speed = fSpeed
        var sum = oSubLi.length;
        var a = 0;
        var delay = second * 1800;

        var setValLeft = function (s) {
            return function () {
                oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
                $id(oSlider).style[point] = -Math.floor(oslideRange + (parseInt(s * sSingleSize) - oslideRange) * speed) + 'px';
                if (oslideRange == [(sSingleSize * s)]) {
                    clearInterval(interval);
                    a = s;
                }
            }
        };

        var setValRight = function (s) {
            return function () {
                oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
                $id(oSlider).style[point] = -Math.ceil(oslideRange + (parseInt(s * sSingleSize) - oslideRange) * speed) + 'px';
                if (oslideRange == [(sSingleSize * s)]) {
                    clearInterval(interval);
                    a = s;
                }
            }
        }

        function autoGlide() {
            for (var c = 0; c < sum; c++) { oSubLi[c].className = ''; };
            clearTimeout(interval);
            if (a == (parseInt(sum) - 1)) {
                for (var c = 0; c < sum; c++) { oSubLi[c].className = ''; };
                a = 0;
                oSubLi[a].className = "active";
                interval = setInterval(setValLeft(a), time);
                timeout = setTimeout(autoGlide, delay);
            } else {
                a++;
                oSubLi[a].className = "active";
                interval = setInterval(setValRight(a), time);
                timeout = setTimeout(autoGlide, delay);
            }
        }

        if (auto) { timeout = setTimeout(autoGlide, delay); };

        for (var i = 0; i < sum; i++) {

            oSubLi[i].onmouseover = (function (i) {

                return function () {
                    for (var c = 0; c < sum; c++) { oSubLi[c].className = ''; };
                    clearTimeout(timeout);
                    clearInterval(interval);
                    oSubLi[i].className = "active";
                    if (Math.abs(parseInt($id(oSlider).style[point])) > [(sSingleSize * i)]) {
                        interval = setInterval(setValLeft(i), time);
                        this.onmouseout = function () { if (auto) { timeout = setTimeout(autoGlide, delay); }; };
                    } else if (Math.abs(parseInt($id(oSlider).style[point])) < [(sSingleSize * i)]) {
                        interval = setInterval(setValRight(i), time);
                        this.onmouseout = function () { if (auto) { timeout = setTimeout(autoGlide, delay); }; };
                    }
                }
            })(i)
        }
    }
}
glide.layerGlide(true, 'icon_num', 'show_pic', 690, 2, 0.1, 'left');

