juery slider is loaded only after page refresh

juery slider is loaded only after page refresh

In jquery mobile image slider is loaded only after page is refreshed by ctrl+f5.
my code is-
<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
        var i = 0;
        var image = new Array();
        // LIST OF IMAGES
        image[0] = "images/home-images/wmx1.jpg";
        image[1] = "images/home-images/wmx2.jpg";
        image[2] = "images/home-images/wmx3.jpg";
        image[3] = "images/home-images/wmx4.jpg";
        image[4] = "images/home-images/wmx5.jpg";
        var k = image.length - 1;
        var caption = new Array();
        // LIST OF CAPTÇIONS 
        caption[0] = "Acclerate Growth";
        caption[1] = "Outgrow Spreadsheets and Point Solutions";
        caption[2] = "Gain Access to Industry Best Practices";
        caption[3] = "Transform Business with Enterprise Class ERP";
        caption[4] = "Experience Painless Growth";
        function swapImage() {
            var el = document.getElementById("mydiv");
       
            el.innerHTML = caption[i];
            var img = document.getElementById("slide");
           
            img.src = image[i];
            if (i < k) { i++; }
            else { i = 0; }
            setTimeout("swapImage()", 2000);
        }

        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            }
            else {
                window.onload = function () {
                    if (oldonload) {
                        oldonload();
                    }
                    func();
                }
            }
        }
        addLoadEvent(function () {
            swapImage();
        });
    </script>
It is working on index page but not on other pages.
Please help!
I have spend last three days debugging the problem.
Not able to solve.
Please help immediately.
Thanks!
Tamanna