
        function fade(step) {
            var imgs = document.getElementById("slider").getElementsByTagName("img");

            step = step || 0;

            imgs[counter].style.opacity = step/100;
            imgs[counter].style.filter = "alpha(opacity=" + step + ")"; // 
            
            var lastCounter = counter - 1;
            if (lastCounter < 0) {
            	lastCounter = imgs.length - 1;
            }
            imgs[lastCounter].style.opacity = (100 - step)/100;
            imgs[lastCounter].style.filter = "alpha(opacity=" + (100 - step) + ")"; // 

            step = step + 2;

            if (step <= 100) {
                window.setTimeout(function () { fade(step); }, 40);
            } else {
                window.setTimeout(next, 2000);
            }
        }

        function next() {
            var imgs = document.getElementById("slider").getElementsByTagName("img");

            if (typeof(counter) != "number") {
              counter = 0;
            }
				counter = (counter + 1) % (imgs.length);
            fade();
        };
