function init(vContainer,width,height) {
    // create container - with main width and height given
    var container = $("<div></div>");
    var labels = $("<ul></ul>");
    var images = $("<div></div>");
    $(container).addClass("acarousel");
    $(container).append(labels).append("<div style='clear: both; height: 0px;'>&nbsp;</div>");
    $(images).addClass("theimages").css({width: width + "px",height: height + "px",marginLeft: "auto",marginRight: "auto"});
    $(container).append(images);
    return $(container).get(0);
}

$(window).load(function() {
    setInterval(function() {
        $("div.acarousel a:visible").fadeOut(function() {
        }).each(function() {
            if ($(this).next("a").length>0) {
                $(this).next("a").fadeIn();
            } else {
                $(this).parent().find("a:first").fadeIn();
            }
        });
        $("div.acarousel ul li.current").each(function() {
            $(this).removeClass("current");
            if ($(this).next("li").length>0) {
                $(this).next("li").addClass("current");
            } else {
                $(this).parent().find("li:first").addClass("current");
            }            
        });
    },5000);
});

function addImage(path,label) {
    addImageWithLink(path,label,"#");
}

function addImageWithLink(path,label,link) {
    var container = $("div.acarousel");

    var labels = $(container).find("ul");
    var labli = $("<li></li>");
    labli.append("<span>" + label + "</span>");
    labels.append(labli);

    var images = $($(container).find("div.theimages").get(0));
    var imglink = $("<a></a>");
    var imgsrc = $("<img />");
    $(imglink).attr("href",link);
    $(imgsrc).attr("src",path);
    $(imglink).append(imgsrc);
    $(images).append(imglink);
    $(imglink).css({clear: "both",overflow: "hidden",position: "absolute"});

    // set li's to be width of ul divded by their count
    var wdth = ($(labels).width()-35) / $(labels).find("li").length;
    $(labels).find("li").css({width: wdth + "px"});
    $(labels).find("li span").css({width: (wdth - 20) + "px"});

    $("div.acarousel div a").hide();
    $("div.acarousel ul li").removeClass("current");
    $("div.acarousel div a:first").fadeIn();
    $("div.acarousel ul li:first").addClass("current");
}

