var bags = new Object;
bags.dir = "";
bags.images= ["images/home/home_main_2.jpg",
                "images/home/home_main_1.jpg",
                "images/home/home_main_3.jpg",
                "images/home/home_main_4.jpg"];

var imageCounter = 1;
var timerRotator;

// you can do this short if this is
// the only thing you do after onload
window.onload = RotateImages;

function RotateImages() {
    // restart rotation
    if (imageCounter >= bags.images.length) {
        imageCounter = 0;
    }

    // the standard way to grab an element by its id
    var img = document.getElementById("imgBags");

    // change the src and increment counter
    img.src = bags.dir + bags.images[imageCounter];
    imageCounter++;

    // RotateImages function can be passed by reference
    timerRotator = setTimeout(RotateImages, 6000);
}

