$(document).ready(function() {
            var currentIndex = 0;
            var maxIndex = 0;  
            $(window).load(function(){
                
                maxIndex = $(".slider").children().length;
                $(".slider img").click(function(){nextImg();});
                $(".slider").css({width: (parseInt($(".main_img").css("width")) * maxIndex + 1) + "px"}).fadeIn("normal");
                $('.main_img').css({backgroundImage: "url(images/livebg.jpg)"});
            });
            
            function nextImg(){
                currentIndex++;
                if (currentIndex > maxIndex) {currentIndex = 0;}
                scrollTo(currentIndex);
            }
            
            function prevImg(){
                currentIndex--;
                if (currentIndex < 0) {currentIndex = maxIndex;}
                scrollTo(currentIndex);
            }
            
            function scrollTo(number){
                var imageSize = 576;
                var pos = number * imageSize * -1;
                //$(".slider").stop().animate({left: pos + "px"}, 1100, "easeInOutCubic");
                $(".slider img").fadeOut("normal", function(){
                        $(".slider").css({left: pos + "px"});
                        $(".slider img").fadeIn("normal");
                        });
            }
            
            $('.next').click(function(){nextImg();});
            $('.back').click(function(){prevImg();});

            function debug(text){$(".debug").empty().append(text);}           
          });